Skip to content

Commit

Permalink
metrics: assign histogram metric type before returning metadata
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ericharmeling committed Aug 11, 2023
1 parent c0fbeb3 commit 221e294
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/util/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 221e294

Please sign in to comment.