Notifier: don't reuse payload after relabeling

Also clarify why these variables are being cleared.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2024-03-08 09:14:22 +00:00
parent 9acae57937
commit 57c799132b
1 changed files with 7 additions and 5 deletions

View File

@ -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)