Repository: minio/minio (language: go)

Issue:
SIGSEGV in github.com/prometheus/client_golang@v1.11.0/prometheus/registry.go:538
## NOTE
If this case is urgent, please subscribe to [Subnet](https://min.io/pricing) so that our 24/7 support team may help you faster.

<!--- Provide a general summary of the issue in the Title above -->
SIGSEGV in github.com/prometheus/client_golang@v1.11.0/prometheus/registry.go:538

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
no crash

## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x25c01fb]

goroutine 219 [running]:
github.com/minio/minio/cmd.getLocalDiskStorageMetrics.func1({0x51ea730, 0xc000635bc0})
	github.com/minio/minio/cmd/metrics-v2.go:1620 +0x23b
github.com/minio/minio/cmd.(*MetricsGroup).RegisterRead.func1.1()
	github.com/minio/minio/cmd/metrics-v2.go:227 +0x2b
github.com/minio/minio/cmd.(*timedValue).Get(0xc0009b15e0)
	github.com/minio/minio/cmd/utils.go:912 +0x32
github.com/minio/minio/cmd.(*MetricsGroup).Get(0x2de2a0c)
	github.com/minio/minio/cmd/metrics-v2.go:262 +0x3f
github.com/minio/minio/cmd.populateAndPublish({0xc000635d00, 0x7, 0x0}, 0xc00058ff10)
	github.com/minio/minio/cmd/metrics-v2.go:1804 +0x66
github.com/minio/minio/cmd.(*minioNodeCollector).Collect(0xc0000a7a20, 0xc001adfce0)
	github.com/minio/minio/cmd/metrics-v2.go:1817 +0xe6
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
	github.com/prometheus/client_golang@v1.11.0/prometheus/registry.go:446 +0x102
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
	github.com/prometheus/client_golang@v1.11.0/prometheus/registry.go:538 +0xb4d

## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->

## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
<!--- and make sure you have followed https://github.com/minio/minio/tree/release/docs/debugging to capture relevant logs -->

1. start minio.RELEASE.2022-01-27T03-53-02Z or later 
2.
3.
4.

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
does not crash with minio.RELEASE.2022-01-25T19-56-04Z

## Regression
<!-- Is this issue a regression? (Yes / No) -->
<!-- If Yes, optionally please include minio version or commit id or PR# that caused this regression, if you have these details. -->

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Version used (`minio --version`): minio.RELEASE.2022-01-27T03-53-02Z
* Server setup and configuration:
* Operating System and version (`uname -a`): Linux minio 5.13.0-27-generic #29-Ubuntu SMP Wed Jan 12 17:36:47 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Start script:
#!/bin/bash
export DATA_PATH=/var/lib/minio
export MINIO_ROOT_USER=abc
export MINIO_ROOT_PASSWORD=xyz
export MINIO_PROMETHEUS_URL="http://xxx.yyy.zzz:9090"
export CONSOLE_PROMETHEUS_JOB_ID="minio-cluster"
export MINIO_PROMETHEUS_AUTH_TYPE="public"
$HOME/bin/minio server --console-address :9001 --address :9000 $DATA_PATH


Discussion / hints:
> export DATA_PATH=/var/lib/minio
> export MINIO_ROOT_USER=abc
> export MINIO_ROOT_PASSWORD=xyz
> export MINIO_PROMETHEUS_URL="http://xxx.yyy.zzz:9090"
> export CONSOLE_PROMETHEUS_JOB_ID="minio-cluster"
> export MINIO_PROMETHEUS_AUTH_TYPE="public"
> $HOME/bin/minio server --console-address :9001 --address :9000 $DATA_PATH

This is a regression added from #14117

Fix patch:
diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go
index bf73dc176a168..b0ceba2ba781e 100644
--- a/cmd/metrics-v2.go
+++ b/cmd/metrics-v2.go
@@ -27,6 +27,7 @@ import (
 	"sync/atomic"
 	"time"
 
+	"github.com/minio/madmin-go"
 	"github.com/minio/minio/internal/bucket/lifecycle"
 	"github.com/minio/minio/internal/logger"
 	"github.com/prometheus/client_golang/prometheus"
@@ -1614,9 +1615,15 @@ func getLocalDiskStorageMetrics() *MetricsGroup {
 			return
 		}
 
-		metrics = make([]Metric, 0, 50)
 		storageInfo, _ := objLayer.LocalStorageInfo(ctx)
+		if storageInfo.Backend.Type == madmin.FS {
+			return
+		}
+		metrics = make([]Metric, 0, 50)
 		for _, disk := range storageInfo.Disks {
+			if disk.Metrics == nil {
+				continue
+			}
 			for apiName, latency := range disk.Metrics.APILatencies {
 				val := latency.(uint64)
 				metrics = append(metrics, Metric{


Test patch: