Skip to content

Commit

Permalink
move to second function
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Nov 29, 2023
1 parent a3c7578 commit e2ecad8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions plugins/outputs/prometheus_client/v1/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,21 @@ func sorted(metrics []telegraf.Metric) []telegraf.Metric {
}

func (c *Collector) Add(metrics []telegraf.Metric) error {
c.addMetrics(metrics)

// Expire metrics, doing this on Add ensure metrics are removed even if no
// new metrics are added to the output.
if c.ExpirationInterval != 0 {
c.Expire(time.Now())
}

return nil
}

func (c *Collector) addMetrics(metrics []telegraf.Metric) {
c.Lock()
defer c.Unlock()

now := time.Now()

for _, point := range sorted(metrics) {
Expand Down Expand Up @@ -392,16 +406,6 @@ func (c *Collector) Add(metrics []telegraf.Metric) error {
}
}
}

c.Unlock()

// Expire metrics, doing this on Add ensure metrics are removed even if no
// new metrics are added to the output.
if c.ExpirationInterval != 0 {
c.Expire(time.Now())
}

return nil
}

func (c *Collector) Expire(now time.Time) {
Expand Down

0 comments on commit e2ecad8

Please sign in to comment.