@@ -25,6 +25,7 @@ type Bundle struct {
25
25
Deployment Deployment `json:"deployment"`
26
26
Network Network `json:"network"`
27
27
Workspace Workspace `json:"workspace"`
28
+ Agent Agent `json:"agent"`
28
29
Logs []string `json:"logs"`
29
30
}
30
31
@@ -49,8 +50,11 @@ type Workspace struct {
49
50
TemplateVersion codersdk.TemplateVersion `json:"template_version"`
50
51
TemplateFileBase64 string `json:"template_file_base64"`
51
52
BuildLogs []codersdk.ProvisionerJobLog `json:"build_logs"`
52
- Agent codersdk.WorkspaceAgent `json:"agent"`
53
- AgentStartupLogs []codersdk.WorkspaceAgentLog `json:"startup_logs"`
53
+ }
54
+
55
+ type Agent struct {
56
+ Agent codersdk.WorkspaceAgent `json:"agent"`
57
+ StartupLogs []codersdk.WorkspaceAgentLog `json:"startup_logs"`
54
58
}
55
59
56
60
// Deps is a set of dependencies for discovering information
@@ -170,7 +174,7 @@ func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger,
170
174
return n
171
175
}
172
176
173
- func WorkspaceInfo (ctx context.Context , client * codersdk.Client , log slog.Logger , workspaceID , agentID uuid.UUID ) Workspace {
177
+ func WorkspaceInfo (ctx context.Context , client * codersdk.Client , log slog.Logger , workspaceID uuid.UUID ) Workspace {
174
178
var (
175
179
w Workspace
176
180
eg errgroup.Group
@@ -181,10 +185,6 @@ func WorkspaceInfo(ctx context.Context, client *codersdk.Client, log slog.Logger
181
185
return w
182
186
}
183
187
184
- if agentID == uuid .Nil {
185
- log .Error (ctx , "no agent id specified" )
186
- }
187
-
188
188
// dependency, cannot fetch concurrently
189
189
ws , err := client .Workspace (ctx , workspaceID )
190
190
if err != nil {
@@ -198,15 +198,6 @@ func WorkspaceInfo(ctx context.Context, client *codersdk.Client, log slog.Logger
198
198
}
199
199
w .Workspace = ws
200
200
201
- eg .Go (func () error {
202
- agt , err := client .WorkspaceAgent (ctx , agentID )
203
- if err != nil {
204
- return xerrors .Errorf ("fetch workspace agent: %w" , err )
205
- }
206
- w .Agent = agt
207
- return nil
208
- })
209
-
210
201
eg .Go (func () error {
211
202
buildLogCh , closer , err := client .WorkspaceBuildLogsAfter (ctx , ws .LatestBuild .ID , 0 )
212
203
if err != nil {
@@ -221,24 +212,6 @@ func WorkspaceInfo(ctx context.Context, client *codersdk.Client, log slog.Logger
221
212
return nil
222
213
})
223
214
224
- eg .Go (func () error {
225
- if len (w .Workspace .LatestBuild .Resources ) == 0 {
226
- log .Warn (ctx , "workspace build has no resources" )
227
- return nil
228
- }
229
- agentLogCh , closer , err := client .WorkspaceAgentLogsAfter (ctx , agentID , 0 , false )
230
- if err != nil {
231
- return xerrors .Errorf ("fetch agent startup logs: %w" , err )
232
- }
233
- defer closer .Close ()
234
- var logs []codersdk.WorkspaceAgentLog
235
- for logChunk := range agentLogCh {
236
- logs = append (w .AgentStartupLogs , logChunk ... )
237
- }
238
- w .AgentStartupLogs = logs
239
- return nil
240
- })
241
-
242
215
eg .Go (func () error {
243
216
if w .Workspace .TemplateActiveVersionID == uuid .Nil {
244
217
return xerrors .Errorf ("workspace has nil template active version id" )
@@ -296,6 +269,47 @@ func WorkspaceInfo(ctx context.Context, client *codersdk.Client, log slog.Logger
296
269
return w
297
270
}
298
271
272
+ func AgentInfo (ctx context.Context , client * codersdk.Client , log slog.Logger , agentID uuid.UUID ) Agent {
273
+ var (
274
+ a Agent
275
+ eg errgroup.Group
276
+ )
277
+
278
+ if agentID == uuid .Nil {
279
+ log .Error (ctx , "no agent id specified" )
280
+ return a
281
+ }
282
+
283
+ eg .Go (func () error {
284
+ agt , err := client .WorkspaceAgent (ctx , agentID )
285
+ if err != nil {
286
+ return xerrors .Errorf ("fetch workspace agent: %w" , err )
287
+ }
288
+ a .Agent = agt
289
+ return nil
290
+ })
291
+
292
+ eg .Go (func () error {
293
+ agentLogCh , closer , err := client .WorkspaceAgentLogsAfter (ctx , agentID , 0 , false )
294
+ if err != nil {
295
+ return xerrors .Errorf ("fetch agent startup logs: %w" , err )
296
+ }
297
+ defer closer .Close ()
298
+ var logs []codersdk.WorkspaceAgentLog
299
+ for logChunk := range agentLogCh {
300
+ logs = append (logs , logChunk ... )
301
+ }
302
+ a .StartupLogs = logs
303
+ return nil
304
+ })
305
+
306
+ if err := eg .Wait (); err != nil {
307
+ log .Error (ctx , "fetch agent information" , slog .Error (err ))
308
+ }
309
+
310
+ return a
311
+ }
312
+
299
313
// Run generates a support bundle with the given dependencies.
300
314
func Run (ctx context.Context , d * Deps ) (* Bundle , error ) {
301
315
var b Bundle
@@ -337,7 +351,7 @@ func Run(ctx context.Context, d *Deps) (*Bundle, error) {
337
351
return nil
338
352
})
339
353
eg .Go (func () error {
340
- wi := WorkspaceInfo (ctx , d .Client , d .Log , d .WorkspaceID , d . AgentID )
354
+ wi := WorkspaceInfo (ctx , d .Client , d .Log , d .WorkspaceID )
341
355
b .Workspace = wi
342
356
return nil
343
357
})
@@ -346,6 +360,11 @@ func Run(ctx context.Context, d *Deps) (*Bundle, error) {
346
360
b .Network = ni
347
361
return nil
348
362
})
363
+ eg .Go (func () error {
364
+ ai := AgentInfo (ctx , d .Client , d .Log , d .AgentID )
365
+ b .Agent = ai
366
+ return nil
367
+ })
349
368
350
369
_ = eg .Wait ()
351
370
0 commit comments