Skip to content

Commit 71d4e4e

Browse files
authored
fix(agent): check agent metadata every second instead of minute (#8614)
1 parent c8d65de commit 71d4e4e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

agent/agent.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func New(options Options) Agent {
108108
}
109109
}
110110
if options.ReportMetadataInterval == 0 {
111-
options.ReportMetadataInterval = 1 * time.Minute
111+
options.ReportMetadataInterval = time.Second
112112
}
113113
if options.ServiceBannerRefreshInterval == 0 {
114114
options.ServiceBannerRefreshInterval = 2 * time.Minute
@@ -339,15 +339,19 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
339339
// baseInterval to run.
340340
flight := trySingleflight{m: map[string]struct{}{}}
341341

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+
342349
for {
343350
select {
344351
case <-ctx.Done():
345352
return
346353
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)
351355
continue
352356
case <-baseTicker.C:
353357
}
@@ -409,8 +413,14 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
409413
if md.Interval == 0 {
410414
return
411415
}
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+
}
412422
// 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()) {
414424
return
415425
}
416426
}

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