From 526898ad9f860adb6d220a81571bacbc9731af62 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 12 Oct 2025 15:59:04 +0300 Subject: [PATCH] add HistogramExt method with custom quantiles Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 4 ++-- victoriametrics.go | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7df2ad9..a397def 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.24.4 require ( github.com/VictoriaMetrics/metrics v1.40.2 - go.unistack.org/micro/v4 v4.1.22 + go.unistack.org/micro/v4 v4.1.23 ) require ( diff --git a/go.sum b/go.sum index 2a827c0..74ae80d 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OL github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY= go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk= go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec= -go.unistack.org/micro/v4 v4.1.22 h1:CBRwTxj53gtFkQKyzUeoIad9LyyJaMCJDcsmzUwXHdI= -go.unistack.org/micro/v4 v4.1.22/go.mod h1:nlBXTbx0rQrSZX4HPp2m57PHmpuGPWUd0O+jpUIiPto= +go.unistack.org/micro/v4 v4.1.23 h1:T9O1O1mN60JHqIAIw+XkNik8xb0h90O9fJ55uQMb8VU= +go.unistack.org/micro/v4 v4.1.23/go.mod h1:nlBXTbx0rQrSZX4HPp2m57PHmpuGPWUd0O+jpUIiPto= golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= diff --git a/victoriametrics.go b/victoriametrics.go index 97b3668..d8faee4 100644 --- a/victoriametrics.go +++ b/victoriametrics.go @@ -69,7 +69,14 @@ func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...st func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram { if r.prometheusCompat { - return r.set.GetOrCreatePrometheusHistogram(r.buildName(name, labels...)) + return r.set.GetOrCreatePrometheusHistogramExt(r.buildName(name, labels...), r.opts.Quantiles) + } + return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) +} + +func (r *victoriametricsMeter) HistogramExt(name string, quantiles []float64, labels ...string) meter.Histogram { + if r.prometheusCompat { + return r.set.GetOrCreatePrometheusHistogramExt(r.buildName(name, labels...), quantiles) } return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) } @@ -98,6 +105,9 @@ func (r *victoriametricsMeter) Init(opts ...meter.Option) error { if v, ok := r.opts.Context.Value(prometheusCompatKey{}).(bool); ok && v { r.prometheusCompat = v } + if r.opts.Quantiles == nil { + r.opts.Quantiles = meter.DefaultQuantiles + } return nil }