Skip to content

Commit

Permalink
Alerting: Fix migration to not add label "alertname" (grafana#56509)
Browse files Browse the repository at this point in the history
* do not add label alertname because it is overridden in state manager anyway
* update state manager to not consider labels with same value as dupe

(cherry picked from commit e2f1201)

# Conflicts:
#	pkg/services/ngalert/state/cache.go
  • Loading branch information
yuri-tceretian committed Oct 7, 2022
1 parent d5bb8ab commit a47d6c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pkg/services/ngalert/state/cache.go
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion pkg/services/sqlstore/migrations/ualert/alert_rule.go
Expand Up @@ -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

Expand Down

0 comments on commit a47d6c1

Please sign in to comment.