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
1 changed files with 11 additions and 5 deletions

View File

@ -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...)
}
}
}