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.
This commit is contained in:
Benoit Tigeot 2024-03-26 17:35:30 +01:00 committed by GitHub
parent 2188516a21
commit 6f38ac6615
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -300,9 +300,7 @@ func (r ruleWithFolder) Fingerprint() fingerprint {
// TODO consider removing fields below from the fingerprint // TODO consider removing fields below from the fingerprint
writeInt(rule.ID) writeInt(rule.ID)
writeInt(rule.OrgID) writeInt(rule.OrgID)
writeInt(rule.IntervalSeconds)
writeInt(int64(rule.For)) writeInt(int64(rule.For))
writeLabels(rule.Annotations)
if rule.DashboardUID != nil { if rule.DashboardUID != nil {
writeString(*rule.DashboardUID) writeString(*rule.DashboardUID)
} }

View File

@ -150,10 +150,13 @@ func TestRuleWithFolderFingerprint(t *testing.T) {
f2 := ruleWithFolder{rule: rule, folderTitle: uuid.NewString()}.Fingerprint() f2 := ruleWithFolder{rule: rule, folderTitle: uuid.NewString()}.Fingerprint()
require.NotEqual(t, f, f2) 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 := models.CopyRule(rule)
cp.Version++ cp.Version++
cp.Updated = cp.Updated.Add(1 * time.Second) 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() f2 := ruleWithFolder{rule: cp, folderTitle: title}.Fingerprint()
require.Equal(t, f, f2) require.Equal(t, f, f2)
@ -240,8 +243,10 @@ func TestRuleWithFolderFingerprint(t *testing.T) {
} }
excludedFields := map[string]struct{}{ excludedFields := map[string]struct{}{
"Version": {}, "Version": {},
"Updated": {}, "Updated": {},
"IntervalSeconds": {},
"Annotations": {},
} }
tp := reflect.TypeOf(rule).Elem() tp := reflect.TypeOf(rule).Elem()