From 11ea1dfba8cff13499d832b7af937855fc14d787 Mon Sep 17 00:00:00 2001 From: Moustafa Baiou Date: Wed, 2 Jul 2025 13:26:27 -0400 Subject: [PATCH] Alerting: Fix notification policy conflicts originating from provenance mismatch (#107343) * Alerting: Fix notification policy conflicts originating from provenance mismatch Sometimes the provenance field on the notification policy route can mismatch with the actual provenance in the provenance store. This leads to 409s when trying to update the notification policy via the k8s apis. We avoid this by ignoring the provenance field when calculating the fingerprint. Co-authored-by: Matt Jacobson * fix tests which validate stability --------- Co-authored-by: Matt Jacobson --- pkg/services/ngalert/provisioning/notification_policies.go | 1 - .../ngalert/provisioning/notification_policies_test.go | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/services/ngalert/provisioning/notification_policies.go b/pkg/services/ngalert/provisioning/notification_policies.go index fed23d7bc69..f6563fe45ac 100644 --- a/pkg/services/ngalert/provisioning/notification_policies.go +++ b/pkg/services/ngalert/provisioning/notification_policies.go @@ -277,7 +277,6 @@ func writeToHash(sum hash.Hash, r *definitions.Route) { writeDuration(r.GroupWait) writeDuration(r.GroupInterval) writeDuration(r.RepeatInterval) - writeString(string(r.Provenance)) for _, route := range r.Routes { writeToHash(sum, route) } diff --git a/pkg/services/ngalert/provisioning/notification_policies_test.go b/pkg/services/ngalert/provisioning/notification_policies_test.go index f32d6908fd6..e52460c5c04 100644 --- a/pkg/services/ngalert/provisioning/notification_policies_test.go +++ b/pkg/services/ngalert/provisioning/notification_policies_test.go @@ -428,13 +428,14 @@ func TestRoute_Fingerprint(t *testing.T) { } t.Run("stable across code changes", func(t *testing.T) { - expectedFingerprint := "7faba12778df93b8" // If this is a valid fingerprint generation change, update the expected value. + expectedFingerprint := "450c06a7f4a66675" // If this is a valid fingerprint generation change, update the expected value. assert.Equal(t, expectedFingerprint, calculateRouteFingerprint(baseRouteGen())) }) t.Run("unstable across field modification", func(t *testing.T) { fingerprint := calculateRouteFingerprint(baseRouteGen()) excludedFields := map[string]struct{}{ - "Routes": {}, + "Routes": {}, + "Provenance": {}, } reflectVal := reflect.ValueOf(&completelyDifferentRoute).Elem()