Alerting: Remove UALERT_MIG env guard from dashboard rule migration (#34384)

Rules/notifications/etc migration will now be activated with feature flag alone.
When the feature flag is enabled dashboard alerts are migrated into the system.
When the feature flag is removed, all migrated and newly created alerts in the new system are deleted.
This commit is contained in:
Kyle Brandt 2021-05-19 09:37:56 -04:00 committed by GitHub
parent 9dfaa037d1
commit b987237c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,34 +31,33 @@ func (e MigrationError) Error() string {
func (e *MigrationError) Unwrap() error { return e.Err }
func AddDashAlertMigration(mg *migrator.Migrator) {
if os.Getenv("UALERT_MIG") == "iDidBackup" {
// TODO: unified alerting DB needs to be extacted into ../migrations.go
// so it runs and creates the tables before this migration runs.
logs, err := mg.GetMigrationLog()
logs, err := mg.GetMigrationLog()
if err != nil {
mg.Logger.Crit("alert migration failure: could not get migration log", "error", err)
os.Exit(1)
}
_, migrationRun := logs[migTitle]
ngEnabled := mg.Cfg.IsNgAlertEnabled()
switch {
case ngEnabled && !migrationRun:
// Remove the migration entry that removes all unified alerting data. This is so when the feature
// flag is removed in future the "remove unified alerting data" migration will be run again.
err = mg.ClearMigrationEntry(rmMigTitle)
if err != nil {
mg.Logger.Crit("alert migration failure: could not get migration log", "error", err)
os.Exit(1)
mg.Logger.Error("alert migration error: could not clear alert migration for removing data", "error", err)
}
_, migrationRun := logs[migTitle]
ngEnabled := mg.Cfg.IsNgAlertEnabled()
switch {
case ngEnabled && !migrationRun:
// clear the entry of the migration that
err = mg.ClearMigrationEntry(rmMigTitle)
if err != nil {
mg.Logger.Error("alert migration error: could not clear alert migration for removing data", "error", err)
}
mg.AddMigration(migTitle, &migration{})
case !ngEnabled && migrationRun:
err = mg.ClearMigrationEntry(migTitle)
if err != nil {
mg.Logger.Error("alert migration error: could not clear alert migration", "error", err)
}
mg.AddMigration(rmMigTitle, &rmMigration{})
mg.AddMigration(migTitle, &migration{})
case !ngEnabled && migrationRun:
// Remove the migration entry that creates unified alerting data. This is so when the feature
// flag is enabled in the future the migration "move dashboard alerts to unified alerting" will be run again.
err = mg.ClearMigrationEntry(migTitle)
if err != nil {
mg.Logger.Error("alert migration error: could not clear dashboard alert migration", "error", err)
}
mg.AddMigration(rmMigTitle, &rmMigration{})
}
}