@@ -40,6 +40,14 @@ func testLifecyclerConfig(ringConfig Config, id string) LifecyclerConfig {
40
40
return lifecyclerConfig
41
41
}
42
42
43
+ // testLifecyclerConfigWithAddr creates a LifecyclerConfig with the given address.
44
+ // This is useful for testing when we want to set the address to a specific value.
45
+ func testLifecyclerConfigWithAddr (ringConfig Config , id string , addr string ) LifecyclerConfig {
46
+ l := testLifecyclerConfig (ringConfig , id )
47
+ l .Addr = addr
48
+ return l
49
+ }
50
+
43
51
func checkNormalised (d interface {}, id string ) bool {
44
52
desc , ok := d .(* Desc )
45
53
return ok &&
@@ -644,8 +652,8 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
644
652
}
645
653
646
654
// Starts Ingester and wait it to became active
647
- startIngesterAndWaitActive := func (ingId string ) * Lifecycler {
648
- lifecyclerConfig := testLifecyclerConfig (ringConfig , ingId )
655
+ startIngesterAndWaitActive := func (ingId string , addr string ) * Lifecycler {
656
+ lifecyclerConfig := testLifecyclerConfigWithAddr (ringConfig , ingId , addr )
649
657
// Disabling heartBeat and unregister_on_shutdown
650
658
lifecyclerConfig .UnregisterOnShutdown = false
651
659
lifecyclerConfig .HeartbeatPeriod = 0
@@ -662,10 +670,10 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
662
670
// test if the ingester 2 became active after:
663
671
// * Clean Shutdown (LEAVING after shutdown)
664
672
// * Crashes while in the PENDING or JOINING state
665
- l1 := startIngesterAndWaitActive ("ing1" )
673
+ l1 := startIngesterAndWaitActive ("ing1" , "0.0.0.0" )
666
674
defer services .StopAndAwaitTerminated (context .Background (), l1 ) //nolint:errcheck
667
675
668
- l2 := startIngesterAndWaitActive ("ing2" )
676
+ l2 := startIngesterAndWaitActive ("ing2" , "0.0.0.0" )
669
677
670
678
ingesters := poll (func (desc * Desc ) bool {
671
679
return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing1" ].State == ACTIVE && desc .Ingesters ["ing2" ].State == ACTIVE
@@ -684,7 +692,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
684
692
assert .Equal (t , LEAVING , ingesters ["ing2" ].State )
685
693
686
694
// Start Ingester2 again - Should flip back to ACTIVE in the ring
687
- l2 = startIngesterAndWaitActive ("ing2" )
695
+ l2 = startIngesterAndWaitActive ("ing2" , "0.0.0.0" )
688
696
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
689
697
690
698
// Simulate ingester2 crash on startup and left the ring with JOINING state
@@ -698,7 +706,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
698
706
})
699
707
require .NoError (t , err )
700
708
701
- l2 = startIngesterAndWaitActive ("ing2" )
709
+ l2 = startIngesterAndWaitActive ("ing2" , "0.0.0.0" )
702
710
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
703
711
704
712
// Simulate ingester2 crash on startup and left the ring with PENDING state
@@ -712,7 +720,26 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
712
720
})
713
721
require .NoError (t , err )
714
722
715
- l2 = startIngesterAndWaitActive ("ing2" )
723
+ l2 = startIngesterAndWaitActive ("ing2" , "0.0.0.0" )
724
+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
725
+
726
+ // Simulate ingester2 crashing and left the ring with ACTIVE state, but when it comes up
727
+ // it has a different ip address
728
+ startIngesterAndWaitActive ("ing2" , "0.0.0.0" )
729
+ ingesters = poll (func (desc * Desc ) bool {
730
+ return desc .Ingesters ["ing2" ].State == ACTIVE && desc .Ingesters ["ing2" ].Addr == "0.0.0.0:1"
731
+ })
732
+ assert .Equal (t , ACTIVE , ingesters ["ing2" ].State )
733
+ assert .Equal (t , "0.0.0.0:1" , ingesters ["ing2" ].Addr )
734
+
735
+ l2 = startIngesterAndWaitActive ("ing2" , "1.1.1.1" )
736
+
737
+ // The ring should have the new ip address
738
+ ingesters = poll (func (desc * Desc ) bool {
739
+ return desc .Ingesters ["ing2" ].State == ACTIVE && desc .Ingesters ["ing2" ].Addr == "1.1.1.1:1"
740
+ })
741
+ assert .Equal (t , ACTIVE , ingesters ["ing2" ].State )
742
+ assert .Equal (t , "1.1.1.1:1" , ingesters ["ing2" ].Addr )
716
743
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
717
744
}
718
745
0 commit comments