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 <shubhendu@minio.io>
This commit is contained in:
Shubhendu 2024-04-30 20:35:22 +05:30 committed by GitHub
parent 6bb10a81a6
commit 6579304d8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -232,10 +232,13 @@ func (m *MetricValues) Set(name MetricName, value float64, labels ...string) {
if !ok { if !ok {
v = make([]metricValue, 0, 1) v = make([]metricValue, 0, 1)
} }
// If valid non zero value set the metrics
if value > 0 {
m.values[name] = append(v, metricValue{ m.values[name] = append(v, metricValue{
Labels: labelMap, Labels: labelMap,
Value: value, Value: value,
}) })
}
} }
// SetHistogram - sets values for the given MetricName using the provided // SetHistogram - sets values for the given MetricName using the provided
@ -274,8 +277,11 @@ func (m *MetricValues) SetHistogram(name MetricName, hist *prometheus.HistogramV
} }
} }
labels = append(labels, extraLabels...) labels = append(labels, extraLabels...)
// If valid non zero value set the metrics
if metric.Value > 0 {
m.Set(name, metric.Value, labels...) m.Set(name, metric.Value, labels...)
} }
}
} }
// MetricsLoaderFn - represents a function to load metrics from the // MetricsLoaderFn - represents a function to load metrics from the