diff --git a/metrics.go b/metrics.go index 36642a4..f0d4d3d 100644 --- a/metrics.go +++ b/metrics.go @@ -4,6 +4,7 @@ import ( "runtime" "strings" "time" + "math" iradix "github.com/hashicorp/go-immutable-radix" ) @@ -128,10 +129,14 @@ func (m *Metrics) MeasureSinceWithLabels(key []string, start time.Time, labels [ if !allowed { return } - now := time.Now() - elapsed := now.Sub(start) - msec := float32(elapsed.Nanoseconds()) / float32(m.TimerGranularity) - m.sink.AddSampleWithLabels(key, msec, labelsFiltered) + if m.TimerGranularity == 0 { + m.sink.AddSampleWithLabels(key, math.MaxFloat32, labels) + } else { + now := time.Now() + elapsed := now.Sub(start) + msec := float32(elapsed.Nanoseconds()) / float32(m.TimerGranularity) + m.sink.AddSampleWithLabels(key, msec, labels) + } } // UpdateFilter overwrites the existing filter with the given rules.