Commit e21f6a29 by Ricky Putra Committed by GitHub

Alerting: Fix so that sending an alert with the Alertmanager notifier doesn't…

Alerting: Fix so that sending an alert with the Alertmanager notifier doesn't fail when one of multiple configured URL's are down (#31079)

Fixes behaviour of Notify that returns error when one of the dispatch 
event return error, to maintain high availability, we should return error 
when all dispatched events return error instead.

Fixes #30509
parent 9d36f3cc
......@@ -2,6 +2,7 @@ package notifiers
import (
"context"
"fmt"
"regexp"
"strings"
"time"
......@@ -170,6 +171,7 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
bodyJSON := simplejson.NewFromAny(alerts)
body, _ := bodyJSON.MarshalJSON()
errCnt := 0
for _, url := range am.URL {
cmd := &models.SendWebhookSync{
......@@ -182,10 +184,15 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
am.log.Error("Failed to send alertmanager", "error", err, "alertmanager", am.Name, "url", url)
return err
errCnt++
}
}
// This happens when every dispatch return error
if errCnt == len(am.URL) {
return fmt.Errorf("failed to send alert to alertmanager")
}
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment