Skip to content
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

[BUGFIX] Alerts: don't reuse payload after relabeling. #13735

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,11 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {

if len(ams.cfg.AlertRelabelConfigs) > 0 {
amAlerts = relabelAlerts(ams.cfg.AlertRelabelConfigs, labels.Labels{}, alerts)
// TODO(nabokihms): figure out the right way to cache marshalled alerts.
// Now it works well only for happy cases.
v1Payload = nil
v2Payload = nil

if len(amAlerts) == 0 {
continue
}
// We can't use the cached values from previous iteration.
v1Payload, v2Payload = nil, nil
}

switch ams.cfg.APIVersion {
Expand Down Expand Up @@ -531,15 +528,20 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
}
}

if len(ams.cfg.AlertRelabelConfigs) > 0 {
// We can't use the cached values on the next iteration.
v1Payload, v2Payload = nil, nil
}

for _, am := range ams.ams {
wg.Add(1)

ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout))
defer cancel()

go func(client *http.Client, url string) {
go func(ctx context.Context, client *http.Client, url string, payload []byte, count int) {
if err := n.sendOne(ctx, client, url, payload); err != nil {
level.Error(n.logger).Log("alertmanager", url, "count", len(amAlerts), "msg", "Error sending alert", "err", err)
level.Error(n.logger).Log("alertmanager", url, "count", count, "msg", "Error sending alert", "err", err)
n.metrics.errors.WithLabelValues(url).Inc()
} else {
numSuccess.Inc()
Expand All @@ -548,7 +550,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
n.metrics.sent.WithLabelValues(url).Add(float64(len(amAlerts)))

wg.Done()
}(ams.client, am.url().String())
}(ctx, ams.client, am.url().String(), payload, len(amAlerts))
}

ams.mtx.RUnlock()
Expand Down