From b987237c9bdde26e41d3ef6c0f035852b37cfde4 Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Wed, 19 May 2021 09:37:56 -0400 Subject: [PATCH] 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. --- .../sqlstore/migrations/ualert/ualert.go | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/pkg/services/sqlstore/migrations/ualert/ualert.go b/pkg/services/sqlstore/migrations/ualert/ualert.go index 0cbc6b45028..05421d50b1e 100644 --- a/pkg/services/sqlstore/migrations/ualert/ualert.go +++ b/pkg/services/sqlstore/migrations/ualert/ualert.go @@ -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{}) } }