[release-12.1.0] Alerting: Fix active time intervals when time interval is renamed (#108547)

Alerting: Fix active time intervals when time interval is renamed (#108534)

(cherry picked from commit cc869e7668)

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot] 2025-07-23 18:26:50 +01:00 committed by GitHub
parent ee5cc5a271
commit 2a87c627ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -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)
}

View File

@ -15,6 +15,9 @@
],
"mute_time_intervals": [
"test-interval", "persisted-interval"
],
"active_time_intervals": [
"test-interval", "persisted-interval"
]
}
]

View File

@ -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