From d6a7badbaa5e1070cbd7d2a5e8c81f1c684d6de6 Mon Sep 17 00:00:00 2001 From: Steven Landers Date: Wed, 2 Aug 2023 15:34:07 -0400 Subject: [PATCH] Write batches at slow rate if only heartbeat bot is present --- services/publisher/publisher.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/publisher/publisher.go b/services/publisher/publisher.go index c3873fad..4a64797f 100644 --- a/services/publisher/publisher.go +++ b/services/publisher/publisher.go @@ -379,6 +379,17 @@ func (pub *Publisher) publishNextBatch(batch *protocol.AlertBatch) (published bo return true, nil } +func (pub *Publisher) hasBots() bool { + pub.botConfigMu.RLock() + defer pub.botConfigMu.RUnlock() + for _, bc := range pub.botConfigs { + if bc.ID != config.HeartbeatBotID { + return true + } + } + return false +} + func (pub *Publisher) shouldSkipPublishing(batch *protocol.AlertBatch) (string, bool) { if pub.cfg.PublisherConfig.AlwaysPublish { return "", false @@ -392,9 +403,8 @@ func (pub *Publisher) shouldSkipPublishing(batch *protocol.AlertBatch) (string, localModeConfig := &pub.cfg.Config.LocalModeConfig lastBatchSendAttempt := pub.lastBatchSendAttempt - pub.botConfigMu.RLock() - runsBots := len(pub.botConfigs) > 0 - pub.botConfigMu.RUnlock() + + runsBots := pub.hasBots() switch { case localModeConfig.Enable && localModeConfig.IncludeMetrics: