From e9d4f5f7a0a3f5a51ad660e0362d6a16dbcae056 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 10 Dec 2024 16:08:01 +0800 Subject: [PATCH] metrics: add handler performance metrics (#22581) --- metrics/histogram.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/metrics/histogram.go b/metrics/histogram.go index 46f3bbd2f138b..2c54ce8b4063e 100644 --- a/metrics/histogram.go +++ b/metrics/histogram.go @@ -26,6 +26,15 @@ func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram { return r.GetOrRegister(name, func() Histogram { return NewHistogram(s) }).(Histogram) } +// GetOrRegisterHistogramLazy returns an existing Histogram or constructs and +// registers a new StandardHistogram. +func GetOrRegisterHistogramLazy(name string, r Registry, s func() Sample) Histogram { + if nil == r { + r = DefaultRegistry + } + return r.GetOrRegister(name, func() Histogram { return NewHistogram(s()) }).(Histogram) +} + // NewHistogram constructs a new StandardHistogram from a Sample. func NewHistogram(s Sample) Histogram { if !Enabled {