- Notifications
You must be signed in to change notification settings - Fork928
feat: add startup script logs to the ui#6558
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
99d510c
66c8ec3
1cc3e9d
45d250f
7fed360
7ce73aa
b86c400
0c4d2c3
1bb700f
736705f
f741523
54c30be
adb06ea
4061b13
4c5b630
05d536c
34fde1a
379f1f4
decde5c
d74457c
ac55f48
8d75963
cc715cd
e3a4b2c
399dad7
45c0aca
5a0b15d
b1b3fcb
6e1032c
3762e8d
f6b9fce
c48658c
4ec1a0e
b55b7a1
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 |
---|---|---|
@@ -41,6 +41,7 @@ import ( | ||
"cdr.dev/slog" | ||
"github.com/coder/coder/agent/usershell" | ||
"github.com/coder/coder/buildinfo" | ||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/coderd/gitauth" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/codersdk/agentsdk" | ||
@@ -662,16 +663,23 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error { | ||
}() | ||
startupLogsReader, startupLogsWriter := io.Pipe() | ||
defer func() { | ||
_ = startupLogsReader.Close() | ||
_ = startupLogsWriter.Close() | ||
}() | ||
writer := io.MultiWriter(startupLogsWriter, fileWriter) | ||
queuedLogs := make([]agentsdk.StartupLog, 0) | ||
var flushLogsTimer *time.Timer | ||
var logMutex sync.Mutex | ||
var logsSending bool | ||
sendLogs := func() { | ||
logMutex.Lock() | ||
if logsSending { | ||
logMutex.Unlock() | ||
return | ||
} | ||
logsSending = true | ||
toSend := make([]agentsdk.StartupLog, len(queuedLogs)) | ||
copy(toSend, queuedLogs) | ||
logMutex.Unlock() | ||
@@ -683,9 +691,13 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error { | ||
a.logger.Error(ctx, "upload startup logs", slog.Error(err)) | ||
} | ||
if ctx.Err() != nil { | ||
logMutex.Lock() | ||
logsSending = false | ||
logMutex.Unlock() | ||
return | ||
} | ||
logMutex.Lock() | ||
logsSending = false | ||
queuedLogs = queuedLogs[len(toSend):] | ||
logMutex.Unlock() | ||
} | ||
@@ -698,25 +710,25 @@ func (a *agent) runScript(ctx context.Context, lifecycle, script string) error { | ||
return | ||
} | ||
if len(queuedLogs) > 100 { | ||
gosendLogs() | ||
return | ||
} | ||
flushLogsTimer = time.AfterFunc(100*time.Millisecond, func() { | ||
sendLogs() | ||
}) | ||
} | ||
err = a.trackConnGoroutine(func() { | ||
scanner := bufio.NewScanner(startupLogsReader) | ||
kylecarbs marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
for scanner.Scan() { | ||
queueLog(agentsdk.StartupLog{ | ||
CreatedAt: database.Now(), | ||
Output: scanner.Text(), | ||
}) | ||
} | ||
}) | ||
if err != nil { | ||
return xerrors.Errorf("track conn goroutine: %w", err) | ||
} | ||
cmd, err := a.createCommand(ctx, script, nil) | ||
if err != nil { | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.