metrics: make sample respect enabled-flag

This commit is contained in:
Martin Holst Swende 2024-11-27 04:56:31 +01:00
parent 6ef3c5bdcc
commit b1dc19d7ee
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -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++