From dbfb7f8fc9ba85358a332e1a9f810879d5908038 Mon Sep 17 00:00:00 2001 From: huanggze Date: Tue, 15 Oct 2019 16:06:50 +0800 Subject: [PATCH] fix crash when monit is disabled Signed-off-by: huanggze --- pkg/models/metrics/namespaces.go | 3 +++ pkg/models/metrics/util.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/models/metrics/namespaces.go b/pkg/models/metrics/namespaces.go index 981e46911..5125cc168 100644 --- a/pkg/models/metrics/namespaces.go +++ b/pkg/models/metrics/namespaces.go @@ -40,6 +40,9 @@ func GetNamespacesWithMetrics(namespaces []*v1.Namespace) []*v1.Namespace { } rawMetrics := GetNamespaceMetrics(params) + if rawMetrics == nil { + return namespaces + } for _, result := range rawMetrics.Results { for _, data := range result.Data.Result { diff --git a/pkg/models/metrics/util.go b/pkg/models/metrics/util.go index b332ced4f..bead04ff4 100644 --- a/pkg/models/metrics/util.go +++ b/pkg/models/metrics/util.go @@ -68,7 +68,7 @@ func (rawMetrics *Response) SortBy(sortMetricName string, sortType string) (*Res } }() - if sortMetricName == "" { + if sortMetricName == "" || rawMetrics == nil { return rawMetrics, -1 }