Alerting: In migration improve deduplication of title and group (#78351)

* Alerting: In migration improve deduplication of title and group

This change improves alert titles generated in the legacy migration 
that occur when we need to deduplicate titles. Now when duplicate 
titles are detected we will first attempt to append a sequential index, 
falling back to a random uid if none are unique within 10 attempts. 
This should cause shorter and more easily readable deduplicated 
titles in most cases.

In addition, groups are no longer deduplicated. Instead we set them 
to a combination of truncated dashboard name and humanized alert 
frequency. This way, alerts from the same dashboard share a group 
if they have the same evaluation interval. In the event that truncation 
causes overlap, it won't be a big issue as all alerts will still be in a 
group with the correct evaluation interval.
This commit is contained in:
Matthew Jacobson
2023-11-29 10:05:00 -05:00
committed by GitHub
parent 773e0680c5
commit 2b51f0e263
9 changed files with 332 additions and 198 deletions

View File

@@ -41,6 +41,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
}
genAlert := func(title string, namespaceUID string, dashboardUID string, mutators ...func(*ngModels.AlertRule)) *ngModels.AlertRule {
dashTitle := "Dashboard Title " + dashboardUID
a := &ngModels.AlertRule{
ID: 1,
OrgID: 1,
@@ -55,7 +56,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
},
NamespaceUID: namespaceUID,
DashboardUID: &dashboardUID,
RuleGroup: fmt.Sprintf("Dashboard Title %s - %d", dashboardUID, 1),
RuleGroup: fmt.Sprintf("%s - 1m", dashTitle),
IntervalSeconds: 60,
Version: 1,
PanelID: pointer(int64(1)),
@@ -83,7 +84,6 @@ func TestDashAlertPermissionMigration(t *testing.T) {
return func(a *ngModels.AlertRule) {
a.PanelID = pointer(id)
a.Annotations["__panelId__"] = fmt.Sprintf("%d", id)
a.RuleGroup = fmt.Sprintf("Dashboard Title %s - %d", *a.DashboardUID, id)
}
}