From 280657a8bd8f103a71f8a77d6380bb4b151a13bf Mon Sep 17 00:00:00 2001 From: Martin HS Date: Fri, 8 Dec 2023 09:40:50 +0100 Subject: [PATCH] =?UTF-8?q?rpc:=20fix=20ns/=C2=B5s=20mismatch=20in=20metri?= =?UTF-8?q?cs=20(#28649)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rpc/duration/all meter was in nanoseconds, the individual meter in microseconds. This PR changes it so both of them use nanoseconds. --- metrics/timer.go | 10 ++++------ rpc/metrics.go | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/metrics/timer.go b/metrics/timer.go index 2e1a9be472..4fcc297d24 100644 --- a/metrics/timer.go +++ b/metrics/timer.go @@ -225,20 +225,18 @@ func (t *StandardTimer) Time(f func()) { t.Update(time.Since(ts)) } -// Record the duration of an event. +// Record the duration of an event, in nanoseconds. func (t *StandardTimer) Update(d time.Duration) { t.mutex.Lock() defer t.mutex.Unlock() - t.histogram.Update(int64(d)) + t.histogram.Update(d.Nanoseconds()) t.meter.Mark(1) } // Record the duration of an event that started at a time and ends now. +// The record uses nanoseconds. func (t *StandardTimer) UpdateSince(ts time.Time) { - t.mutex.Lock() - defer t.mutex.Unlock() - t.histogram.Update(int64(time.Since(ts))) - t.meter.Mark(1) + t.Update(time.Since(ts)) } // Variance returns the variance of the values in the sample. diff --git a/rpc/metrics.go b/rpc/metrics.go index 2a87db94c4..e44e8d76e1 100644 --- a/rpc/metrics.go +++ b/rpc/metrics.go @@ -46,7 +46,7 @@ func updateServeTimeHistogram(method string, success bool, elapsed time.Duration metrics.NewExpDecaySample(1028, 0.015), ) } - metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Microseconds()) + metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Nanoseconds()) } func newRPCRequestGauge(method string) metrics.Gauge {