From 2a50d857c8410f4d8c378bcdf55619d52ac3fbb3 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 17 Dec 2024 18:00:04 +0100 Subject: [PATCH] Limit in getBucketUsageMetrics --- cmd/metrics-v2.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index afe4f7ffc..c8a0c04c5 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -1836,8 +1836,8 @@ func getGoMetrics() *MetricsGroupV2 { // getHistogramMetrics fetches histogram metrics and returns it in a []Metric // Note: Typically used in MetricGroup.RegisterRead // -// The last parameter is added for compatibility - if true it lowercases the -// `api` label values. +// The toLowerAPILabels parameter is added for compatibility, +// if set, it lowercases the `api` label values. func getHistogramMetrics(hist *prometheus.HistogramVec, desc MetricDescription, toLowerAPILabels, limitBuckets bool) []MetricV2 { ch := make(chan prometheus.Metric) go func() { @@ -3281,7 +3281,12 @@ func getBucketUsageMetrics(opts MetricsGroupOpts) *MetricsGroupV2 { if !globalSiteReplicationSys.isEnabled() { bucketReplStats = globalReplicationStats.Load().getAllLatest(dataUsageInfo.BucketsUsage) } - for bucket, usage := range dataUsageInfo.BucketsUsage { + buckets := mapKeysSorted(dataUsageInfo.BucketsUsage) + if len(buckets) > v2MetricsMaxBuckets { + buckets = buckets[:v2MetricsMaxBuckets] + } + for _, bucket := range buckets { + usage := dataUsageInfo.BucketsUsage[bucket] quota, _ := globalBucketQuotaSys.Get(ctx, bucket) metrics = append(metrics, MetricV2{