Alerting: Modify configuration apply and save semantics - v2 (#34143)

* Save default configuration to the database and copy over secure settings
This commit is contained in:
gotjosh
2021-05-14 19:49:54 +01:00
committed by GitHub
parent 4d161f9fb2
commit eb74994b8b
10 changed files with 391 additions and 47 deletions

View File

@@ -42,15 +42,29 @@ func (st *DBstore) GetLatestAlertmanagerConfiguration(query *models.GetLatestAle
}
// SaveAlertmanagerConfiguration creates an alertmanager configuration.
func (st *DBstore) SaveAlertmanagerConfiguration(cmd *models.SaveAlertmanagerConfigurationCmd) error {
return st.SQLStore.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
func (st DBstore) SaveAlertmanagerConfiguration(cmd *models.SaveAlertmanagerConfigurationCmd) error {
return st.SaveAlertmanagerConfigurationWithCallback(cmd, func() error { return nil })
}
type SaveCallback func() error
// SaveAlertmanagerConfigurationWithCallback creates an alertmanager configuration version and then executes a callback.
// If the callback results in error in rollsback the transaction.
func (st DBstore) SaveAlertmanagerConfigurationWithCallback(cmd *models.SaveAlertmanagerConfigurationCmd, callback SaveCallback) error {
return st.SQLStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
config := models.AlertConfiguration{
AlertmanagerConfiguration: cmd.AlertmanagerConfiguration,
ConfigurationVersion: cmd.ConfigurationVersion,
Default: cmd.Default,
}
if _, err := sess.Insert(config); err != nil {
return err
}
if err := callback(); err != nil {
return err
}
return nil
})
}

View File

@@ -18,6 +18,7 @@ const AlertDefinitionMaxTitleLength = 190
type AlertingStore interface {
GetLatestAlertmanagerConfiguration(*models.GetLatestAlertmanagerConfigurationQuery) error
SaveAlertmanagerConfiguration(*models.SaveAlertmanagerConfigurationCmd) error
SaveAlertmanagerConfigurationWithCallback(*models.SaveAlertmanagerConfigurationCmd, SaveCallback) error
}
// DBstore stores the alert definitions and instances in the database.