From a7fb3a385362d47834ba78910be0e931884af252 Mon Sep 17 00:00:00 2001 From: drivebyer Date: Mon, 24 Jul 2023 23:40:21 +0800 Subject: [PATCH] fix: Create metrics slice when necessary in getCacheMetrics() (#17711) --- cmd/metrics-v2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index 1781dd25d..475d7f53d 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -1863,12 +1863,12 @@ func getCacheMetrics() *MetricsGroup { cacheInterval: 10 * time.Second, } mg.RegisterRead(func(ctx context.Context) (metrics []Metric) { - metrics = make([]Metric, 0, 20) cacheObjLayer := newCachedObjectLayerFn() // Service not initialized yet if cacheObjLayer == nil { return } + metrics = make([]Metric, 0, 20) metrics = append(metrics, Metric{ Description: getCacheHitsTotalMD(), Value: float64(cacheObjLayer.CacheStats().getHits()),