From cc869e7668c89818329efc47d68eea38d9751aae Mon Sep 17 00:00:00 2001 From: Yuri Tseretyan Date: Wed, 23 Jul 2025 13:08:11 -0400 Subject: [PATCH] Alerting: Fix active time intervals when time interval is renamed (#108534) --- pkg/services/ngalert/provisioning/mute_timings.go | 6 ++++++ .../timeinterval/test-data/notification-settings.json | 3 +++ .../notifications/timeinterval/timeinterval_test.go | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/services/ngalert/provisioning/mute_timings.go b/pkg/services/ngalert/provisioning/mute_timings.go index 8ed7d93a597..6ad0f7efd65 100644 --- a/pkg/services/ngalert/provisioning/mute_timings.go +++ b/pkg/services/ngalert/provisioning/mute_timings.go @@ -440,6 +440,12 @@ func replaceMuteTiming(route *definitions.Route, oldName, newName string) int { updated++ } } + for idx := range route.ActiveTimeIntervals { + if route.ActiveTimeIntervals[idx] == oldName { + route.ActiveTimeIntervals[idx] = newName + updated++ + } + } for _, route := range route.Routes { updated += replaceMuteTiming(route, oldName, newName) } diff --git a/pkg/tests/apis/alerting/notifications/timeinterval/test-data/notification-settings.json b/pkg/tests/apis/alerting/notifications/timeinterval/test-data/notification-settings.json index 80f1b0438a0..33be4d06be5 100644 --- a/pkg/tests/apis/alerting/notifications/timeinterval/test-data/notification-settings.json +++ b/pkg/tests/apis/alerting/notifications/timeinterval/test-data/notification-settings.json @@ -15,6 +15,9 @@ ], "mute_time_intervals": [ "test-interval", "persisted-interval" + ], + "active_time_intervals": [ + "test-interval", "persisted-interval" ] } ] diff --git a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go index 8ea61ab6716..73656fcbc17 100644 --- a/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go +++ b/pkg/tests/apis/alerting/notifications/timeinterval/timeinterval_test.go @@ -725,7 +725,9 @@ func TestIntegrationTimeIntervalReferentialIntegrity(t *testing.T) { updatedRoute := legacyCli.GetRoute(t) for idx, route := range updatedRoute.Routes { expectedTimeIntervals := replace(currentRoute.Routes[idx].MuteTimeIntervals, interval.Spec.Name, actual.Spec.Name) - assert.Equalf(t, expectedTimeIntervals, route.MuteTimeIntervals, "time interval in routes should have been renamed but it did not") + assert.Equalf(t, expectedTimeIntervals, route.MuteTimeIntervals, "mute time interval in routes should have been renamed but it did not") + expectedTimeIntervals = replace(currentRoute.Routes[idx].ActiveTimeIntervals, interval.Spec.Name, actual.Spec.Name) + assert.Equalf(t, expectedTimeIntervals, route.ActiveTimeIntervals, "active time interval in routes should have been renamed but it did not") } interval = *actual