From 1aa6f4014f38d31e22d487d99f377acea6ddafd2 Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Fri, 14 Apr 2023 11:13:52 +0200 Subject: [PATCH] do not send more than group_threshold alerts at once to a notification plugin --- pkg/csplugin/broker.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/csplugin/broker.go b/pkg/csplugin/broker.go index 716368a92..4557906f6 100644 --- a/pkg/csplugin/broker.go +++ b/pkg/csplugin/broker.go @@ -115,8 +115,19 @@ loop: pb.alertsByPluginName[pluginName] = make([]*models.Alert, 0) pluginMutex.Unlock() go func() { - if err := pb.pushNotificationsToPlugin(pluginName, tmpAlerts); err != nil { - log.WithField("plugin:", pluginName).Error(err) + //Chunk alerts to respect group_threshold + threshold := pb.pluginConfigByName[pluginName].GroupThreshold + if threshold == 0 { + threshold = 1 + } + for i := 0; i < len(tmpAlerts); i += threshold { + end := i + threshold + if end > len(tmpAlerts) { + end = len(tmpAlerts) + } + if err := pb.pushNotificationsToPlugin(pluginName, tmpAlerts[i:end]); err != nil { + log.WithField("plugin:", pluginName).Error(err) + } } }()