Skip to content

Commit cf17cd4

Browse files
committed
fix review comments
1 parent fb4cdad commit cf17cd4

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

agent/agentcontainers/api.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (api *API) updaterLoop() {
296296
if err := api.cleanupSubAgents(api.ctx); err != nil {
297297
api.logger.Error(api.ctx, "cleanup subagents failed", slog.Error(err))
298298
} else {
299-
api.logger.Debug(api.ctx, "subagent cleanup complete")
299+
api.logger.Debug(api.ctx, "cleanup subagents complete")
300300
}
301301

302302
// Perform an initial update to populate the container list, this
@@ -440,6 +440,20 @@ func (api *API) updateContainers(ctx context.Context) error {
440440
// on the latest list of containers. This method assumes that api.mu is
441441
// held.
442442
func (api *API) processUpdatedContainersLocked(ctx context.Context, updated codersdk.WorkspaceAgentListContainersResponse) {
443+
dcFields := func(dc codersdk.WorkspaceAgentDevcontainer) []slog.Field {
444+
f := []slog.Field{
445+
slog.F("devcontainer_id", dc.ID),
446+
slog.F("devcontainer_name", dc.Name),
447+
slog.F("workspace_folder", dc.WorkspaceFolder),
448+
slog.F("config_path", dc.ConfigPath),
449+
}
450+
if dc.Container != nil {
451+
f = append(f, slog.F("container_id", dc.Container.ID))
452+
f = append(f, slog.F("container_name", dc.Container.FriendlyName))
453+
}
454+
return f
455+
}
456+
443457
// Reset the container links in known devcontainers to detect if
444458
// they still exist.
445459
for _, dc := range api.knownDevcontainers {
@@ -460,6 +474,13 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
460474
continue
461475
}
462476

477+
logger := api.logger.With(
478+
slog.F("container_id", updated.Containers[i].ID),
479+
slog.F("container_name", updated.Containers[i].FriendlyName),
480+
slog.F("workspace_folder", workspaceFolder),
481+
slog.F("config_file", configFile),
482+
)
483+
463484
if dc, ok := api.knownDevcontainers[workspaceFolder]; ok {
464485
// If no config path is set, this devcontainer was defined
465486
// in Terraform without the optional config file. Assume the
@@ -468,7 +489,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
468489
if dc.ConfigPath == "" && configFile != "" {
469490
dc.ConfigPath = configFile
470491
if err := api.watcher.Add(configFile); err != nil {
471-
api.logger.Error(ctx, "watch devcontainer config file failed", slog.Error(err), slog.F("file", configFile))
492+
logger.With(dcFields(dc)...).Error(ctx, "watch devcontainer config file failed", slog.Error(err))
472493
}
473494
}
474495

@@ -477,13 +498,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
477498
continue
478499
}
479500

480-
if configFile != "" {
481-
if err := api.watcher.Add(configFile); err != nil {
482-
api.logger.Error(ctx, "watch devcontainer config file failed", slog.Error(err), slog.F("file", configFile))
483-
}
484-
}
485-
486-
api.knownDevcontainers[workspaceFolder] = codersdk.WorkspaceAgentDevcontainer{
501+
dc := codersdk.WorkspaceAgentDevcontainer{
487502
ID: uuid.New(),
488503
Name: "", // Updated later based on container state.
489504
WorkspaceFolder: workspaceFolder,
@@ -492,11 +507,21 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
492507
Dirty: false, // Updated later based on config file changes.
493508
Container: container,
494509
}
510+
511+
if configFile != "" {
512+
if err := api.watcher.Add(configFile); err != nil {
513+
logger.With(dcFields(dc)...).Error(ctx, "watch devcontainer config file failed", slog.Error(err))
514+
}
515+
}
516+
517+
api.knownDevcontainers[workspaceFolder] = dc
495518
}
496519

497520
// Iterate through all known devcontainers and update their status
498521
// based on the current state of the containers.
499522
for _, dc := range api.knownDevcontainers {
523+
logger := api.logger.With(dcFields(dc)...)
524+
500525
if dc.Container != nil {
501526
if !api.devcontainerNames[dc.Name] {
502527
// If the devcontainer name wasn't set via terraform, we
@@ -532,7 +557,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
532557
if _, injected := api.injectedSubAgentProcs[dc.Container.ID]; !injected && dc.Status == codersdk.WorkspaceAgentDevcontainerStatusRunning {
533558
err := api.injectSubAgentIntoContainerLocked(ctx, dc)
534559
if err != nil {
535-
api.logger.Error(ctx, "inject subagent into container failed", slog.Error(err))
560+
logger.Error(ctx, "inject subagent into container failed", slog.Error(err))
536561
}
537562
}
538563

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy