Alerting: Fix force_migration when alerting is disabled (#50431)

* Alerting: Fix force_migration when alerting is disabled

This commit fixes a bug where force_migration must be set to true
when both unified and legacy alerting is disabled.

* Update comment

* Fix typo in comment

Co-authored-by: Armand Grillet <armand.grillet@outlook.com>
This commit is contained in:
George Robinson 2022-06-09 09:10:11 +01:00 committed by GitHub
parent 3fa7f72d6c
commit 0bd12ab531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,6 +59,7 @@ func AddDashAlertMigration(mg *migrator.Migrator) {
_, migrationRun := logs[migTitle]
switch {
// If unified alerting is enabled and the upgrade migration has not been run
case mg.Cfg.UnifiedAlerting.IsEnabled() && !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.
@ -72,7 +73,13 @@ func AddDashAlertMigration(mg *migrator.Migrator) {
seenChannelUIDs: make(map[string]struct{}),
silences: make(map[int64][]*pb.MeshSilence),
})
// If unified alerting is disabled and upgrade migration has been run
case !mg.Cfg.UnifiedAlerting.IsEnabled() && migrationRun:
// If legacy alerting is also disabled, there is nothing to do
if setting.AlertingEnabled != nil && !*setting.AlertingEnabled {
return
}
// Safeguard to prevent data loss when migrating from UA to LA
if !mg.Cfg.ForceMigration {
panic("Grafana has already been migrated to Unified Alerting.\nAny alert rules created while using Unified Alerting will be deleted by rolling back.\n\nSet force_migration=true in your grafana.ini and restart Grafana to roll back and delete Unified Alerting configuration data.")