Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor: replace startup script logs EOF with starting/ready time#8082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
PR comment fixes
  • Loading branch information
@mafredri
mafredri committedJun 20, 2023
commit43a0f87dc84fb04a692b4b69290db01336d34cc8
19 changes: 9 additions & 10 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -837,28 +837,27 @@ func (a *agent) runShutdownScript(ctx context.Context, script string) error {
}

func (a *agent) runScript(ctx context.Context, lifecycle, script string) (err error) {
logger := a.logger.With(slog.F("lifecycle", lifecycle))

if script == "" {
logger.Info(ctx, "not running empty script")
return nil
}

logger.Info(ctx, "running script", slog.F("script", script))
logger := a.logger.With(slog.F("lifecycle", lifecycle))

logger.Info(ctx, fmt.Sprintf("running %s script", lifecycle), slog.F("script", script))
fileWriter, err := a.filesystem.OpenFile(filepath.Join(a.logDir, fmt.Sprintf("coder-%s-script.log", lifecycle)), os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return xerrors.Errorf("open %s script log file: %w", lifecycle, err)
}
defer func() {
err := fileWriter.Close()
if err != nil {
logger.Warn(ctx, "close script log file", slog.Error(err))
logger.Warn(ctx,fmt.Sprintf("close%sscript log file", lifecycle), slog.Error(err))
}
}()

cmdPty, err := a.sshServer.CreateCommand(ctx, script, nil)
if err != nil {
return xerrors.Errorf("create command: %w", err)
return xerrors.Errorf("%s script:create command: %w", lifecycle, err)
}
cmd := cmdPty.AsExec()

Expand All@@ -872,7 +871,7 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) (err er
writer = io.MultiWriter(fileWriter, logsWriter)
flushedLogs, err := a.trackScriptLogs(ctx, logsReader)
if err != nil {
return xerrors.Errorf("track script logs: %w", err)
return xerrors.Errorf("track%sscript logs: %w", lifecycle, err)
}
defer func() {
_ = logsWriter.Close()
Expand All@@ -894,9 +893,9 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) (err er
if xerrors.As(err, &exitError) {
exitCode = exitError.ExitCode()
}
logger.Warn(ctx,"script failed", slog.F("execution_time", execTime), slog.F("exit_code", exitCode), slog.Error(err))
logger.Warn(ctx,fmt.Sprintf("%sscript failed", lifecycle), slog.F("execution_time", execTime), slog.F("exit_code", exitCode), slog.Error(err))
} else {
logger.Info(ctx,"script completed", slog.F("execution_time", execTime), slog.F("exit_code", exitCode))
logger.Info(ctx,fmt.Sprintf("%sscript completed", lifecycle), slog.F("execution_time", execTime), slog.F("exit_code", exitCode))
}
}()
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Review: Small cleanup to unify logging between startup and shutdown scripts.

mtojek reacted with thumbs up emoji

Expand All@@ -907,7 +906,7 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) (err er
return ctx.Err()
}

return xerrors.Errorf("run: %w", err)
return xerrors.Errorf("%s script:run: %w", lifecycle, err)
}
return nil
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,8 @@ ALTER TABLE workspace_agents
DROP COLUMN started_at,
DROP COLUMN ready_at;

-- We won't bring back log entries where eof = TRUE, but this doesn't matter
-- as the implementation doesn't require it and hasn't been part of a release.
ALTER TABLE workspace_agent_startup_logs ADD COLUMN eof boolean NOT NULL DEFAULT false;

COMMENT ON COLUMN workspace_agent_startup_logs.eof IS 'End of file reached';
Expand Down
6 changes: 3 additions & 3 deletionscoderd/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -283,12 +283,12 @@ func (api *API) patchWorkspaceAgentStartupLogs(rw http.ResponseWriter, r *http.R
// Ensure logs are not written after script ended.
scriptEndedError := xerrors.New("startup script has ended")
err := api.Database.InTx(func(db database.Store) error {
ss, err := db.GetWorkspaceAgentLifecycleStateByID(ctx, workspaceAgent.ID)
state, err := db.GetWorkspaceAgentLifecycleStateByID(ctx, workspaceAgent.ID)
if err != nil {
return xerrors.Errorf("workspace agent startup script status: %w", err)
}

ifss.ReadyAt.Valid {
ifstate.ReadyAt.Valid {
// The agent startup script has already ended, so we don't want to
// process any more logs.
return scriptEndedError
Expand DownExpand Up@@ -1626,7 +1626,7 @@ func (api *API) workspaceAgentReportLifecycle(rw http.ResponseWriter, r *http.Re
ReadyAt: readyAt,
})
if err != nil {
logger.Warn(ctx, "failed to update lifecycle state", slog.Error(err))
logger.Error(ctx, "failed to update lifecycle state", slog.Error(err))
httpapi.InternalServerError(rw, err)
return
}
Expand Down
3 changes: 0 additions & 3 deletionsscripts/coder-dev.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,4 @@ if [[ ! -x "${CODER_DEV_BIN}" ]]; then
exit 1
fi

if [[ -x /tmp/coder ]]; then
CODER_DEV_BIN=/tmp/coder
fi
exec "${CODER_DEV_BIN}" --global-config "${CODER_DEV_DIR}" "$@"

[8]ページ先頭

©2009-2025 Movatter.jp