From 6f38ac6615aef641a489c2d34ca351475f48b5a4 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Tue, 26 Mar 2024 17:35:30 +0100 Subject: [PATCH] Alerting: Reduce set of fields that could trigger alert state change (#83496) We want to avoid too much change of alert state based on change on alert's fields. For that we ignore some fields from the diff. --- pkg/services/ngalert/schedule/registry.go | 2 -- pkg/services/ngalert/schedule/registry_test.go | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/services/ngalert/schedule/registry.go b/pkg/services/ngalert/schedule/registry.go index a44f25b9b61..6a8ec87f19a 100644 --- a/pkg/services/ngalert/schedule/registry.go +++ b/pkg/services/ngalert/schedule/registry.go @@ -300,9 +300,7 @@ func (r ruleWithFolder) Fingerprint() fingerprint { // TODO consider removing fields below from the fingerprint writeInt(rule.ID) writeInt(rule.OrgID) - writeInt(rule.IntervalSeconds) writeInt(int64(rule.For)) - writeLabels(rule.Annotations) if rule.DashboardUID != nil { writeString(*rule.DashboardUID) } diff --git a/pkg/services/ngalert/schedule/registry_test.go b/pkg/services/ngalert/schedule/registry_test.go index 70d4ec7b172..c617d91a562 100644 --- a/pkg/services/ngalert/schedule/registry_test.go +++ b/pkg/services/ngalert/schedule/registry_test.go @@ -150,10 +150,13 @@ func TestRuleWithFolderFingerprint(t *testing.T) { f2 := ruleWithFolder{rule: rule, folderTitle: uuid.NewString()}.Fingerprint() require.NotEqual(t, f, f2) }) - t.Run("Version and Updated should be excluded from fingerprint", func(t *testing.T) { + t.Run("Version, Updated, IntervalSeconds and Annotations should be excluded from fingerprint", func(t *testing.T) { cp := models.CopyRule(rule) cp.Version++ cp.Updated = cp.Updated.Add(1 * time.Second) + cp.IntervalSeconds++ + cp.Annotations = make(map[string]string) + cp.Annotations["test"] = "test" f2 := ruleWithFolder{rule: cp, folderTitle: title}.Fingerprint() require.Equal(t, f, f2) @@ -240,8 +243,10 @@ func TestRuleWithFolderFingerprint(t *testing.T) { } excludedFields := map[string]struct{}{ - "Version": {}, - "Updated": {}, + "Version": {}, + "Updated": {}, + "IntervalSeconds": {}, + "Annotations": {}, } tp := reflect.TypeOf(rule).Elem()