Skip to content

Apply review comments consistently to alertmanager/multitenant.go #4005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Changes from all commits
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
11 changes: 3 additions & 8 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,17 +996,12 @@ func (am *MultitenantAlertmanager) ReplicateStateForUser(ctx context.Context, us
}

switch resp.Status {
case alertmanagerpb.OK:
return nil
case alertmanagerpb.MERGE_ERROR:
level.Error(am.logger).Log("msg", "state replication failed", "user", userID, "key", part.Key, "err", resp.Error)
return nil
case alertmanagerpb.USER_NOT_FOUND:
level.Debug(am.logger).Log("msg", "user not found while trying to replicate state", "user", userID, "key", part.Key)
return nil
default:
return nil
}
return nil
}, func() {})

return err
Expand Down Expand Up @@ -1083,8 +1078,9 @@ func (am *MultitenantAlertmanager) UpdateState(ctx context.Context, part *cluste
}

am.alertmanagersMtx.Lock()
defer am.alertmanagersMtx.Unlock()
userAM, ok := am.alertmanagers[userID]
am.alertmanagersMtx.Unlock()

if !ok {
// We can end up trying to replicate state to an alertmanager that is no longer available due to e.g. a ring topology change.
level.Debug(am.logger).Log("msg", "user does not have an alertmanager in this instance", "user", userID)
Expand All @@ -1095,7 +1091,6 @@ func (am *MultitenantAlertmanager) UpdateState(ctx context.Context, part *cluste
}

if err = userAM.mergePartialExternalState(part); err != nil {
level.Error(am.logger).Log("msg", "failed to merge state", "err", err, "key", part.Key)
return &alertmanagerpb.UpdateStateResponse{
Status: alertmanagerpb.MERGE_ERROR,
Error: err.Error(),
Expand Down