@@ -2391,6 +2391,7 @@ type prepConfig struct {
2391
2391
replicationFactor int
2392
2392
enableTracker bool
2393
2393
errFail error
2394
+ tokens [][]uint32
2394
2395
}
2395
2396
2396
2397
func prepare (tb testing.TB , cfg prepConfig ) ([]* Distributor , []* mockIngester , []* prometheus.Registry , * ring.Ring ) {
@@ -2417,14 +2418,20 @@ func prepare(tb testing.TB, cfg prepConfig) ([]*Distributor, []*mockIngester, []
2417
2418
ingesterDescs := map [string ]ring.InstanceDesc {}
2418
2419
ingestersByAddr := map [string ]* mockIngester {}
2419
2420
for i := range ingesters {
2421
+ var tokens []uint32
2422
+ if len (cfg .tokens ) > i {
2423
+ tokens = cfg .tokens [i ]
2424
+ } else {
2425
+ tokens = []uint32 {uint32 ((math .MaxUint32 / cfg .numIngesters ) * i )}
2426
+ }
2420
2427
addr := fmt .Sprintf ("%d" , i )
2421
2428
ingesterDescs [addr ] = ring.InstanceDesc {
2422
2429
Addr : addr ,
2423
2430
Zone : "" ,
2424
2431
State : ring .ACTIVE ,
2425
2432
Timestamp : time .Now ().Unix (),
2426
2433
RegisteredTimestamp : time .Now ().Add (- 2 * time .Hour ).Unix (),
2427
- Tokens : [] uint32 { uint32 (( math . MaxUint32 / cfg . numIngesters ) * i )} ,
2434
+ Tokens : tokens ,
2428
2435
}
2429
2436
ingestersByAddr [addr ] = ingesters [i ]
2430
2437
}
@@ -3303,6 +3310,86 @@ func TestDistributor_Push_Relabel(t *testing.T) {
3303
3310
}
3304
3311
}
3305
3312
3313
+ func TestDistributor_Push_EmptyLabel (t * testing.T ) {
3314
+ t .Parallel ()
3315
+ ctx := user .InjectOrgID (context .Background (), "pushEmptyLabel" )
3316
+ type testcase struct {
3317
+ name string
3318
+ inputSeries []labels.Labels
3319
+ expectedSeries labels.Labels
3320
+ }
3321
+
3322
+ cases := []testcase {
3323
+ {
3324
+ name : "with empty label" ,
3325
+ inputSeries : []labels.Labels {
3326
+ { //Token 1106054332 without filtering
3327
+ {Name : "__name__" , Value : "foo" },
3328
+ {Name : "empty" , Value : "" },
3329
+ },
3330
+ { //Token 3827924124 without filtering
3331
+ {Name : "__name__" , Value : "foo" },
3332
+ {Name : "changHash" , Value : "" },
3333
+ },
3334
+ },
3335
+ expectedSeries : labels.Labels {
3336
+ //Token 1797290973
3337
+ {Name : "__name__" , Value : "foo" },
3338
+ },
3339
+ },
3340
+ }
3341
+
3342
+ for _ , tc := range cases {
3343
+ tc := tc
3344
+ t .Run (tc .name , func (t * testing.T ) {
3345
+ t .Parallel ()
3346
+ var err error
3347
+ var limits validation.Limits
3348
+ flagext .DefaultValues (& limits )
3349
+
3350
+ token := [][]uint32 {
3351
+ {1 },
3352
+ {2 },
3353
+ {3 },
3354
+ {1106054333 },
3355
+ {5 },
3356
+ {6 },
3357
+ {7 },
3358
+ {8 },
3359
+ {9 },
3360
+ {3827924125 },
3361
+ }
3362
+
3363
+ ds , ingesters , _ , _ := prepare (t , prepConfig {
3364
+ numIngesters : 10 ,
3365
+ happyIngesters : 10 ,
3366
+ numDistributors : 1 ,
3367
+ shardByAllLabels : true ,
3368
+ limits : & limits ,
3369
+ replicationFactor : 1 ,
3370
+ shuffleShardSize : 10 ,
3371
+ tokens : token ,
3372
+ })
3373
+
3374
+ // Push the series to the distributor
3375
+ req := mockWriteRequest (tc .inputSeries , 1 , 1 )
3376
+ _ , err = ds [0 ].Push (ctx , req )
3377
+ require .NoError (t , err )
3378
+
3379
+ // Since each test pushes only 1 series, we do expect the ingester
3380
+ // to have received exactly 1 series
3381
+ ingesterWithSeries := 0
3382
+ for i := range ingesters {
3383
+ timeseries := ingesters [i ].series ()
3384
+ if len (timeseries ) > 0 {
3385
+ ingesterWithSeries ++
3386
+ }
3387
+ }
3388
+ assert .Equal (t , 1 , ingesterWithSeries )
3389
+ })
3390
+ }
3391
+ }
3392
+
3306
3393
func TestDistributor_Push_RelabelDropWillExportMetricOfDroppedSamples (t * testing.T ) {
3307
3394
t .Parallel ()
3308
3395
metricRelabelConfigs := []* relabel.Config {
0 commit comments