Migrations:
* add a new column alert_group_idx to alert_rule table
* add a new column alert_group_idx to alert_rule_version table
* re-index existing rules during migration
API:
* set group index on update. Use the natural order of items in the array as group index
* sort rules in the group on GET
* update the version of all rules of all affected groups. This will make optimistic lock work in the case of multiple concurrent request touching the same groups.
UI:
* update UI to keep the order of alerts in a group
logger.Debug("updating database with the authorized changes","add",len(finalChanges.New),"update",len(finalChanges.New),"delete",len(finalChanges.Delete))
logger.Debug("updating database with the authorized changes","add",len(finalChanges.New),"update",len(finalChanges.New),"delete",len(finalChanges.Delete))
// calculateChanges calculates the difference between rules in the group in the database and the submitted rules. If a submitted rule has UID it tries to find it in the database (in other groups).
// calculateChanges calculates the difference between rules in the group in the database and the submitted rules. If a submitted rule has UID it tries to find it in the database (in other groups).
// returns a list of rules that need to be added, updated and deleted. Deleted considered rules in the database that belong to the group but do not exist in the list of submitted rules.
// returns a list of rules that need to be added, updated and deleted. Deleted considered rules in the database that belong to the group but do not exist in the list of submitted rules.
// calculateAutomaticChanges scans all affected groups and creates either a noop update that will increment the version of each rule as well as re-index other groups.
// this is needed to make sure that there are no any concurrent changes made to all affected groups.
// Returns a copy of changes enriched with either noop or group index changes for all rules in
require.Lenf(t,diff,1,fmt.Sprintf("the rule in affected group should be re-indexed to %d but it still has index %d. Moved rule with index %d",expectedIdx,upd.Existing.RuleGroupIndex,movedIndex))
mg.AddMigration("add column labels to alert_rule_version",migrator.NewAddColumnMigration(alertRuleVersion,&migrator.Column{Name:"labels",Type:migrator.DB_Text,Nullable:true}))
mg.AddMigration("add column labels to alert_rule_version",migrator.NewAddColumnMigration(alertRuleVersion,&migrator.Column{Name:"labels",Type:migrator.DB_Text,Nullable:true}))
mg.AddMigration("add rule_group_idx column to alert_rule_version",migrator.NewAddColumnMigration(
// getAlertFolderNameFromDashboard generates a folder name for alerts that belong to a dashboard. Formats the string according to DASHBOARD_FOLDER format.
// getAlertFolderNameFromDashboard generates a folder name for alerts that belong to a dashboard. Formats the string according to DASHBOARD_FOLDER format.