Skip to content

Commit

Permalink
rpc: fix ns/µs mismatch in metrics (#28649)
Browse files Browse the repository at this point in the history
The rpc/duration/all meter was in nanoseconds, the individual meter in microseconds.
This PR changes it so both of them use nanoseconds.
  • Loading branch information
holiman authored Dec 8, 2023
1 parent 77c4bbc commit 5a45e7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions metrics/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,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))
}

// timerSnapshot is a read-only copy of another Timer.
Expand Down
2 changes: 1 addition & 1 deletion rpc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ 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())
}

0 comments on commit 5a45e7a

Please sign in to comment.