@@ -262,7 +262,7 @@ func TestDistributor_Push(t *testing.T) {
262
262
limits .IngestionRate = 20
263
263
limits .IngestionBurstSize = 20
264
264
265
- ds , _ , regs := prepare (t , prepConfig {
265
+ ds , _ , regs , _ := prepare (t , prepConfig {
266
266
numIngesters : tc .numIngesters ,
267
267
happyIngesters : tc .happyIngesters ,
268
268
numDistributors : 1 ,
@@ -291,7 +291,7 @@ func TestDistributor_Push(t *testing.T) {
291
291
}
292
292
293
293
func TestDistributor_MetricsCleanup (t * testing.T ) {
294
- dists , _ , regs := prepare (t , prepConfig {
294
+ dists , _ , regs , _ := prepare (t , prepConfig {
295
295
numDistributors : 1 ,
296
296
})
297
297
d := dists [0 ]
@@ -468,7 +468,7 @@ func TestDistributor_PushIngestionRateLimiter(t *testing.T) {
468
468
limits .IngestionBurstSize = testData .ingestionBurstSize
469
469
470
470
// Start all expected distributors
471
- distributors , _ , _ := prepare (t , prepConfig {
471
+ distributors , _ , _ , _ := prepare (t , prepConfig {
472
472
numIngesters : 3 ,
473
473
happyIngesters : 3 ,
474
474
numDistributors : testData .distributors ,
@@ -499,7 +499,7 @@ func TestPush_QuorumError(t *testing.T) {
499
499
500
500
limits .IngestionRate = math .MaxFloat64
501
501
502
- dists , ingesters , r , _ := prepare (t , prepConfig {
502
+ dists , ingesters , _ , r := prepare (t , prepConfig {
503
503
numDistributors : 1 ,
504
504
numIngesters : 3 ,
505
505
happyIngesters : 0 ,
@@ -545,7 +545,7 @@ func TestPush_QuorumError(t *testing.T) {
545
545
ingesters [1 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
546
546
ingesters [2 ].happy .Store (true )
547
547
548
- for i := 0 ; i < 1000 ; i ++ {
548
+ for i := 0 ; i < 1 ; i ++ {
549
549
request := makeWriteRequest (0 , 30 , 20 )
550
550
_ , err := d .Push (ctx , request )
551
551
status , ok := status .FromError (err )
@@ -558,7 +558,7 @@ func TestPush_QuorumError(t *testing.T) {
558
558
ingesters [1 ].happy .Store (true )
559
559
ingesters [2 ].happy .Store (true )
560
560
561
- for i := 0 ; i < 1000 ; i ++ {
561
+ for i := 0 ; i < 1 ; i ++ {
562
562
request := makeWriteRequest (0 , 30 , 20 )
563
563
_ , err := d .Push (ctx , request )
564
564
require .NoError (t , err )
@@ -569,7 +569,19 @@ func TestPush_QuorumError(t *testing.T) {
569
569
ingesters [1 ].happy .Store (true )
570
570
ingesters [2 ].happy .Store (true )
571
571
572
- err := r .KVClient .CAS (context .Background (), ring .IngesterRingKey , func (in interface {}) (interface {}, bool , error ) {
572
+ // Wait group to check when the ring got updated
573
+ wg := & sync.WaitGroup {}
574
+ wg .Add (1 )
575
+
576
+ go func () {
577
+ r .KVClient .WatchKey (context .Background (), ingester .RingKey , func (i interface {}) bool {
578
+ wg .Done ()
579
+ // False will terminate the watch
580
+ return false
581
+ })
582
+ }()
583
+
584
+ err := r .KVClient .CAS (context .Background (), ingester .RingKey , func (in interface {}) (interface {}, bool , error ) {
573
585
r := in .(* ring.Desc )
574
586
ingester2 := r .Ingesters ["2" ]
575
587
ingester2 .State = ring .LEFT
@@ -581,7 +593,7 @@ func TestPush_QuorumError(t *testing.T) {
581
593
require .NoError (t , err )
582
594
583
595
// Give time to the ring get updated with the KV value
584
- time . Sleep ( time . Second )
596
+ wg . Wait ( )
585
597
586
598
for i := 0 ; i < 1000 ; i ++ {
587
599
request := makeWriteRequest (0 , 30 , 20 )
@@ -707,7 +719,7 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
707
719
flagext .DefaultValues (limits )
708
720
709
721
// Start all expected distributors
710
- distributors , _ , regs := prepare (t , prepConfig {
722
+ distributors , _ , regs , _ := prepare (t , prepConfig {
711
723
numIngesters : 3 ,
712
724
happyIngesters : 3 ,
713
725
numDistributors : 1 ,
@@ -799,7 +811,7 @@ func TestDistributor_PushHAInstances(t *testing.T) {
799
811
limits .AcceptHASamples = true
800
812
limits .MaxLabelValueLength = 15
801
813
802
- ds , _ , _ := prepare (t , prepConfig {
814
+ ds , _ , _ , _ := prepare (t , prepConfig {
803
815
numIngesters : 3 ,
804
816
happyIngesters : 3 ,
805
817
numDistributors : 1 ,
@@ -963,7 +975,7 @@ func TestDistributor_PushQuery(t *testing.T) {
963
975
964
976
for _ , tc := range testcases {
965
977
t .Run (tc .name , func (t * testing.T ) {
966
- ds , ingesters , _ := prepare (t , prepConfig {
978
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
967
979
numIngesters : tc .numIngesters ,
968
980
happyIngesters : tc .happyIngesters ,
969
981
numDistributors : 1 ,
@@ -1014,7 +1026,7 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxChunksPerQueryLimitIsReac
1014
1026
limits .MaxChunksPerQuery = maxChunksLimit
1015
1027
1016
1028
// Prepare distributors.
1017
- ds , _ , _ := prepare (t , prepConfig {
1029
+ ds , _ , _ , _ := prepare (t , prepConfig {
1018
1030
numIngesters : 3 ,
1019
1031
happyIngesters : 3 ,
1020
1032
numDistributors : 1 ,
@@ -1070,7 +1082,7 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxSeriesPerQueryLimitIsReac
1070
1082
ctx = limiter .AddQueryLimiterToContext (ctx , limiter .NewQueryLimiter (maxSeriesLimit , 0 , 0 ))
1071
1083
1072
1084
// Prepare distributors.
1073
- ds , _ , _ := prepare (t , prepConfig {
1085
+ ds , _ , _ , _ := prepare (t , prepConfig {
1074
1086
numIngesters : 3 ,
1075
1087
happyIngesters : 3 ,
1076
1088
numDistributors : 1 ,
@@ -1123,7 +1135,7 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxChunkBytesPerQueryLimitIs
1123
1135
// Prepare distributors.
1124
1136
// Use replication factor of 2 to always read all the chunks from both ingesters,
1125
1137
// this guarantees us to always read the same chunks and have a stable test.
1126
- ds , _ , _ := prepare (t , prepConfig {
1138
+ ds , _ , _ , _ := prepare (t , prepConfig {
1127
1139
numIngesters : 2 ,
1128
1140
happyIngesters : 2 ,
1129
1141
numDistributors : 1 ,
@@ -1245,7 +1257,7 @@ func TestDistributor_Push_LabelRemoval(t *testing.T) {
1245
1257
limits .DropLabels = tc .removeLabels
1246
1258
limits .AcceptHASamples = tc .removeReplica
1247
1259
1248
- ds , ingesters , _ := prepare (t , prepConfig {
1260
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
1249
1261
numIngesters : 2 ,
1250
1262
happyIngesters : 2 ,
1251
1263
numDistributors : 1 ,
@@ -1296,7 +1308,7 @@ func TestDistributor_Push_LabelRemoval_RemovingNameLabelWillError(t *testing.T)
1296
1308
limits .DropLabels = tc .removeLabels
1297
1309
limits .AcceptHASamples = tc .removeReplica
1298
1310
1299
- ds , _ , _ := prepare (t , prepConfig {
1311
+ ds , _ , _ , _ := prepare (t , prepConfig {
1300
1312
numIngesters : 2 ,
1301
1313
happyIngesters : 2 ,
1302
1314
numDistributors : 1 ,
@@ -1390,7 +1402,7 @@ func TestDistributor_Push_ShouldGuaranteeShardingTokenConsistencyOverTheTime(t *
1390
1402
1391
1403
for testName , testData := range tests {
1392
1404
t .Run (testName , func (t * testing.T ) {
1393
- ds , ingesters , _ := prepare (t , prepConfig {
1405
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
1394
1406
numIngesters : 2 ,
1395
1407
happyIngesters : 2 ,
1396
1408
numDistributors : 1 ,
@@ -1450,7 +1462,7 @@ func TestDistributor_Push_LabelNameValidation(t *testing.T) {
1450
1462
1451
1463
for testName , tc := range tests {
1452
1464
t .Run (testName , func (t * testing.T ) {
1453
- ds , _ , _ := prepare (t , prepConfig {
1465
+ ds , _ , _ , _ := prepare (t , prepConfig {
1454
1466
numIngesters : 2 ,
1455
1467
happyIngesters : 2 ,
1456
1468
numDistributors : 1 ,
@@ -1512,7 +1524,7 @@ func TestDistributor_Push_ExemplarValidation(t *testing.T) {
1512
1524
1513
1525
for testName , tc := range tests {
1514
1526
t .Run (testName , func (t * testing.T ) {
1515
- ds , _ , _ := prepare (t , prepConfig {
1527
+ ds , _ , _ , _ := prepare (t , prepConfig {
1516
1528
numIngesters : 2 ,
1517
1529
happyIngesters : 2 ,
1518
1530
numDistributors : 1 ,
@@ -1813,7 +1825,7 @@ func TestSlowQueries(t *testing.T) {
1813
1825
expectedErr = errFail
1814
1826
}
1815
1827
1816
- ds , _ , _ := prepare (t , prepConfig {
1828
+ ds , _ , _ , _ := prepare (t , prepConfig {
1817
1829
numIngesters : nIngesters ,
1818
1830
happyIngesters : happy ,
1819
1831
numDistributors : 1 ,
@@ -1922,7 +1934,7 @@ func TestDistributor_MetricsForLabelMatchers(t *testing.T) {
1922
1934
now := model .Now ()
1923
1935
1924
1936
// Create distributor
1925
- ds , ingesters , _ := prepare (t , prepConfig {
1937
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
1926
1938
numIngesters : numIngesters ,
1927
1939
happyIngesters : numIngesters ,
1928
1940
numDistributors : 1 ,
@@ -1980,7 +1992,7 @@ func TestDistributor_MetricsMetadata(t *testing.T) {
1980
1992
for testName , testData := range tests {
1981
1993
t .Run (testName , func (t * testing.T ) {
1982
1994
// Create distributor
1983
- ds , ingesters , _ := prepare (t , prepConfig {
1995
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
1984
1996
numIngesters : numIngesters ,
1985
1997
happyIngesters : numIngesters ,
1986
1998
numDistributors : 1 ,
@@ -2048,7 +2060,7 @@ type prepConfig struct {
2048
2060
errFail error
2049
2061
}
2050
2062
2051
- func prepare (t * testing.T , cfg prepConfig ) ([]* Distributor , []mockIngester , []* prometheus.Registry ) {
2063
+ func prepare (t * testing.T , cfg prepConfig ) ([]* Distributor , []mockIngester , []* prometheus.Registry , * ring. Ring ) {
2052
2064
ingesters := []mockIngester {}
2053
2065
for i := 0 ; i < cfg .happyIngesters ; i ++ {
2054
2066
ingesters = append (ingesters , mockIngester {
@@ -2186,7 +2198,7 @@ func prepare(t *testing.T, cfg prepConfig) ([]*Distributor, []mockIngester, []*p
2186
2198
2187
2199
t .Cleanup (func () { stopAll (distributors , ingestersRing ) })
2188
2200
2189
- return distributors , ingesters , registries
2201
+ return distributors , ingesters , registries , ingestersRing
2190
2202
}
2191
2203
2192
2204
func stopAll (ds []* Distributor , r * ring.Ring ) {
@@ -2684,7 +2696,7 @@ func TestDistributorValidation(t *testing.T) {
2684
2696
limits .RejectOldSamplesMaxAge = model .Duration (24 * time .Hour )
2685
2697
limits .MaxLabelNamesPerSeries = 2
2686
2698
2687
- ds , _ , _ := prepare (t , prepConfig {
2699
+ ds , _ , _ , _ := prepare (t , prepConfig {
2688
2700
numIngesters : 3 ,
2689
2701
happyIngesters : 3 ,
2690
2702
numDistributors : 1 ,
@@ -2865,7 +2877,7 @@ func TestDistributor_Push_Relabel(t *testing.T) {
2865
2877
flagext .DefaultValues (& limits )
2866
2878
limits .MetricRelabelConfigs = tc .metricRelabelConfigs
2867
2879
2868
- ds , ingesters , _ := prepare (t , prepConfig {
2880
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
2869
2881
numIngesters : 2 ,
2870
2882
happyIngesters : 2 ,
2871
2883
numDistributors : 1 ,
@@ -2916,7 +2928,7 @@ func TestDistributor_Push_RelabelDropWillExportMetricOfDroppedSamples(t *testing
2916
2928
flagext .DefaultValues (& limits )
2917
2929
limits .MetricRelabelConfigs = metricRelabelConfigs
2918
2930
2919
- ds , ingesters , regs := prepare (t , prepConfig {
2931
+ ds , ingesters , regs , _ := prepare (t , prepConfig {
2920
2932
numIngesters : 2 ,
2921
2933
happyIngesters : 2 ,
2922
2934
numDistributors : 1 ,
0 commit comments