Alerting: Fix error when updating Alertmanager config with autogenerated receivers (#113710)
If an alert rule with an invalid receiver is created it breaks the entire alertmanager configuration rather than preventing the save. This fixes the issue by erroring on save and apply, and logging invalid receivers only when applying the config after an update. Introduced in #111838
This commit is contained in:
@@ -233,7 +233,7 @@ func (am *alertmanager) SaveAndApplyConfig(ctx context.Context, cfg *apimodels.P
|
||||
}
|
||||
|
||||
err = am.Store.SaveAlertmanagerConfigurationWithCallback(ctx, cmd, func() error {
|
||||
_, err = am.applyConfig(ctx, cfg, LogInvalidReceivers) // fail if the autogen config is invalid
|
||||
_, err = am.applyConfig(ctx, cfg, ErrorOnInvalidReceivers) // fail if the autogen config is invalid
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
@@ -259,7 +259,7 @@ func (am *alertmanager) ApplyConfig(ctx context.Context, dbCfg *ngmodels.AlertCo
|
||||
// Since we will now update last_applied when autogen changes even if the user-created config remains the same.
|
||||
// To fix this however, the local alertmanager needs to be able to tell the difference between user-created and
|
||||
// autogen config, which may introduce cross-cutting complexity.
|
||||
configChanged, err := am.applyConfig(ctx, cfg, ErrorOnInvalidReceivers)
|
||||
configChanged, err := am.applyConfig(ctx, cfg, LogInvalidReceivers)
|
||||
if err != nil {
|
||||
outerErr = fmt.Errorf("unable to apply configuration: %w", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user