From f8bf984191987cbf6da3110bc1bd6c1e1cae8f4c Mon Sep 17 00:00:00 2001 From: huanggze Date: Thu, 17 Oct 2019 15:53:48 +0800 Subject: [PATCH] monitor: no need to produce error when devops is disabled Signed-off-by: huanggze --- pkg/models/metrics/metrics.go | 8 ++++++-- pkg/models/workspaces/workspaces.go | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/models/metrics/metrics.go b/pkg/models/metrics/metrics.go index 224c21fd..2fe5cbb6 100644 --- a/pkg/models/metrics/metrics.go +++ b/pkg/models/metrics/metrics.go @@ -679,7 +679,9 @@ func GetClusterStatistics() *Response { go func() { num, err := workspaces.GetAllDevOpsProjectsNums() if err != nil { - klog.Errorln(err) + if _, notEnabled := err.(cs.ClientSetNotEnabledError); !notEnabled { + klog.Errorln(err) + } devopsStats.Status = "error" } else { devopsStats.withMetricResult(now, num) @@ -746,7 +748,9 @@ func GetWorkspaceStatistics(workspaceName string) *Response { go func() { num, err := workspaces.GetDevOpsProjectsCount(workspaceName) if err != nil { - klog.Errorln(err) + if _, notEnabled := err.(cs.ClientSetNotEnabledError); !notEnabled { + klog.Errorln(err) + } devopsStats.Status = "error" } else { devopsStats.withMetricResult(now, num) diff --git a/pkg/models/workspaces/workspaces.go b/pkg/models/workspaces/workspaces.go index ebf9ce50..e9bf2f21 100644 --- a/pkg/models/workspaces/workspaces.go +++ b/pkg/models/workspaces/workspaces.go @@ -169,6 +169,10 @@ func DeleteWorkspaceRoleBinding(workspace, username string, role string) error { } func GetDevOpsProjectsCount(workspaceName string) (int, error) { + _, err := clientset.ClientSets().Devops() + if _, notEnabled := err.(clientset.ClientSetNotEnabledError); notEnabled { + return 0, err + } dbconn, err := clientset.ClientSets().MySQL() if err != nil { @@ -237,6 +241,11 @@ func GetAllProjectNums() (int, error) { } func GetAllDevOpsProjectsNums() (int, error) { + _, err := clientset.ClientSets().Devops() + if _, notEnabled := err.(clientset.ClientSetNotEnabledError); notEnabled { + return 0, err + } + dbconn, err := clientset.ClientSets().MySQL() if err != nil { return 0, err -- GitLab