From b1dc19d7ee96cb60668d78afe2bdee7762e0b470 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 27 Nov 2024 04:56:31 +0100 Subject: [PATCH] metrics: make sample respect enabled-flag --- metrics/sample.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/metrics/sample.go b/metrics/sample.go index 7cbe99d3a4..dc8167809f 100644 --- a/metrics/sample.go +++ b/metrics/sample.go @@ -198,13 +198,15 @@ func (s *ExpDecaySample) Snapshot() *sampleSnapshot { // Update samples a new value. func (s *ExpDecaySample) Update(v int64) { + if !metricsEnabled { + return + } s.update(time.Now(), v) } // update samples a new value at a particular timestamp. This is a method all // its own to facilitate testing. func (s *ExpDecaySample) update(t time.Time, v int64) { - //TODO(@holiman) Check metrics.Enabled s.mutex.Lock() defer s.mutex.Unlock() s.count++ @@ -326,6 +328,9 @@ func (s *UniformSample) Snapshot() *sampleSnapshot { // Update samples a new value. func (s *UniformSample) Update(v int64) { + if !metricsEnabled { + return + } s.mutex.Lock() defer s.mutex.Unlock() s.count++