From 98aecbc14877cf06962f3d7e51d356555ac7192b Mon Sep 17 00:00:00 2001 From: hysyeah Date: Fri, 13 Dec 2024 21:05:40 +0800 Subject: [PATCH] fix: metric values length is 0 --- pkg/apiserver/utils.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/apiserver/utils.go b/pkg/apiserver/utils.go index 17d4d48..4cb698f 100644 --- a/pkg/apiserver/utils.go +++ b/pkg/apiserver/utils.go @@ -332,6 +332,9 @@ func GetClusterResource(kubeConfig *rest.Config, token string) (*prometheus.Clus } func getValue(m *kubesphere.Metric) float64 { + if len(m.MetricData.MetricValues) == 0 { + return 0.0 + } return m.MetricData.MetricValues[0].Sample[1] } func isInPrivateNamespace(namespace string) bool {