Skip to content

Commit 9badb15

Browse files
holimanzzzckck
authored andcommitted
rpc: fix ns/µs mismatch in metrics (ethereum#28649)
The rpc/duration/all meter was in nanoseconds, the individual meter in microseconds. This PR changes it so both of them use nanoseconds.
1 parent 01a4b00 commit 9badb15

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

metrics/timer.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,18 @@ func (t *StandardTimer) Time(f func()) {
225225
t.Update(time.Since(ts))
226226
}
227227

228-
// Record the duration of an event.
228+
// Record the duration of an event, in nanoseconds.
229229
func (t *StandardTimer) Update(d time.Duration) {
230230
t.mutex.Lock()
231231
defer t.mutex.Unlock()
232-
t.histogram.Update(int64(d))
232+
t.histogram.Update(d.Nanoseconds())
233233
t.meter.Mark(1)
234234
}
235235

236236
// Record the duration of an event that started at a time and ends now.
237+
// The record uses nanoseconds.
237238
func (t *StandardTimer) UpdateSince(ts time.Time) {
238-
t.mutex.Lock()
239-
defer t.mutex.Unlock()
240-
t.histogram.Update(int64(time.Since(ts)))
241-
t.meter.Mark(1)
239+
t.Update(time.Since(ts))
242240
}
243241

244242
// Variance returns the variance of the values in the sample.

rpc/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func updateServeTimeHistogram(method string, success bool, elapsed time.Duration
4646
metrics.NewExpDecaySample(1028, 0.015),
4747
)
4848
}
49-
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Microseconds())
49+
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Nanoseconds())
5050
}
5151

5252
func newRPCRequestGauge(method string) metrics.Gauge {

0 commit comments

Comments
 (0)