From 526961f2984aae1671a90cb830e816fc813d1602 Mon Sep 17 00:00:00 2001 From: Yuriy Tseretyan Date: Thu, 30 Sep 2021 15:07:56 -0400 Subject: [PATCH] Alerting: rule evaluation loop to not access multiorg Alertmanager if no alerts to add (#39872) --- pkg/services/ngalert/schedule/schedule.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/services/ngalert/schedule/schedule.go b/pkg/services/ngalert/schedule/schedule.go index 786a6328c70..0a40e485a99 100644 --- a/pkg/services/ngalert/schedule/schedule.go +++ b/pkg/services/ngalert/schedule/schedule.go @@ -478,6 +478,11 @@ func (sch *schedule) ruleRoutine(grafanaCtx context.Context, key models.AlertRul sch.saveAlertStates(processedStates) alerts := FromAlertStateToPostableAlerts(processedStates, sch.stateManager, sch.appURL) + if len(alerts.PostableAlerts) == 0 { + sch.log.Debug("no alerts to put in the notifier", "org", alertRule.OrgID) + return nil + } + sch.log.Debug("sending alerts to notifier", "count", len(alerts.PostableAlerts), "alerts", alerts.PostableAlerts, "org", alertRule.OrgID) n, err := sch.multiOrgNotifier.AlertmanagerFor(alertRule.OrgID) if err == nil {