@@ -250,6 +250,10 @@ type MultitenantAlertmanager struct {
250
250
distributor * Distributor
251
251
grpcServer * server.Server
252
252
253
+ // Last ring state. This variable is not protected with a mutex because it's always
254
+ // accessed by a single goroutine at a time.
255
+ ringLastState ring.ReplicationSet
256
+
253
257
// Subservices manager (ring, lifecycler)
254
258
subservices * services.Manager
255
259
subservicesWatcher * services.FailureWatcher
@@ -488,6 +492,10 @@ func (am *MultitenantAlertmanager) starting(ctx context.Context) (err error) {
488
492
}
489
493
490
494
if am .cfg .ShardingEnabled {
495
+ // Store the ring state after the initial Alertmanager configs sync has been done and before we do change
496
+ // our state in the ring.
497
+ am .ringLastState , _ = am .ring .GetAllHealthy (RingOp )
498
+
491
499
// Make sure that all the alertmanagers we were initially configured with have
492
500
// fetched state from the replicas, before advertising as ACTIVE. This will
493
501
// reduce the possibility that we lose state when new instances join/leave.
@@ -631,10 +639,8 @@ func (am *MultitenantAlertmanager) run(ctx context.Context) error {
631
639
defer tick .Stop ()
632
640
633
641
var ringTickerChan <- chan time.Time
634
- var ringLastState ring.ReplicationSet
635
642
636
643
if am .cfg .ShardingEnabled {
637
- ringLastState , _ = am .ring .GetAllHealthy (RingOp )
638
644
ringTicker := time .NewTicker (util .DurationWithJitter (am .cfg .ShardingRing .RingCheckPeriod , 0.2 ))
639
645
defer ringTicker .Stop ()
640
646
ringTickerChan = ringTicker .C
@@ -656,8 +662,8 @@ func (am *MultitenantAlertmanager) run(ctx context.Context) error {
656
662
// replication set which we use to compare with the previous state.
657
663
currRingState , _ := am .ring .GetAllHealthy (RingOp )
658
664
659
- if ring .HasReplicationSetChanged (ringLastState , currRingState ) {
660
- ringLastState = currRingState
665
+ if ring .HasReplicationSetChanged (am . ringLastState , currRingState ) {
666
+ am . ringLastState = currRingState
661
667
if err := am .loadAndSyncConfigs (ctx , reasonRingChange ); err != nil {
662
668
level .Warn (am .logger ).Log ("msg" , "error while synchronizing alertmanager configs" , "err" , err )
663
669
}
0 commit comments