@@ -365,3 +365,49 @@ func TestIndex_DeleteShard(t *testing.T) {
365
365
assertShard (t , db , p , tenant2 , 1 , true )
366
366
})
367
367
}
368
+
369
+ func TestIndex_GetTenantStats (t * testing.T ) {
370
+ const (
371
+ existingTenant = "tenant"
372
+ )
373
+ var (
374
+ minTime = test .UnixMilli ("2024-09-11T07:00:00.000Z" )
375
+ maxTime = test .UnixMilli ("2024-09-11T09:00:00.000Z" )
376
+ )
377
+
378
+ db := test .BoltDB (t )
379
+ idx := NewIndex (util .Logger , NewStore (), DefaultConfig )
380
+ require .NoError (t , db .Update (idx .Init ))
381
+
382
+ shardID := uint32 (42 )
383
+ blockMeta := & metastorev1.BlockMeta {
384
+ Id : test .ULID ("2024-09-11T07:00:00.001Z" ),
385
+ Tenant : 1 ,
386
+ Shard : shardID ,
387
+ MinTime : minTime ,
388
+ MaxTime : maxTime ,
389
+ CreatedBy : 1 ,
390
+ StringTable : []string {"" , existingTenant , "ingester" },
391
+ }
392
+
393
+ require .NoError (t , db .Update (func (tx * bbolt.Tx ) error {
394
+ return idx .InsertBlock (tx , blockMeta .CloneVT ())
395
+ }))
396
+
397
+ require .NoError (t , db .View (func (tx * bbolt.Tx ) error {
398
+ stats := idx .GetTenantStats (tx , existingTenant )
399
+ assert .Equal (t , true , stats .GetDataIngested ())
400
+ assert .Equal (t , minTime , stats .GetOldestProfileTime ())
401
+ assert .Equal (t , maxTime , stats .GetNewestProfileTime ())
402
+ return nil
403
+ }))
404
+
405
+ require .NoError (t , db .View (func (tx * bbolt.Tx ) error {
406
+ stats := idx .GetTenantStats (tx , "tenant-never-sent" )
407
+ assert .Equal (t , false , stats .GetDataIngested ())
408
+ assert .Equal (t , int64 (0 ), stats .GetOldestProfileTime ())
409
+ assert .Equal (t , int64 (0 ), stats .GetNewestProfileTime ())
410
+ return nil
411
+ }))
412
+
413
+ }
0 commit comments