@@ -16,7 +16,6 @@ import (
1616
1717 v2 "github.com/grafana/loki/v3/pkg/iter/v2"
1818 "github.com/grafana/loki/v3/pkg/logproto"
19- "github.com/grafana/loki/v3/pkg/storage/chunk"
2019 "github.com/grafana/loki/v3/pkg/storage/config"
2120 "github.com/grafana/loki/v3/pkg/storage/stores/series/index"
2221 tsdb_index "github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb/index"
@@ -426,135 +425,47 @@ func TestRefWithSizingInfo(t *testing.T) {
426425// TODO(owen-d): more testing for specific cases
427426func TestAccumulateChunksToShards (t * testing.T ) {
428427 // only check eq by checksum for convenience -- we're not testing the comparison function here
429- mkRef := func (fp model.Fingerprint , checksum uint32 ) * logproto.ChunkRef {
430- return & logproto.ChunkRef {
428+ mkRef := func (fp model.Fingerprint , checksum uint32 ) logproto.ChunkRef {
429+ return logproto.ChunkRef {
431430 Fingerprint : uint64 (fp ),
432431 Checksum : checksum ,
433432 }
434433 }
435434
436- sized := func (ref * logproto.ChunkRef , kb , entries uint32 ) refWithSizingInfo {
437- return refWithSizingInfo {
438- ref : ref ,
439- KB : kb ,
440- Entries : entries ,
435+ sized := func (ref logproto.ChunkRef , kb , entries uint32 ) logproto. ChunkRefWithSizingInfo {
436+ return logproto. ChunkRefWithSizingInfo {
437+ ChunkRef : ref ,
438+ KB : kb ,
439+ Entries : entries ,
441440 }
442441
443442 }
444443
445- fsImpl := func (series [][]refWithSizingInfo ) sharding.ForSeriesFunc {
446- return sharding .ForSeriesFunc (
447- func (
448- _ context.Context ,
449- _ string ,
450- _ tsdb_index.FingerprintFilter ,
451- _ , _ model.Time ,
452- fn func (
453- _ labels.Labels ,
454- fp model.Fingerprint ,
455- chks []tsdb_index.ChunkMeta ,
456- ) (stop bool ), _ ... * labels.Matcher ) error {
457-
458- for _ , s := range series {
459- chks := []tsdb_index.ChunkMeta {}
460- for _ , r := range s {
461- chks = append (chks , tsdb_index.ChunkMeta {
462- Checksum : r .ref .Checksum ,
463- KB : r .KB ,
464- Entries : r .Entries ,
465- })
466- }
467-
468- if stop := fn (labels .EmptyLabels (), s [0 ].ref .FingerprintModel (), chks ); stop {
469- return nil
470- }
471- }
472- return nil
473- },
474- )
475- }
476-
477- filtered := []* logproto.ChunkRef {
444+ filtered := []logproto.ChunkRefWithSizingInfo {
478445 // shard 0
479- mkRef (1 , 0 ),
480- mkRef (1 , 1 ),
481- mkRef (1 , 2 ),
446+ sized ( mkRef (1 , 0 ), 100 , 1 ),
447+ sized ( mkRef (1 , 1 ), 100 , 1 ),
448+ sized ( mkRef (1 , 2 ), 100 , 1 ),
482449
483450 // shard 1
484- mkRef (2 , 10 ),
485- mkRef (2 , 20 ),
486- mkRef (2 , 30 ),
451+ sized ( mkRef (2 , 10 ), 100 , 1 ),
452+ sized ( mkRef (2 , 20 ), 100 , 1 ),
453+ sized ( mkRef (2 , 30 ), 100 , 1 ),
487454
488455 // shard 2 split across multiple series
489- mkRef (3 , 10 ),
490- mkRef (4 , 10 ),
491- mkRef (4 , 20 ),
456+ sized ( mkRef (3 , 10 ), 50 , 1 ),
457+ sized ( mkRef (4 , 10 ), 30 , 1 ),
458+ sized ( mkRef (4 , 20 ), 30 , 1 ),
492459
493460 // last shard contains leftovers + skip a few fps in between
494- mkRef (7 , 10 ),
461+ sized ( mkRef (7 , 10 ), 25 , 1 ),
495462 }
496463
497- series := [][]refWithSizingInfo {
498- {
499- // first series creates one shard since a shard can't contain partial series.
500- // no chunks were filtered out
501- sized (mkRef (1 , 0 ), 100 , 1 ),
502- sized (mkRef (1 , 1 ), 100 , 1 ),
503- sized (mkRef (1 , 2 ), 100 , 1 ),
504- },
505- {
506- // second shard also contains one series, but this series has chunks filtered out.
507- sized (mkRef (2 , 0 ), 100 , 1 ), // filtered out
508- sized (mkRef (2 , 10 ), 100 , 1 ), // included
509- sized (mkRef (2 , 11 ), 100 , 1 ), // filtered out
510- sized (mkRef (2 , 20 ), 100 , 1 ), // included
511- sized (mkRef (2 , 21 ), 100 , 1 ), // filtered out
512- sized (mkRef (2 , 30 ), 100 , 1 ), // included
513- sized (mkRef (2 , 31 ), 100 , 1 ), // filtered out
514- },
515-
516- // third shard contains multiple series.
517- // combined they have 110kb, which is above the target of 100kb
518- // but closer than leaving the second series out which would create
519- // a shard with 50kb
520- {
521- // first series, 50kb
522- sized (mkRef (3 , 10 ), 50 , 1 ), // 50kb
523- sized (mkRef (3 , 11 ), 50 , 1 ), // 50kb, not included
524- },
525- {
526- // second series
527- sized (mkRef (4 , 10 ), 30 , 1 ), // 30kb
528- sized (mkRef (4 , 11 ), 30 , 1 ), // 30kb, not included
529- sized (mkRef (4 , 20 ), 30 , 1 ), // 30kb
530- },
531-
532- // Fourth shard contains a single series with 25kb,
533- // but iterates over non-included fp(s) before it
534- {
535- // register a series in the index which is not included in the filtered list
536- sized (mkRef (6 , 10 ), 100 , 1 ), // not included
537- sized (mkRef (6 , 11 ), 100 , 1 ), // not included
538- },
539- {
540- // last shard contains leftovers
541- sized (mkRef (7 , 10 ), 25 , 1 ),
542- sized (mkRef (7 , 11 ), 100 , 1 ), // not included
543- },
544- }
545-
546- shards , grps , err := accumulateChunksToShards (
547- context .Background (),
548- "" ,
549- fsImpl (series ),
550- & logproto.ShardsRequest {
551- TargetBytesPerShard : 100 << 10 ,
552- },
553- chunk .NewPredicate (nil , nil ), // we're not checking matcher injection here
554- filtered ,
555- )
464+ shards , grps , err := accumulateChunksToShards (& logproto.ShardsRequest {
465+ TargetBytesPerShard : 100 << 10 ,
466+ }, filtered )
556467
557- expectedChks := [][]* logproto.ChunkRef {
468+ expectedChks := [][]logproto.ChunkRefWithSizingInfo {
558469 filtered [0 :3 ],
559470 filtered [3 :6 ],
560471 filtered [6 :9 ],
@@ -604,7 +515,7 @@ func TestAccumulateChunksToShards(t *testing.T) {
604515 for i := range shards {
605516 require .Equal (t , exp [i ], shards [i ], "invalid shard at index %d" , i )
606517 for j := range grps [i ].Refs {
607- require .Equal (t , expectedChks [i ][j ], grps [i ].Refs [j ], "invalid chunk in grp %d at index %d" , i , j )
518+ require .Equal (t , & expectedChks [i ][j ]. ChunkRef , grps [i ].Refs [j ], "invalid chunk in grp %d at index %d" , i , j )
608519 }
609520 }
610521 require .Equal (t , len (exp ), len (shards ))
0 commit comments