Skip to content

Commit

Permalink
NETOBSERV-976 Fix disabling alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Apr 19, 2023
1 parent 36de463 commit cb460a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions controllers/flowcollector_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ func flowCollectorControllerSpecs() {
Duration: conntrackEndTimeout,
},
Metrics: flowslatest.FLPMetrics{
IgnoreTags: []string{"flows", "bytes", "packets"},
IgnoreTags: []string{"flows", "bytes", "packets"},
DisableAlerts: []flowslatest.FLPAlert{flowslatest.AlertLokiError},
},
}
fc.Spec.Loki = flowslatest.FlowCollectorLoki{}
Expand Down Expand Up @@ -396,13 +397,15 @@ func flowCollectorControllerSpecs() {
}, &sm)
}, timeout, interval).Should(Succeed())

By("Expecting PrometheusRule to exist")
By("Expecting PrometheusRule to exist and be updated")
Eventually(func() interface{} {
return k8sClient.Get(ctx, types.NamespacedName{
Name: "flowlogs-pipeline-alert",
Namespace: operatorNamespace,
}, &pr)
}, timeout, interval).Should(Succeed())
Expect(pr.Spec.Groups).Should(HaveLen(1))
Expect(pr.Spec.Groups[0].Rules).Should(HaveLen(1))

// Manually delete ServiceMonitor
By("Deleting ServiceMonitor")
Expand Down
2 changes: 1 addition & 1 deletion controllers/flowlogspipeline/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func TestPrometheusRuleChanged(t *testing.T) {
b := newMonolithBuilder("namespace", image, &cfg, true)
first := b.generic.prometheusRule()

// Check namespace change
// Check enabled rule change
cfg.Processor.Metrics.DisableAlerts = []flowslatest.FLPAlert{flowslatest.AlertNoFlows}
b = newMonolithBuilder("namespace", image, &cfg, true)
second := b.generic.prometheusRule()
Expand Down
3 changes: 2 additions & 1 deletion pkg/helper/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func ServiceMonitorChanged(old, new *monitoringv1.ServiceMonitor, report *Change
}

func PrometheusRuleChanged(old, new *monitoringv1.PrometheusRule, report *ChangeReport) bool {
return report.Check("PrometheusRule spec changed", !equality.Semantic.DeepDerivative(new.Spec, old.Spec)) ||
// Note: DeepDerivative misses changes in Spec.Groups.Rules (covered by test "Expecting PrometheusRule to exist and be updated")
return report.Check("PrometheusRule spec changed", !equality.Semantic.DeepEqual(new.Spec, old.Spec)) ||
report.Check("PrometheusRule labels changed", !IsSubSet(old.Labels, new.Labels))
}

Expand Down

0 comments on commit cb460a4

Please sign in to comment.