Skip to content

Commit

Permalink
fix(outputs.prometheus): expire during add
Browse files Browse the repository at this point in the history
Currently, we are only expiring data is someone is getting the data.
This means that if data is continiously pushed, but not gathered, the
usage can grow and grow. This change forces expiration during add,
similar to how v2 handles this as well.

fixes: influxdata#9821
  • Loading branch information
powersj committed Nov 3, 2022
1 parent 497297a commit c73b04b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/outputs/prometheus_client/v1/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c73b04b

Please sign in to comment.