diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 42d0412a12..8149db1495 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -218,9 +218,7 @@ func handleMessage(backend Backend, peer *Peer) error { h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code) defer func(start time.Time) { sampler := func() metrics.Sample { - return metrics.ResettingSample( - metrics.NewExpDecaySample(1028, 0.015), - ) + return metrics.NewBoundedHistogramSample() } metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds()) }(time.Now()) diff --git a/eth/protocols/snap/handler.go b/eth/protocols/snap/handler.go index bd7ce9e715..968fcfbfa5 100644 --- a/eth/protocols/snap/handler.go +++ b/eth/protocols/snap/handler.go @@ -145,9 +145,7 @@ func HandleMessage(backend Backend, peer *Peer) error { h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code) defer func(start time.Time) { sampler := func() metrics.Sample { - return metrics.ResettingSample( - metrics.NewExpDecaySample(1028, 0.015), - ) + return metrics.NewBoundedHistogramSample() } metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds()) }(start) diff --git a/metrics/sample.go b/metrics/sample.go index 5398dd42d5..3ec7fff136 100644 --- a/metrics/sample.go +++ b/metrics/sample.go @@ -32,6 +32,12 @@ type Sample interface { Update(int64) } +func NewBoundedHistogramSample() Sample { + return ResettingSample( + NewExpDecaySample(1028, 0.015), + ) +} + // ExpDecaySample is an exponentially-decaying sample using a forward-decaying // priority reservoir. See Cormode et al's "Forward Decay: A Practical Time // Decay Model for Streaming Systems". diff --git a/p2p/tracker/tracker.go b/p2p/tracker/tracker.go index 6a733b9ba5..0e473420f1 100644 --- a/p2p/tracker/tracker.go +++ b/p2p/tracker/tracker.go @@ -197,9 +197,7 @@ func (t *Tracker) Fulfil(peer string, version uint, code uint64, id uint64) { h := fmt.Sprintf("%s/%s/%d/%#02x", waitHistName, t.protocol, req.version, req.reqCode) sampler := func() metrics.Sample { - return metrics.ResettingSample( - metrics.NewExpDecaySample(1028, 0.015), - ) + return metrics.NewBoundedHistogramSample() } metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(req.time).Microseconds()) } diff --git a/rpc/metrics.go b/rpc/metrics.go index ef7449ce05..4573fee110 100644 --- a/rpc/metrics.go +++ b/rpc/metrics.go @@ -42,9 +42,7 @@ func updateServeTimeHistogram(method string, success bool, elapsed time.Duration } h := fmt.Sprintf("%s/%s/%s", serveTimeHistName, method, note) sampler := func() metrics.Sample { - return metrics.ResettingSample( - metrics.NewExpDecaySample(1028, 0.015), - ) + return metrics.NewBoundedHistogramSample() } metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Nanoseconds()) }