Skip to content

Commit 2ae25c5

Browse files
committed
fixup! more debug logging
1 parent 4b08319 commit 2ae25c5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

agent/agent.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,15 @@ func (a *agent) runLoop(ctx context.Context) {
242242
}
243243
}
244244

245-
func (a *agent) collectMetadata(ctx context.Context, md codersdk.WorkspaceAgentMetadataDescription) *codersdk.WorkspaceAgentMetadataResult {
245+
func (a *agent) collectMetadata(ctx context.Context, md codersdk.WorkspaceAgentMetadataDescription, now time.Time) *codersdk.WorkspaceAgentMetadataResult {
246246
var out bytes.Buffer
247247
result := &codersdk.WorkspaceAgentMetadataResult{
248248
// CollectedAt is set here for testing purposes and overrode by
249249
// coderd to the time of server receipt to solve clock skew.
250250
//
251251
// In the future, the server may accept the timestamp from the agent
252252
// if it can guarantee the clocks are synchronized.
253-
CollectedAt: time.Now(),
253+
CollectedAt: now,
254254
}
255255
cmdPty, err := a.sshServer.CreateCommand(ctx, md.Script, nil)
256256
if err != nil {
@@ -337,9 +337,7 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
337337
case <-ctx.Done():
338338
return
339339
case mr := <-metadataResults:
340-
lastCollectedAtMu.Lock()
341-
lastCollectedAts[mr.key] = mr.result.CollectedAt
342-
lastCollectedAtMu.Unlock()
340+
343341
err := a.client.PostMetadata(ctx, mr.key, *mr.result)
344342
if err != nil {
345343
a.logger.Error(ctx, "agent failed to report metadata", slog.Error(err))
@@ -406,7 +404,7 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
406404
// If the interval is zero, we assume the user just wants
407405
// a single collection at startup, not a spinning loop.
408406
if md.Interval == 0 {
409-
logger.Debug(ctx, "skipping metadata, interval 0 and alredy collected once")
407+
logger.Debug(ctx, "skipping metadata, interval 0 and already collected once")
410408
return
411409
}
412410
// The last collected value isn't quite stale yet, so we skip it.
@@ -434,14 +432,18 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
434432
ctx, cancel := context.WithTimeout(ctx, ctxTimeout)
435433
defer cancel()
436434

435+
now := time.Now()
437436
select {
438437
case <-ctx.Done():
439438
logger.Debug(ctx, "metadata collection timed out", slog.F("timeout", ctxTimeout))
440439
case metadataResults <- metadataResultAndKey{
441440
key: md.Key,
442-
result: a.collectMetadata(ctx, md),
441+
result: a.collectMetadata(ctx, md, now),
443442
}:
444-
logger.Debug(ctx, "sent metadata")
443+
logger.Debug(ctx, "sent metadata", slog.F("took", time.Since(now).String()))
444+
lastCollectedAtMu.Lock()
445+
lastCollectedAts[md.Key] = now
446+
lastCollectedAtMu.Unlock()
445447
}
446448
})
447449
}

0 commit comments

Comments
 (0)