From d495cb68d3d1501d2aba0f5000d47db01a31a4c6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 6 May 2021 15:43:34 -0700 Subject: [PATCH] fix: crash in prometherus metrics collector (#12244) node_health metrics crashes in gateway mode, in gateway mode ignore node health metrics. fixes #12243 --- cmd/metrics-v2.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index 2183b4f88..1c9a2636e 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -1041,6 +1041,10 @@ func getNodeHealthMetrics() MetricsGroup { id: "NodeHealthMetrics", cachedRead: cachedRead, read: func(_ context.Context) (metrics []Metric) { + if globalIsGateway { + return + } + metrics = make([]Metric, 0, 16) nodesUp, nodesDown := GetPeerOnlineCount() metrics = append(metrics, Metric{ Description: getNodeOnlineTotalMD(), @@ -1276,17 +1280,13 @@ func getBucketUsageMetrics() MetricsGroup { id: "BucketUsageMetrics", cachedRead: cachedRead, read: func(ctx context.Context) (metrics []Metric) { - metrics = make([]Metric, 0, 50) objLayer := newObjectLayerFn() // Service not initialized yet - if objLayer == nil { - return - } - - if globalIsGateway { + if objLayer == nil || globalIsGateway { return } + metrics = make([]Metric, 0, 50) dataUsageInfo, err := loadDataUsageFromBackend(ctx, objLayer) if err != nil { return @@ -1369,11 +1369,7 @@ func getLocalStorageMetrics() MetricsGroup { read: func(ctx context.Context) (metrics []Metric) { objLayer := newObjectLayerFn() // Service not initialized yet - if objLayer == nil { - return - } - - if globalIsGateway { + if objLayer == nil || globalIsGateway { return } @@ -1415,11 +1411,7 @@ func getClusterStorageMetrics() MetricsGroup { read: func(ctx context.Context) (metrics []Metric) { objLayer := newObjectLayerFn() // Service not initialized yet - if objLayer == nil { - return - } - - if globalIsGateway { + if objLayer == nil || globalIsGateway { return }