Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9.2.x] Alerting: Fix migration to create rules with group index 1 #56584

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/services/sqlstore/migrations/ualert/alert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (m *migration) makeAlertRule(cond condition, da dashAlert, folderUID string
Updated: time.Now().UTC(),
Annotations: annotations,
Labels: lbls,
RuleGroupIndex: 1,
}

ar.NoDataState, err = transNoData(da.ParsedSettings.NoDataState)
Expand Down
5 changes: 2 additions & 3 deletions pkg/services/sqlstore/migrations/ualert/ualert.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ func (c updateRulesOrderInGroup) Exec(sess *xorm.Session, migrator *migrator.Mig
}

updated := time.Now()
versions := make([]*alertRuleVersion, 0, len(toUpdate))
versions := make([]interface{}, 0, len(toUpdate))

for _, rule := range toUpdate {
rule.Updated = updated
Expand All @@ -855,8 +855,7 @@ func (c updateRulesOrderInGroup) Exec(sess *xorm.Session, migrator *migrator.Mig
migrator.Logger.Debug("updated group index for alert rule", "rule_uid", rule.UID)
versions = append(versions, version)
}

_, err := sess.Insert(&versions)
_, err := sess.Insert(versions...)
if err != nil {
migrator.Logger.Error("failed to insert changes to alert_rule_version", "err", err)
return fmt.Errorf("unable to update alert rules with group index: %w", err)
Expand Down