From 221e2946765bd73a4b52cb7ad36765897c5f3406 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 before returning metadata This commit assigns prometheusgo.MetricType_HISTOGRAM to the Metadata.MetricType in Histogram.GetMetadata. 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/util/metric/metric.go b/pkg/util/metric/metric.go index e3508c2ebdb3..c71e2f0a948f 100644 --- a/pkg/util/metric/metric.go +++ b/pkg/util/metric/metric.go @@ -400,7 +400,9 @@ func (h *Histogram) ToPrometheusMetricWindowed() *prometheusgo.Metric { // GetMetadata returns the metric's metadata including the Prometheus // MetricType. func (h *Histogram) GetMetadata() Metadata { - return h.Metadata + baseMetadata := h.Metadata + baseMetadata.MetricType = prometheusgo.MetricType_HISTOGRAM + return baseMetadata } // Inspect calls the closure. @@ -586,7 +588,9 @@ func (mwh *ManualWindowHistogram) Rotate() error { // GetMetadata returns the metric's metadata including the Prometheus // MetricType. func (mwh *ManualWindowHistogram) GetMetadata() Metadata { - return mwh.Metadata + baseMetadata := mwh.Metadata + baseMetadata.MetricType = prometheusgo.MetricType_HISTOGRAM + return baseMetadata } // Inspect calls the closure.