fix: Create metrics slice when necessary in getCacheMetrics() (#17711)

This commit is contained in:
drivebyer 2023-07-24 23:40:21 +08:00 committed by GitHub
parent 2da4bd5f1a
commit a7fb3a3853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()),