@@ -258,15 +258,14 @@ func TestDistributor_Push(t *testing.T) {
258
258
limits .IngestionRate = 20
259
259
limits .IngestionBurstSize = 20
260
260
261
- ds , _ , r , regs := prepare (t , prepConfig {
261
+ ds , _ , regs := prepare (t , prepConfig {
262
262
numIngesters : tc .numIngesters ,
263
263
happyIngesters : tc .happyIngesters ,
264
264
numDistributors : 1 ,
265
265
shardByAllLabels : shardByAllLabels ,
266
266
limits : limits ,
267
267
errFail : tc .ingesterError ,
268
268
})
269
- defer stopAll (ds , r )
270
269
271
270
request := makeWriteRequest (tc .samples .startTimestampMs , tc .samples .num , tc .metadata )
272
271
response , err := ds [0 ].Push (ctx , request )
@@ -288,7 +287,7 @@ func TestDistributor_Push(t *testing.T) {
288
287
}
289
288
290
289
func TestDistributor_MetricsCleanup (t * testing.T ) {
291
- dists , _ , _ , regs := prepare (t , prepConfig {
290
+ dists , _ , regs := prepare (t , prepConfig {
292
291
numDistributors : 1 ,
293
292
})
294
293
d := dists [0 ]
@@ -465,14 +464,13 @@ func TestDistributor_PushIngestionRateLimiter(t *testing.T) {
465
464
limits .IngestionBurstSize = testData .ingestionBurstSize
466
465
467
466
// Start all expected distributors
468
- distributors , _ , r , _ := prepare (t , prepConfig {
467
+ distributors , _ , _ := prepare (t , prepConfig {
469
468
numIngesters : 3 ,
470
469
happyIngesters : 3 ,
471
470
numDistributors : testData .distributors ,
472
471
shardByAllLabels : true ,
473
472
limits : limits ,
474
473
})
475
- defer stopAll (distributors , r )
476
474
477
475
// Push samples in multiple requests to the first distributor
478
476
for _ , push := range testData .pushes {
@@ -605,7 +603,7 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
605
603
flagext .DefaultValues (limits )
606
604
607
605
// Start all expected distributors
608
- distributors , _ , r , regs := prepare (t , prepConfig {
606
+ distributors , _ , regs := prepare (t , prepConfig {
609
607
numIngesters : 3 ,
610
608
happyIngesters : 3 ,
611
609
numDistributors : 1 ,
@@ -614,7 +612,6 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
614
612
maxInflightRequests : testData .inflightLimit ,
615
613
maxIngestionRate : testData .ingestionRateLimit ,
616
614
})
617
- defer stopAll (distributors , r )
618
615
619
616
d := distributors [0 ]
620
617
d .inflightPushRequests .Add (int64 (testData .preInflight ))
@@ -698,34 +695,17 @@ func TestDistributor_PushHAInstances(t *testing.T) {
698
695
limits .AcceptHASamples = true
699
696
limits .MaxLabelValueLength = 15
700
697
701
- ds , _ , r , _ := prepare (t , prepConfig {
698
+ ds , _ , _ := prepare (t , prepConfig {
702
699
numIngesters : 3 ,
703
700
happyIngesters : 3 ,
704
701
numDistributors : 1 ,
705
702
shardByAllLabels : shardByAllLabels ,
706
703
limits : & limits ,
704
+ enableTracker : tc .enableTracker ,
707
705
})
708
- defer stopAll (ds , r )
709
- codec := GetReplicaDescCodec ()
710
706
711
- ringStore , closer := consul .NewInMemoryClient (codec , log .NewNopLogger (), nil )
712
- t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
713
-
714
- mock := kv .PrefixClient (ringStore , "prefix" )
715
707
d := ds [0 ]
716
708
717
- if tc .enableTracker {
718
- r , err := newHATracker (HATrackerConfig {
719
- EnableHATracker : true ,
720
- KVStore : kv.Config {Mock : mock },
721
- UpdateTimeout : 100 * time .Millisecond ,
722
- FailoverTimeout : time .Second ,
723
- }, trackerLimits {maxClusters : 100 }, nil , log .NewNopLogger ())
724
- require .NoError (t , err )
725
- require .NoError (t , services .StartAndAwaitRunning (context .Background (), r ))
726
- d .HATracker = r
727
- }
728
-
729
709
userID , err := tenant .TenantID (ctx )
730
710
assert .NoError (t , err )
731
711
err = d .HATracker .checkReplica (ctx , userID , tc .cluster , tc .acceptedReplica , time .Now ())
@@ -879,15 +859,14 @@ func TestDistributor_PushQuery(t *testing.T) {
879
859
880
860
for _ , tc := range testcases {
881
861
t .Run (tc .name , func (t * testing.T ) {
882
- ds , ingesters , r , _ := prepare (t , prepConfig {
862
+ ds , ingesters , _ := prepare (t , prepConfig {
883
863
numIngesters : tc .numIngesters ,
884
864
happyIngesters : tc .happyIngesters ,
885
865
numDistributors : 1 ,
886
866
shardByAllLabels : tc .shardByAllLabels ,
887
867
shuffleShardEnabled : tc .shuffleShardEnabled ,
888
868
shuffleShardSize : shuffleShardSize ,
889
869
})
890
- defer stopAll (ds , r )
891
870
892
871
request := makeWriteRequest (0 , tc .samples , tc .metadata )
893
872
writeResponse , err := ds [0 ].Push (ctx , request )
@@ -931,7 +910,7 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxChunksPerQueryLimitIsReac
931
910
limits .MaxChunksPerQuery = maxChunksLimit
932
911
933
912
// Prepare distributors.
934
- ds , _ , r , _ := prepare (t , prepConfig {
913
+ ds , _ , _ := prepare (t , prepConfig {
935
914
numIngesters : 3 ,
936
915
happyIngesters : 3 ,
937
916
numDistributors : 1 ,
@@ -940,7 +919,6 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxChunksPerQueryLimitIsReac
940
919
})
941
920
942
921
ctx = limiter .AddQueryLimiterToContext (ctx , limiter .NewQueryLimiter (0 , 0 , maxChunksLimit ))
943
- defer stopAll (ds , r )
944
922
945
923
// Push a number of series below the max chunks limit. Each series has 1 sample,
946
924
// so expect 1 chunk per series when querying back.
@@ -988,14 +966,13 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxSeriesPerQueryLimitIsReac
988
966
ctx = limiter .AddQueryLimiterToContext (ctx , limiter .NewQueryLimiter (maxSeriesLimit , 0 , 0 ))
989
967
990
968
// Prepare distributors.
991
- ds , _ , r , _ := prepare (t , prepConfig {
969
+ ds , _ , _ := prepare (t , prepConfig {
992
970
numIngesters : 3 ,
993
971
happyIngesters : 3 ,
994
972
numDistributors : 1 ,
995
973
shardByAllLabels : true ,
996
974
limits : limits ,
997
975
})
998
- defer stopAll (ds , r )
999
976
1000
977
// Push a number of series below the max series limit.
1001
978
initialSeries := maxSeriesLimit
@@ -1042,15 +1019,14 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxChunkBytesPerQueryLimitIs
1042
1019
// Prepare distributors.
1043
1020
// Use replication factor of 2 to always read all the chunks from both ingesters,
1044
1021
// this guarantees us to always read the same chunks and have a stable test.
1045
- ds , _ , r , _ := prepare (t , prepConfig {
1022
+ ds , _ , _ := prepare (t , prepConfig {
1046
1023
numIngesters : 2 ,
1047
1024
happyIngesters : 2 ,
1048
1025
numDistributors : 1 ,
1049
1026
shardByAllLabels : true ,
1050
1027
limits : limits ,
1051
1028
replicationFactor : 2 ,
1052
1029
})
1053
- defer stopAll (ds , r )
1054
1030
1055
1031
allSeriesMatchers := []* labels.Matcher {
1056
1032
labels .MustNewMatcher (labels .MatchRegexp , model .MetricNameLabel , ".+" ),
@@ -1165,14 +1141,13 @@ func TestDistributor_Push_LabelRemoval(t *testing.T) {
1165
1141
limits .DropLabels = tc .removeLabels
1166
1142
limits .AcceptHASamples = tc .removeReplica
1167
1143
1168
- ds , ingesters , r , _ := prepare (t , prepConfig {
1144
+ ds , ingesters , _ := prepare (t , prepConfig {
1169
1145
numIngesters : 2 ,
1170
1146
happyIngesters : 2 ,
1171
1147
numDistributors : 1 ,
1172
1148
shardByAllLabels : true ,
1173
1149
limits : & limits ,
1174
1150
})
1175
- defer stopAll (ds , r )
1176
1151
1177
1152
// Push the series to the distributor
1178
1153
req := mockWriteRequest (tc .inputSeries , 1 , 1 )
@@ -1270,14 +1245,13 @@ func TestDistributor_Push_ShouldGuaranteeShardingTokenConsistencyOverTheTime(t *
1270
1245
1271
1246
for testName , testData := range tests {
1272
1247
t .Run (testName , func (t * testing.T ) {
1273
- ds , ingesters , r , _ := prepare (t , prepConfig {
1248
+ ds , ingesters , _ := prepare (t , prepConfig {
1274
1249
numIngesters : 2 ,
1275
1250
happyIngesters : 2 ,
1276
1251
numDistributors : 1 ,
1277
1252
shardByAllLabels : true ,
1278
1253
limits : & limits ,
1279
1254
})
1280
- defer stopAll (ds , r )
1281
1255
1282
1256
// Push the series to the distributor
1283
1257
req := mockWriteRequest (testData .inputSeries , 1 , 1 )
@@ -1331,7 +1305,7 @@ func TestDistributor_Push_LabelNameValidation(t *testing.T) {
1331
1305
1332
1306
for testName , tc := range tests {
1333
1307
t .Run (testName , func (t * testing.T ) {
1334
- ds , _ , _ , _ := prepare (t , prepConfig {
1308
+ ds , _ , _ := prepare (t , prepConfig {
1335
1309
numIngesters : 2 ,
1336
1310
happyIngesters : 2 ,
1337
1311
numDistributors : 1 ,
@@ -1393,7 +1367,7 @@ func TestDistributor_Push_ExemplarValidation(t *testing.T) {
1393
1367
1394
1368
for testName , tc := range tests {
1395
1369
t .Run (testName , func (t * testing.T ) {
1396
- ds , _ , _ , _ := prepare (t , prepConfig {
1370
+ ds , _ , _ := prepare (t , prepConfig {
1397
1371
numIngesters : 2 ,
1398
1372
happyIngesters : 2 ,
1399
1373
numDistributors : 1 ,
@@ -1694,14 +1668,13 @@ func TestSlowQueries(t *testing.T) {
1694
1668
expectedErr = errFail
1695
1669
}
1696
1670
1697
- ds , _ , r , _ := prepare (t , prepConfig {
1671
+ ds , _ , _ := prepare (t , prepConfig {
1698
1672
numIngesters : nIngesters ,
1699
1673
happyIngesters : happy ,
1700
1674
numDistributors : 1 ,
1701
1675
queryDelay : 100 * time .Millisecond ,
1702
1676
shardByAllLabels : shardByAllLabels ,
1703
1677
})
1704
- defer stopAll (ds , r )
1705
1678
1706
1679
_ , err := ds [0 ].Query (ctx , 0 , 10 , nameMatcher )
1707
1680
assert .Equal (t , expectedErr , err )
@@ -1804,15 +1777,14 @@ func TestDistributor_MetricsForLabelMatchers(t *testing.T) {
1804
1777
now := model .Now ()
1805
1778
1806
1779
// Create distributor
1807
- ds , ingesters , r , _ := prepare (t , prepConfig {
1780
+ ds , ingesters , _ := prepare (t , prepConfig {
1808
1781
numIngesters : numIngesters ,
1809
1782
happyIngesters : numIngesters ,
1810
1783
numDistributors : 1 ,
1811
1784
shardByAllLabels : true ,
1812
1785
shuffleShardEnabled : testData .shuffleShardEnabled ,
1813
1786
shuffleShardSize : testData .shuffleShardSize ,
1814
1787
})
1815
- defer stopAll (ds , r )
1816
1788
1817
1789
// Push fixtures
1818
1790
ctx := user .InjectOrgID (context .Background (), "test" )
@@ -1863,7 +1835,7 @@ func TestDistributor_MetricsMetadata(t *testing.T) {
1863
1835
for testName , testData := range tests {
1864
1836
t .Run (testName , func (t * testing.T ) {
1865
1837
// Create distributor
1866
- ds , ingesters , r , _ := prepare (t , prepConfig {
1838
+ ds , ingesters , _ := prepare (t , prepConfig {
1867
1839
numIngesters : numIngesters ,
1868
1840
happyIngesters : numIngesters ,
1869
1841
numDistributors : 1 ,
@@ -1872,7 +1844,6 @@ func TestDistributor_MetricsMetadata(t *testing.T) {
1872
1844
shuffleShardSize : testData .shuffleShardSize ,
1873
1845
limits : nil ,
1874
1846
})
1875
- defer stopAll (ds , r )
1876
1847
1877
1848
// Push metadata
1878
1849
ctx := user .InjectOrgID (context .Background (), "test" )
@@ -1927,10 +1898,11 @@ type prepConfig struct {
1927
1898
maxInflightRequests int
1928
1899
maxIngestionRate float64
1929
1900
replicationFactor int
1901
+ enableTracker bool
1930
1902
errFail error
1931
1903
}
1932
1904
1933
- func prepare (t * testing.T , cfg prepConfig ) ([]* Distributor , []mockIngester , * ring. Ring , []* prometheus.Registry ) {
1905
+ func prepare (t * testing.T , cfg prepConfig ) ([]* Distributor , []mockIngester , []* prometheus.Registry ) {
1934
1906
ingesters := []mockIngester {}
1935
1907
for i := 0 ; i < cfg .happyIngesters ; i ++ {
1936
1908
ingesters = append (ingesters , mockIngester {
@@ -2032,6 +2004,20 @@ func prepare(t *testing.T, cfg prepConfig) ([]*Distributor, []mockIngester, *rin
2032
2004
cfg .limits .IngestionTenantShardSize = cfg .shuffleShardSize
2033
2005
}
2034
2006
2007
+ if cfg .enableTracker {
2008
+ codec := GetReplicaDescCodec ()
2009
+ ringStore , closer := consul .NewInMemoryClient (codec , log .NewNopLogger (), nil )
2010
+ t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
2011
+ mock := kv .PrefixClient (ringStore , "prefix" )
2012
+ distributorCfg .HATrackerConfig = HATrackerConfig {
2013
+ EnableHATracker : true ,
2014
+ KVStore : kv.Config {Mock : mock },
2015
+ UpdateTimeout : 100 * time .Millisecond ,
2016
+ FailoverTimeout : time .Second ,
2017
+ }
2018
+ cfg .limits .HAMaxClusters = 100
2019
+ }
2020
+
2035
2021
overrides , err := validation .NewOverrides (* cfg .limits , nil )
2036
2022
require .NoError (t , err )
2037
2023
@@ -2052,7 +2038,9 @@ func prepare(t *testing.T, cfg prepConfig) ([]*Distributor, []mockIngester, *rin
2052
2038
})
2053
2039
}
2054
2040
2055
- return distributors , ingesters , ingestersRing , registries
2041
+ t .Cleanup (func () { stopAll (distributors , ingestersRing ) })
2042
+
2043
+ return distributors , ingesters , registries
2056
2044
}
2057
2045
2058
2046
func stopAll (ds []* Distributor , r * ring.Ring ) {
@@ -2550,14 +2538,13 @@ func TestDistributorValidation(t *testing.T) {
2550
2538
limits .RejectOldSamplesMaxAge = model .Duration (24 * time .Hour )
2551
2539
limits .MaxLabelNamesPerSeries = 2
2552
2540
2553
- ds , _ , r , _ := prepare (t , prepConfig {
2541
+ ds , _ , _ := prepare (t , prepConfig {
2554
2542
numIngesters : 3 ,
2555
2543
happyIngesters : 3 ,
2556
2544
numDistributors : 1 ,
2557
2545
shardByAllLabels : true ,
2558
2546
limits : & limits ,
2559
2547
})
2560
- defer stopAll (ds , r )
2561
2548
2562
2549
_ , err := ds [0 ].Push (ctx , cortexpb .ToWriteRequest (tc .labels , tc .samples , tc .metadata , cortexpb .API ))
2563
2550
require .Equal (t , tc .err , err )
@@ -2701,14 +2688,13 @@ func TestDistributor_Push_Relabel(t *testing.T) {
2701
2688
flagext .DefaultValues (& limits )
2702
2689
limits .MetricRelabelConfigs = tc .metricRelabelConfigs
2703
2690
2704
- ds , ingesters , r , _ := prepare (t , prepConfig {
2691
+ ds , ingesters , _ := prepare (t , prepConfig {
2705
2692
numIngesters : 2 ,
2706
2693
happyIngesters : 2 ,
2707
2694
numDistributors : 1 ,
2708
2695
shardByAllLabels : true ,
2709
2696
limits : & limits ,
2710
2697
})
2711
- defer stopAll (ds , r )
2712
2698
2713
2699
// Push the series to the distributor
2714
2700
req := mockWriteRequest (tc .inputSeries , 1 , 1 )
0 commit comments