From 6579304d8c88deefe304964bc104cc335f6d23ae Mon Sep 17 00:00:00 2001 From: Shubhendu Date: Tue, 30 Apr 2024 20:35:22 +0530 Subject: [PATCH] Suppress metrics with zero values (#19638) This would reduce the size of data in response of metrics listing. While graphing we can default these metrics with a zero value if not found. Signed-off-by: Shubhendu Ram Tripathi --- cmd/metrics-v3-types.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/metrics-v3-types.go b/cmd/metrics-v3-types.go index b7df8eae3..4fd5e265b 100644 --- a/cmd/metrics-v3-types.go +++ b/cmd/metrics-v3-types.go @@ -232,10 +232,13 @@ func (m *MetricValues) Set(name MetricName, value float64, labels ...string) { if !ok { v = make([]metricValue, 0, 1) } - m.values[name] = append(v, metricValue{ - Labels: labelMap, - Value: value, - }) + // If valid non zero value set the metrics + if value > 0 { + m.values[name] = append(v, metricValue{ + Labels: labelMap, + Value: value, + }) + } } // SetHistogram - sets values for the given MetricName using the provided @@ -274,7 +277,10 @@ func (m *MetricValues) SetHistogram(name MetricName, hist *prometheus.HistogramV } } labels = append(labels, extraLabels...) - m.Set(name, metric.Value, labels...) + // If valid non zero value set the metrics + if metric.Value > 0 { + m.Set(name, metric.Value, labels...) + } } }