mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add buffering to provisioner job logs (#4918)
* feat: Add bufferring to provisioner job logs This should improve overall build performance, and especially under load. It removes the old `id` column on the `provisioner_job_logs` table and replaces it with an auto-incrementing big integer to preserve order. Funny enough, we never had to care about order before because inserts would at minimum be 1ms different. Now they aren't, so the order needs to be preserved. * Fix log bufferring * Fix frontend log streaming * Fix JS test
This commit is contained in:
@@ -41,14 +41,13 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error {
|
||||
req.Name = "test-" + randName
|
||||
}
|
||||
|
||||
after := time.Now()
|
||||
workspace, err := r.client.CreateWorkspace(ctx, r.cfg.OrganizationID, r.cfg.UserID, req)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("create workspace: %w", err)
|
||||
}
|
||||
r.workspaceID = workspace.ID
|
||||
|
||||
err = waitForBuild(ctx, logs, r.client, workspace.LatestBuild.ID, after)
|
||||
err = waitForBuild(ctx, logs, r.client, workspace.LatestBuild.ID)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("wait for build: %w", err)
|
||||
}
|
||||
@@ -68,7 +67,6 @@ func (r *Runner) Cleanup(ctx context.Context, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
after := time.Now()
|
||||
build, err := r.client.CreateWorkspaceBuild(ctx, r.workspaceID, codersdk.CreateWorkspaceBuildRequest{
|
||||
Transition: codersdk.WorkspaceTransitionDelete,
|
||||
})
|
||||
@@ -78,7 +76,7 @@ func (r *Runner) Cleanup(ctx context.Context, _ string) error {
|
||||
|
||||
// TODO: capture these logs
|
||||
logs := io.Discard
|
||||
err = waitForBuild(ctx, logs, r.client, build.ID, after)
|
||||
err = waitForBuild(ctx, logs, r.client, build.ID)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("wait for build: %w", err)
|
||||
}
|
||||
@@ -86,7 +84,7 @@ func (r *Runner) Cleanup(ctx context.Context, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func waitForBuild(ctx context.Context, w io.Writer, client *codersdk.Client, buildID uuid.UUID, after time.Time) error {
|
||||
func waitForBuild(ctx context.Context, w io.Writer, client *codersdk.Client, buildID uuid.UUID) error {
|
||||
_, _ = fmt.Fprint(w, "Build is currently queued...")
|
||||
|
||||
// Wait for build to start.
|
||||
@@ -106,7 +104,7 @@ func waitForBuild(ctx context.Context, w io.Writer, client *codersdk.Client, bui
|
||||
|
||||
_, _ = fmt.Fprintln(w, "\nBuild started! Streaming logs below:")
|
||||
|
||||
logs, closer, err := client.WorkspaceBuildLogsAfter(ctx, buildID, after)
|
||||
logs, closer, err := client.WorkspaceBuildLogsAfter(ctx, buildID, 0)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("start streaming build logs: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user