From d0f11b77be41a5aa532c5e00cf7d556783bb4742 Mon Sep 17 00:00:00 2001 From: Eric Harmeling Date: Fri, 11 Aug 2023 11:03:19 -0400 Subject: [PATCH] metrics: assign histogram metric type on histogram construction This commit assigns prometheusgo.MetricType_HISTOGRAM to the Metadata.MetricType on histogram construction. Before this change, GetMetadata() was returning the Metadata.MetricType zero value (prometheusgo.MetricType_COUNTER) for all histograms that did not explicitly specify the prometheusgo.MetricType_HISTOGRAM for Metadata.MetricType in their Metadata definitions. This prevented checks on histogram Metadata.MetricType from properly evaluating the metrics as histograms. Fixes #106448. Fixes #107701. Releaes note: None --- pkg/util/metric/metric.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/util/metric/metric.go b/pkg/util/metric/metric.go index 9c62c0cf641f..aa5d7628ab6d 100644 --- a/pkg/util/metric/metric.go +++ b/pkg/util/metric/metric.go @@ -255,6 +255,7 @@ type HistogramOptions struct { } func NewHistogram(opt HistogramOptions) IHistogram { + opt.Metadata.MetricType = prometheusgo.MetricType_HISTOGRAM if hdrEnabled && opt.Mode != HistogramModePrometheus { if opt.Mode == HistogramModePreferHdrLatency { return NewHdrLatency(opt.Metadata, opt.Duration) @@ -492,6 +493,7 @@ func NewManualWindowHistogram( panic(err.Error()) } + meta.MetricType = prometheusgo.MetricType_HISTOGRAM h := &ManualWindowHistogram{ Metadata: meta, }