Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ func (am *MultitenantAlertmanager) syncConfigs(cfgs map[string]alerts.AlertConfi
}

func (am *MultitenantAlertmanager) transformConfig(userID string, amConfig *amconfig.Config) (*amconfig.Config, error) {
if amConfig == nil { // shouldn't happen, but check just in case
return nil, fmt.Errorf("no usable Cortex configuration for %v", userID)
}
if am.cfg.AutoWebhookRoot != "" {
for _, r := range amConfig.Receivers {
for _, w := range r.WebhookConfigs {
Expand Down Expand Up @@ -405,15 +402,21 @@ func (am *MultitenantAlertmanager) setConfig(cfg alerts.AlertConfigDesc) error {
} else {
userAmConfig, err = amconfig.Load(cfg.RawConfig)
if err != nil && hasExisting {
// XXX: This means that if a user has a working configuration and
// they submit a broken one, we'll keep processing the last known
// working configuration, and they'll never know.
// TODO: Provide a way of communicating this to the user and for removing
// Alertmanager instances.
// This means that if a user has a working config and
// they submit a broken one, the Manager will keep running the last known
// working configuration.
return fmt.Errorf("invalid Cortex configuration for %v: %v", cfg.User, err)
}
}

// We can have an empty configuration here if:
// 1) the user had a previous alertmanager
// 2) then, submitted a non-working configuration (and we kept running the prev working config)
// 3) finally, the cortex AM instance is restarted and the running version is no longer present
if userAmConfig == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non-blocking,if-minor): Since this check has been moved from transformConfig consider removing the transformConfig function entirely an moving the for loop logic from the function here. transformConfig is only called here so it should be safe to move and I think it would still be quite readable as part of a single function call.

return fmt.Errorf("no usable Alertmanager configuration for %v", cfg.User)
}

if userAmConfig, err = am.transformConfig(cfg.User, userAmConfig); err != nil {
return err
}
Expand Down