mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(agent): check agent metadata every second instead of minute (#8614)
This commit is contained in:
+16
-6
@@ -108,7 +108,7 @@ func New(options Options) Agent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if options.ReportMetadataInterval == 0 {
|
if options.ReportMetadataInterval == 0 {
|
||||||
options.ReportMetadataInterval = 1 * time.Minute
|
options.ReportMetadataInterval = time.Second
|
||||||
}
|
}
|
||||||
if options.ServiceBannerRefreshInterval == 0 {
|
if options.ServiceBannerRefreshInterval == 0 {
|
||||||
options.ServiceBannerRefreshInterval = 2 * time.Minute
|
options.ServiceBannerRefreshInterval = 2 * time.Minute
|
||||||
@@ -339,15 +339,19 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
|
|||||||
// baseInterval to run.
|
// baseInterval to run.
|
||||||
flight := trySingleflight{m: map[string]struct{}{}}
|
flight := trySingleflight{m: map[string]struct{}{}}
|
||||||
|
|
||||||
|
postMetadata := func(mr metadataResultAndKey) {
|
||||||
|
err := a.client.PostMetadata(ctx, mr.key, *mr.result)
|
||||||
|
if err != nil {
|
||||||
|
a.logger.Error(ctx, "agent failed to report metadata", slog.Error(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case mr := <-metadataResults:
|
case mr := <-metadataResults:
|
||||||
err := a.client.PostMetadata(ctx, mr.key, *mr.result)
|
postMetadata(mr)
|
||||||
if err != nil {
|
|
||||||
a.logger.Error(ctx, "agent failed to report metadata", slog.Error(err))
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
case <-baseTicker.C:
|
case <-baseTicker.C:
|
||||||
}
|
}
|
||||||
@@ -409,8 +413,14 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
|
|||||||
if md.Interval == 0 {
|
if md.Interval == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
intervalUnit := time.Second
|
||||||
|
// reportMetadataInterval is only less than a second in tests,
|
||||||
|
// so adjust the interval unit for them.
|
||||||
|
if a.reportMetadataInterval < time.Second {
|
||||||
|
intervalUnit = 100 * time.Millisecond
|
||||||
|
}
|
||||||
// The last collected value isn't quite stale yet, so we skip it.
|
// The last collected value isn't quite stale yet, so we skip it.
|
||||||
if collectedAt.Add(a.reportMetadataInterval).After(time.Now()) {
|
if collectedAt.Add(time.Duration(md.Interval) * intervalUnit).After(time.Now()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user