Skip to content

Commit c3c9968

Browse files
authored
Use fallback config only if supplied config is blank (#592)
Triggering off an error was a bad idea - error could be for other reasons. Also we were returning with the error after first time through setConfig, thus ignoring any rules changes.
1 parent c0b1423 commit c3c9968

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pkg/alertmanager/multitenant.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,25 @@ func copyConfig(config *amconfig.Config) (*amconfig.Config, error) {
430430
// creating an alertmanager if it doesn't already exist.
431431
func (am *MultitenantAlertmanager) setConfig(userID string, config configs.Config) error {
432432
_, hasExisting := am.alertmanagers[userID]
433-
amConfig, err := configs_client.AlertmanagerConfigFromConfig(config)
434-
if err != nil && (hasExisting || am.fallbackConfig == nil) {
435-
// XXX: This means that if a user has a working configuration and
436-
// they submit a broken one, we'll keep processing the last known
437-
// working configuration, and they'll never know.
438-
// TODO: Provide a way of communicating this to the user and for removing
439-
// Alertmanager instances.
440-
return fmt.Errorf("invalid Cortex configuration for %v: %v", userID, err)
441-
}
433+
var amConfig *amconfig.Config
434+
var err error
442435

443-
if amConfig == nil && am.fallbackConfig != nil {
444-
log.Infof("invalid Cortex configuration; using fallback for %v", userID)
436+
if config.AlertmanagerConfig == "" {
437+
if am.fallbackConfig == nil {
438+
return fmt.Errorf("blank Alertmanager configuration for %v", userID)
439+
}
440+
log.Infof("blank Alertmanager configuration; using fallback for %v", userID)
445441
amConfig = am.fallbackConfig
442+
} else {
443+
amConfig, err = configs_client.AlertmanagerConfigFromConfig(config)
444+
if err != nil && hasExisting {
445+
// XXX: This means that if a user has a working configuration and
446+
// they submit a broken one, we'll keep processing the last known
447+
// working configuration, and they'll never know.
448+
// TODO: Provide a way of communicating this to the user and for removing
449+
// Alertmanager instances.
450+
return fmt.Errorf("invalid Cortex configuration for %v: %v", userID, err)
451+
}
446452
}
447453

448454
if amConfig, err = am.transformConfig(userID, amConfig); err != nil {

0 commit comments

Comments
 (0)