helper/metricsutil: Prevent potential Ticker leak (#10913)

This commit is contained in:
Brian Kassouf 2021-02-18 20:31:53 -08:00 committed by GitHub
parent 0ad63e5a20
commit 6f3d179635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -205,6 +205,8 @@ func (p *GaugeCollectionProcess) streamGaugesToSink(values []GaugeLabelValues) {
// 1 second / 500 = 2 ms each, so we can send 25 per 50 milliseconds.
// That should be one or two packets.
sendTick := p.clock.NewTicker(50 * time.Millisecond)
defer sendTick.Stop()
batchSize := 25
for i, lv := range values {
if i > 0 && i%batchSize == 0 {
@ -221,7 +223,6 @@ func (p *GaugeCollectionProcess) streamGaugesToSink(values []GaugeLabelValues) {
}
p.sink.SetGaugeWithLabels(p.key, lv.Value, lv.Labels)
}
sendTick.Stop()
}
// Run should be called as a goroutine.