mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Run table migrations regardless of feature flag and move out of service (#33996)
This commit is contained in:
parent
c39d6ad97d
commit
3da8db7f3f
@ -22,7 +22,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/schedule"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tsdb"
|
||||
)
|
||||
@ -112,19 +111,3 @@ func (ng *AlertNG) IsDisabled() bool {
|
||||
}
|
||||
return !ng.Cfg.IsNgAlertEnabled()
|
||||
}
|
||||
|
||||
// AddMigration defines database migrations.
|
||||
// If Alerting NG is not enabled does nothing.
|
||||
func (ng *AlertNG) AddMigration(mg *migrator.Migrator) {
|
||||
if ng.IsDisabled() {
|
||||
return
|
||||
}
|
||||
store.AddAlertDefinitionMigrations(mg, defaultIntervalSeconds)
|
||||
store.AddAlertDefinitionVersionMigrations(mg)
|
||||
// Create alert_instance table
|
||||
store.AlertInstanceMigration(mg)
|
||||
|
||||
// Create alert_rule
|
||||
store.AddAlertRuleMigrations(mg, defaultIntervalSeconds)
|
||||
store.AddAlertRuleVersionMigrations(mg)
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ func AddMigrations(mg *Migrator) {
|
||||
addUserAuthTokenMigrations(mg)
|
||||
addCacheMigration(mg)
|
||||
addShortURLMigrations(mg)
|
||||
ualert.AddMigration(mg)
|
||||
ualert.AddTablesMigrations(mg)
|
||||
ualert.AddDashAlertMigration(mg)
|
||||
}
|
||||
|
||||
func addMigrationLogMigrations(mg *Migrator) {
|
||||
|
@ -1,12 +1,24 @@
|
||||
package store
|
||||
package ualert
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
)
|
||||
|
||||
// AddMigration defines database migrations.
|
||||
// If Alerting NG is not enabled does nothing.
|
||||
func AddTablesMigrations(mg *migrator.Migrator) {
|
||||
AddAlertDefinitionMigrations(mg, 60)
|
||||
AddAlertDefinitionVersionMigrations(mg)
|
||||
// Create alert_instance table
|
||||
AlertInstanceMigration(mg)
|
||||
|
||||
// Create alert_rule
|
||||
AddAlertRuleMigrations(mg, 60)
|
||||
AddAlertRuleVersionMigrations(mg)
|
||||
}
|
||||
|
||||
// AddAlertDefinitionMigrations should not be modified.
|
||||
func AddAlertDefinitionMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64) {
|
||||
mg.AddMigration("delete alert_definition table", migrator.NewDropTableMigration("alert_definition"))
|
||||
@ -151,8 +163,8 @@ func AddAlertRuleMigrations(mg *migrator.Migrator, defaultIntervalSeconds int64)
|
||||
// the following fields will correspond to a dashboard (or folder) UIID
|
||||
{Name: "namespace_uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},
|
||||
{Name: "rule_group", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.NoData.String())},
|
||||
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.AlertingErrState.String())},
|
||||
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"},
|
||||
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"},
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"org_id", "title"}, Type: migrator.UniqueIndex},
|
||||
@ -199,8 +211,8 @@ func AddAlertRuleVersionMigrations(mg *migrator.Migrator) {
|
||||
{Name: "condition", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
{Name: "data", Type: migrator.DB_Text, Nullable: false},
|
||||
{Name: "interval_seconds", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.NoData.String())},
|
||||
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: fmt.Sprintf("'%s'", models.AlertingErrState.String())},
|
||||
{Name: "no_data_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'NoData'"},
|
||||
{Name: "exec_err_state", Type: migrator.DB_NVarchar, Length: 15, Nullable: false, Default: "'Alerting'"},
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"rule_org_id", "rule_uid", "version"}, Type: migrator.UniqueIndex},
|
@ -30,7 +30,7 @@ func (e MigrationError) Error() string {
|
||||
|
||||
func (e *MigrationError) Unwrap() error { return e.Err }
|
||||
|
||||
func AddMigration(mg *migrator.Migrator) {
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user