@@ -108,7 +108,7 @@ func New(options Options) Agent {
108
108
}
109
109
}
110
110
if options .ReportMetadataInterval == 0 {
111
- options .ReportMetadataInterval = 1 * time .Minute
111
+ options .ReportMetadataInterval = time .Second
112
112
}
113
113
if options .ServiceBannerRefreshInterval == 0 {
114
114
options .ServiceBannerRefreshInterval = 2 * time .Minute
@@ -339,15 +339,19 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
339
339
// baseInterval to run.
340
340
flight := trySingleflight {m : map [string ]struct {}{}}
341
341
342
+ postMetadata := func (mr metadataResultAndKey ) {
343
+ err := a .client .PostMetadata (ctx , mr .key , * mr .result )
344
+ if err != nil {
345
+ a .logger .Error (ctx , "agent failed to report metadata" , slog .Error (err ))
346
+ }
347
+ }
348
+
342
349
for {
343
350
select {
344
351
case <- ctx .Done ():
345
352
return
346
353
case mr := <- metadataResults :
347
- err := a .client .PostMetadata (ctx , mr .key , * mr .result )
348
- if err != nil {
349
- a .logger .Error (ctx , "agent failed to report metadata" , slog .Error (err ))
350
- }
354
+ postMetadata (mr )
351
355
continue
352
356
case <- baseTicker .C :
353
357
}
@@ -409,8 +413,14 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
409
413
if md .Interval == 0 {
410
414
return
411
415
}
416
+ intervalUnit := time .Second
417
+ // reportMetadataInterval is only less than a second in tests,
418
+ // so adjust the interval unit for them.
419
+ if a .reportMetadataInterval < time .Second {
420
+ intervalUnit = 100 * time .Millisecond
421
+ }
412
422
// The last collected value isn't quite stale yet, so we skip it.
413
- if collectedAt .Add (a . reportMetadataInterval ).After (time .Now ()) {
423
+ if collectedAt .Add (time . Duration ( md . Interval ) * intervalUnit ).After (time .Now ()) {
414
424
return
415
425
}
416
426
}
0 commit comments