From b9f7a856eef834abbb5b41ca39d6dc58456acd83 Mon Sep 17 00:00:00 2001 From: nip <182409448+nip-was-here@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:12:14 +0400 Subject: [PATCH 1/2] Fix alerts duplication in HA cluster mode Signed-off-by: nip <182409448+nip-was-here@users.noreply.github.com> --- nflog/nflog.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nflog/nflog.go b/nflog/nflog.go index a6c3160880..c6eef780e2 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -526,17 +526,19 @@ func (l *Log) Merge(b []byte) error { defer l.mtx.Unlock() now := l.now() + var needsBroadcast = false for _, e := range st { - if merged := l.st.merge(e, now); merged && !cluster.OversizedMessage(b) { - // If this is the first we've seen the message and it's - // not oversized, gossip it to other nodes. We don't - // propagate oversized messages because they're sent to - // all nodes already. - l.broadcast(b) - l.metrics.propagatedMessagesTotal.Inc() - l.logger.Debug("gossiping new entry", "entry", e) + if merged := l.st.merge(e, now); merged { + // If this is the first we've seen the message, gossip state to other nodes. + needsBroadcast = true } } + + if needsBroadcast { + l.broadcast(b) + l.metrics.propagatedMessagesTotal.Inc() + l.logger.Debug("gossiping new entry", "entry", e) + } return nil } From 80112ab6f5e095ce5fcfdf5f22570ea0c4e36360 Mon Sep 17 00:00:00 2001 From: nip <182409448+nip-was-here@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:27:38 +0400 Subject: [PATCH 2/2] Remove unused import & fix codestyle Signed-off-by: nip <182409448+nip-was-here@users.noreply.github.com> --- nflog/nflog.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nflog/nflog.go b/nflog/nflog.go index c6eef780e2..13cd2c0fd7 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -33,7 +33,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/promslog" - "github.com/prometheus/alertmanager/cluster" pb "github.com/prometheus/alertmanager/nflog/nflogpb" ) @@ -526,7 +525,7 @@ func (l *Log) Merge(b []byte) error { defer l.mtx.Unlock() now := l.now() - var needsBroadcast = false + needsBroadcast := false for _, e := range st { if merged := l.st.merge(e, now); merged { // If this is the first we've seen the message, gossip state to other nodes. @@ -537,7 +536,7 @@ func (l *Log) Merge(b []byte) error { if needsBroadcast { l.broadcast(b) l.metrics.propagatedMessagesTotal.Inc() - l.logger.Debug("gossiping new entry", "entry", e) + l.logger.Debug("gossiping received state") } return nil }