From f0387535fab0148aefc857a42554d3e95fcd0ce8 Mon Sep 17 00:00:00 2001 From: rmatsuoka <76464810+rmatsuoka@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:41:26 +0900 Subject: [PATCH] fix unintentionally return. validateRules have unintentionally returned without checking all monitor rules. --- monitors/command.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/monitors/command.go b/monitors/command.go index 52c05426..832925ba 100644 --- a/monitors/command.go +++ b/monitors/command.go @@ -249,19 +249,19 @@ func isSameMonitor(a mackerel.Monitor, b mackerel.Monitor, flagNameUniquenessEna return "", false } -func validateRuleAnomalyDetectionScopes(v reflect.Value, label string) (bool, error) { +func validateRuleAnomalyDetectionScopes(v reflect.Value, label string) error { f := "Scopes" vf := v.FieldByName("Scopes") if !vf.IsValid() { - return false, fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface()) + return fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface()) } scopes, ok := vf.Interface().([]string) if !ok { - return false, fmt.Errorf("Monitor '%s' has invalid '%s': %s", label, f, v.FieldByName(f).Interface()) + return fmt.Errorf("Monitor '%s' has invalid '%s': %s", label, f, v.FieldByName(f).Interface()) } else if len(scopes) == 0 { - return false, fmt.Errorf("Monitor '%s' has empty '%s'", label, f) + return fmt.Errorf("Monitor '%s' has empty '%s'", label, f) } - return true, nil + return nil } func validateRules(monitors []mackerel.Monitor, label string) (bool, error) { @@ -305,7 +305,9 @@ func validateRules(monitors []mackerel.Monitor, label string) (bool, error) { return false, fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface()) } } - return validateRuleAnomalyDetectionScopes(v, label) + if err := validateRuleAnomalyDetectionScopes(v, label); err != nil { + return false, err + } case *mackerel.MonitorConnectivity: default: return false, fmt.Errorf("Unknown type is found: %s", m.MonitorType())