fix(outputs.prometheus): expire during add (#12160)

fixes https://github.com/influxdata/telegraf/issues/9821
This commit is contained in:
Joshua Powers 2022-11-07 11:36:34 -07:00 committed by GitHub
parent 67d1ca0f0f
commit a1de125ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -77,6 +77,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.Lock()
defer c.Unlock()
// Expire metrics, doing this on Collect ensure metrics are removed even if no
// new metrics are added to the output.
c.Expire(time.Now(), c.ExpirationInterval)
for name, family := range c.fam {
@ -366,6 +368,10 @@ func (c *Collector) Add(metrics []telegraf.Metric) error {
c.addMetricFamily(point, sample, mname, sampleID)
}
}
// Expire metrics, doing this on Add ensure metrics are removed even if no
// one is querying the data.
c.Expire(time.Now(), c.ExpirationInterval)
}
return nil
}