Skip to content

Commit 4869ba4

Browse files
holimanDoozers
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 4157767 commit 4869ba4

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
@@ -106,20 +106,18 @@ func (t *StandardTimer) Time(f func()) {
106106
t.Update(time.Since(ts))
107107
}
108108

109-
// Record the duration of an event.
109+
// Record the duration of an event, in nanoseconds.
110110
func (t *StandardTimer) Update(d time.Duration) {
111111
t.mutex.Lock()
112112
defer t.mutex.Unlock()
113-
t.histogram.Update(int64(d))
113+
t.histogram.Update(d.Nanoseconds())
114114
t.meter.Mark(1)
115115
}
116116

117117
// Record the duration of an event that started at a time and ends now.
118+
// The record uses nanoseconds.
118119
func (t *StandardTimer) UpdateSince(ts time.Time) {
119-
t.mutex.Lock()
120-
defer t.mutex.Unlock()
121-
t.histogram.Update(int64(time.Since(ts)))
122-
t.meter.Mark(1)
120+
t.Update(time.Since(ts))
123121
}
124122

125123
// timerSnapshot is a read-only copy of another Timer.

rpc/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ 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
}

0 commit comments

Comments
 (0)