@@ -72,7 +72,8 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
72
72
codersdk .WithLogger (logger ),
73
73
codersdk .WithLogBodies ())
74
74
75
- logger .Info (ctx ,fmt .Sprintf ("user %q created" ,newUser .Username ),slog .F ("id" ,newUser .ID .String ()))
75
+ //nolint:gocritic // short log is fine
76
+ logger .Info (ctx ,"user created" ,slog .F ("username" ,newUser .Username ),slog .F ("user_id" ,newUser .ID .String ()))
76
77
77
78
workspaceBuildConfig := r .cfg .Workspace
78
79
workspaceBuildConfig .OrganizationID = r .cfg .User .OrganizationID
@@ -107,7 +108,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
107
108
return xerrors .Errorf ("timeout waiting for initial workspace build to complete: %w" ,err )
108
109
}
109
110
110
- logger .Info (ctx ,fmt . Sprintf ( "stopping workspace %q " ,workspace .Name ))
111
+ logger .Info (ctx ,"stopping workspace" , slog . F ( "workspace_name " ,workspace .Name ))
111
112
112
113
_ ,err = newUserClient .CreateWorkspaceBuild (ctx ,workspace .ID , codersdk.CreateWorkspaceBuildRequest {
113
114
Transition :codersdk .WorkspaceTransitionStop ,
@@ -129,20 +130,19 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
129
130
return xerrors .Errorf ("timeout waiting for stop build to complete: %w" ,err )
130
131
}
131
132
132
- logger .Info (ctx ,fmt . Sprintf ( "workspace%q stopped successfully" ,workspace .Name ))
133
+ logger .Info (ctx ,"workspace stopped successfully" , slog . F ( "workspace_name " ,workspace .Name ))
133
134
134
135
logger .Info (ctx ,"waiting for all runners to reach barrier" )
135
136
reachedBarrier = true
136
137
r .cfg .SetupBarrier .Done ()
137
138
r .cfg .SetupBarrier .Wait ()
138
139
logger .Info (ctx ,"all runners reached barrier, proceeding with autostart schedule" )
139
140
140
- testStartTime := time .Now ()
141
+ testStartTime := time .Now (). UTC ()
141
142
autostartTime := testStartTime .Add (r .cfg .AutostartDelay ).Round (time .Minute )
142
- timeUntilAutostart := autostartTime .Sub (testStartTime )
143
143
schedule := fmt .Sprintf ("CRON_TZ=UTC %d %d * * *" ,autostartTime .Minute (),autostartTime .Hour ())
144
144
145
- logger .Info (ctx ,fmt . Sprintf ( "setting autostart schedule for workspace %q: %s" ,workspace .Name ,schedule ))
145
+ logger .Info (ctx ,"setting autostart schedule for workspace" , slog . F ( "workspace_name" ,workspace .Name ), slog . F ( "schedule" ,schedule ))
146
146
147
147
err = newUserClient .UpdateWorkspaceAutostart (ctx ,workspace .ID , codersdk.UpdateWorkspaceAutostartRequest {
148
148
Schedule :& schedule ,
@@ -152,9 +152,9 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
152
152
return xerrors .Errorf ("update workspace autostart: %w" ,err )
153
153
}
154
154
155
- logger .Info (ctx ,fmt . Sprintf ( "waiting for workspace%q to autostart" ,workspace .Name ))
155
+ logger .Info (ctx ,"waiting for workspace to autostart" , slog . F ( "workspace_name " ,workspace .Name ))
156
156
157
- autostartInitiateCtx ,cancel4 := context .WithTimeout (ctx ,timeUntilAutostart + r .cfg .AutostartTimeout )
157
+ autostartInitiateCtx ,cancel4 := context .WithDeadline (ctx ,autostartTime . Add ( r .cfg .AutostartDelay ) )
158
158
defer cancel4 ()
159
159
160
160
logger .Info (ctx ,"listening for workspace updates to detect autostart build" )
@@ -189,7 +189,7 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
189
189
190
190
r .autostartTotalLatency = time .Since (autostartTime )
191
191
192
- logger .Info (ctx ,fmt . Sprintf ( "autostartcompleted in %v " ,r .autostartTotalLatency ))
192
+ logger .Info (ctx ,"autostartworkspace build complete" , slog . F ( "duration " ,r .autostartTotalLatency ))
193
193
r .cfg .Metrics .RecordCompletion (r .autostartTotalLatency ,newUser .Username ,workspace .Name )
194
194
195
195
return nil