Skip to content

Commit

Permalink
delete tenant from skipped list if it's not owned by the instance, al…
Browse files Browse the repository at this point in the history
…ways use the default config in startAlertmanager()
  • Loading branch information
santihernandezc committed Mar 5, 2025
1 parent c688474 commit 8e88697
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ func (am *MultitenantAlertmanager) serveRequest(w http.ResponseWriter, req *http

// If the Alertmanager initialization was skipped, start the Alertmanager.
if _, ok := am.lastRequestTime.Load(userID); ok {
userAM, err = am.startAlertmanager(req.Context(), userID)
userAM, err = am.startAlertmanager(userID)
if err != nil {
if errors.Is(err, errNotUploadingFallback) {
level.Warn(am.logger).Log("msg", "not initializing Alertmanager", "user", userID, "err", err)
Expand Down Expand Up @@ -1121,22 +1121,15 @@ func (am *MultitenantAlertmanager) serveRequest(w http.ResponseWriter, req *http
}

// startAlertmanager will start the Alertmanager for a tenant, using the fallback configuration if no config is found.
func (am *MultitenantAlertmanager) startAlertmanager(ctx context.Context, userID string) (*Alertmanager, error) {
func (am *MultitenantAlertmanager) startAlertmanager(userID string) (*Alertmanager, error) {
// Avoid starting the Alertmanager for tenants not owned by this instance.
if !am.isUserOwned(userID) {
am.lastRequestTime.Delete(userID)
return nil, errors.Wrap(errNotUploadingFallback, "user not owned by this instance")
}

cfg, err := am.store.GetAlertConfig(ctx, userID)
if err != nil {
if !errors.Is(err, alertspb.ErrNotFound) {
return nil, errors.Wrap(err, "failed to check for existing configuration")
}
cfg = alertspb.ToProto("", nil, userID)
}

amConfig := amConfig{
AlertConfigDesc: cfg,
AlertConfigDesc: alertspb.ToProto("", nil, userID),
tmplExternalURL: am.cfg.ExternalURL.URL,
}
if err := am.setConfig(amConfig); err != nil {
Expand Down

0 comments on commit 8e88697

Please sign in to comment.