[9.2.x] Alerting: Fix migration to not add label "alertname" (#56509) (#56579)

This commit is contained in:
Yuriy Tseretyan
2022-10-07 16:38:00 -04:00
committed by GitHub
parent 1964ddce83
commit 77046b3fba
2 changed files with 5 additions and 4 deletions
+5 -3
View File
@@ -44,16 +44,18 @@ func (c *cache) getOrCreate(ctx context.Context, alertRule *ngModels.AlertRule,
lbs[key] = val
}
for key, val := range ruleLabels {
_, ok := lbs[key]
ruleVal, ok := lbs[key]
// if duplicate labels exist, reserved label will take precedence
if ok {
dupes[key] = val
if ruleVal != val {
dupes[key] = val
}
} else {
lbs[key] = val
}
}
if len(dupes) > 0 {
c.log.Warn("rule declares one or many reserved labels. Those rules labels will be ignored", "labels", dupes)
c.log.Warn("Rule declares one or many reserved labels. Those rules labels will be ignored", "labels", dupes)
}
dupes = make(data.Labels)
for key, val := range result.Instance {
@@ -100,7 +100,6 @@ func addMigrationInfo(da *dashAlert) (map[string]string, map[string]string) {
func (m *migration) makeAlertRule(cond condition, da dashAlert, folderUID string) (*alertRule, error) {
lbls, annotations := addMigrationInfo(&da)
name := normalizeRuleName(da.Name)
lbls["alertname"] = name
annotations["message"] = da.Message
var err error