Skip to content

Commit

Permalink
Expire metrics on query in addition to on add (influxdata#6981)
Browse files Browse the repository at this point in the history
Ensures that expired metrics are removed even when no new data is sent
to the output.
  • Loading branch information
danielnelson authored Feb 4, 2020
1 parent 709ba9c commit f6f6208
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/outputs/prometheus_client/v2/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ 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.
if c.expireDuration != 0 {
c.coll.Expire(time.Now(), c.expireDuration)
}

for _, family := range c.coll.GetProto() {
for _, metric := range family.Metric {
ch <- &Metric{family: family, metric: metric}
Expand All @@ -80,8 +86,11 @@ func (c *Collector) Add(metrics []telegraf.Metric) error {
c.coll.Add(metric)
}

// Expire metrics, doing this on Add ensure metrics are removed even if no
// one is querying the data.
if c.expireDuration != 0 {
c.coll.Expire(time.Now(), c.expireDuration)
}

return nil
}

0 comments on commit f6f6208

Please sign in to comment.