@@ -278,7 +278,7 @@ func TestMetaFetcher_Fetch(t *testing.T) {
278
278
})
279
279
}
280
280
281
- func TestLabelShardedMetaFilter_Filter (t * testing.T ) {
281
+ func TestLabelShardedMetaFilter_Filter_Basic (t * testing.T ) {
282
282
relabelContentYaml := `
283
283
- action: drop
284
284
regex: "A"
@@ -340,6 +340,72 @@ func TestLabelShardedMetaFilter_Filter(t *testing.T) {
340
340
341
341
}
342
342
343
+ func TestLabelShardedMetaFilter_Filter_Hashmod (t * testing.T ) {
344
+ relabelContentYamlFmt := `
345
+ - action: hashmod
346
+ source_labels: ["ff%s"]
347
+ target_label: shard
348
+ modulus: 3
349
+ - action: keep
350
+ source_labels: ["shard"]
351
+ regex: %d
352
+ `
353
+ for i := 0 ; i < 3 ; i ++ {
354
+ t .Run (fmt .Sprintf ("%v" , i ), func (t * testing.T ) {
355
+ var relabelConfig []* relabel.Config
356
+ testutil .Ok (t , yaml .Unmarshal ([]byte (fmt .Sprintf (relabelContentYamlFmt , blockIDLabel , i )), & relabelConfig ))
357
+
358
+ f := NewLabelShardedMetaFilter (relabelConfig )
359
+
360
+ input := map [ulid.ULID ]* metadata.Meta {
361
+ ULID (1 ): {
362
+ Thanos : metadata.Thanos {
363
+ Labels : map [string ]string {"cluster" : "B" , "message" : "keepme" },
364
+ },
365
+ },
366
+ ULID (2 ): {
367
+ Thanos : metadata.Thanos {
368
+ Labels : map [string ]string {"something" : "A" , "message" : "keepme" },
369
+ },
370
+ },
371
+ ULID (3 ): {
372
+ Thanos : metadata.Thanos {
373
+ Labels : map [string ]string {"cluster" : "A" , "message" : "keepme" },
374
+ },
375
+ },
376
+ ULID (4 ): {
377
+ Thanos : metadata.Thanos {
378
+ Labels : map [string ]string {"cluster" : "A" , "something" : "B" , "message" : "keepme" },
379
+ },
380
+ },
381
+ ULID (5 ): {
382
+ Thanos : metadata.Thanos {
383
+ Labels : map [string ]string {"cluster" : "B" },
384
+ },
385
+ },
386
+ ULID (6 ): {
387
+ Thanos : metadata.Thanos {
388
+ Labels : map [string ]string {"cluster" : "B" , "message" : "keepme" },
389
+ },
390
+ },
391
+ ULID (7 ): {},
392
+ ULID (8 ): {}, ULID (8 ): {},
393
+ ULID (9 ): {},
394
+ }
395
+ expected := map [ulid.ULID ]* metadata.Meta {
396
+ // ?
397
+ }
398
+
399
+ synced := prometheus .NewGaugeVec (prometheus.GaugeOpts {}, []string {"state" })
400
+ f .Filter (input , synced , false )
401
+
402
+ testutil .Equals (t , 3.0 , promtest .ToFloat64 (synced .WithLabelValues (labelExcludedMeta )))
403
+ testutil .Equals (t , expected , input )
404
+ })
405
+
406
+ }
407
+ }
408
+
343
409
func TestTimePartitionMetaFilter_Filter (t * testing.T ) {
344
410
mint := time .Unix (0 , 1 * time .Millisecond .Nanoseconds ())
345
411
maxt := time .Unix (0 , 10 * time .Millisecond .Nanoseconds ())
0 commit comments