From 57c799132b8d5b3bc1c0d5489653a789ccb617dc Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 8 Mar 2024 09:14:22 +0000 Subject: [PATCH] Notifier: don't reuse payload after relabeling Also clarify why these variables are being cleared. Signed-off-by: Bryan Boreham --- notifier/notifier.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index a6a99f413..82c489a2e 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -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 { @@ -531,6 +528,11 @@ 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)