- Notifications
You must be signed in to change notification settings - Fork928
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
73f19d6
43a0f87
8ff8c02
b4f78eb
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
if script == "" { | ||
return nil | ||
} | ||
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,fmt.Sprintf("close%sscript log file", lifecycle), slog.Error(err)) | ||
} | ||
}() | ||
cmdPty, err := a.sshServer.CreateCommand(ctx, script, nil) | ||
if err != nil { | ||
return xerrors.Errorf("%s script:create command: %w", lifecycle, err) | ||
} | ||
cmd := cmdPty.AsExec() | ||
@@ -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%sscript logs: %w", lifecycle, err) | ||
} | ||
defer func() { | ||
_ = logsWriter.Close() | ||
@@ -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,fmt.Sprintf("%sscript failed", lifecycle), slog.F("execution_time", execTime), slog.F("exit_code", exitCode), slog.Error(err)) | ||
} else { | ||
logger.Info(ctx,fmt.Sprintf("%sscript completed", lifecycle), slog.F("execution_time", execTime), slog.F("exit_code", exitCode)) | ||
} | ||
}() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Review: Small cleanup to unify logging between startup and shutdown scripts. | ||
@@ -907,7 +906,7 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) (err er | ||
return ctx.Err() | ||
} | ||
return xerrors.Errorf("%s script:run: %w", lifecycle, err) | ||
} | ||
return nil | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
COMMENT ON COLUMN workspace_agent_startup_logs.eof IS 'End of file reached'; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -26,7 +26,4 @@ if [[ ! -x "${CODER_DEV_BIN}" ]]; then | ||
exit 1 | ||
fi | ||
exec "${CODER_DEV_BIN}" --global-config "${CODER_DEV_DIR}" "$@" |