@@ -5523,6 +5523,88 @@ func TestExpendedPostingsCacheIsolation(t *testing.T) {
5523
5523
wg .Wait ()
5524
5524
}
5525
5525
5526
+ func TestExpendedPostingsCacheGlobalLimit (t * testing.T ) {
5527
+ cfg := defaultIngesterTestConfig (t )
5528
+ maxBytes := int64 (1024 )
5529
+ users := []string {"test1" , "test2" }
5530
+ cfg .BlocksStorageConfig .TSDB .BlockRanges = []time.Duration {2 * time .Hour }
5531
+ cfg .BlocksStorageConfig .TSDB .PostingsCache = cortex_tsdb.TSDBPostingsCacheConfig {
5532
+ Blocks : cortex_tsdb.PostingsCacheConfig {
5533
+ Ttl : time .Hour ,
5534
+ MaxBytes : maxBytes ,
5535
+ Enabled : true ,
5536
+ },
5537
+ Head : cortex_tsdb.PostingsCacheConfig {
5538
+ Ttl : time .Hour ,
5539
+ MaxBytes : maxBytes ,
5540
+ Enabled : true ,
5541
+ },
5542
+ }
5543
+
5544
+ cfg .LifecyclerConfig .JoinAfter = 0
5545
+
5546
+ r := prometheus .NewRegistry ()
5547
+ i , err := prepareIngesterWithBlocksStorage (t , cfg , r )
5548
+ require .NoError (t , err )
5549
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), i ))
5550
+ defer services .StopAndAwaitTerminated (context .Background (), i ) //nolint:errcheck
5551
+
5552
+ metricNames := []string {"metric1" , "metric2" }
5553
+
5554
+ // Generate 4 hours of data so we have 1 block + head
5555
+ totalSamples := 4 * 60
5556
+ var samples = make ([]cortexpb.Sample , 0 , totalSamples )
5557
+
5558
+ for i := 0 ; i < totalSamples ; i ++ {
5559
+ samples = append (samples , cortexpb.Sample {
5560
+ Value : float64 (i ),
5561
+ TimestampMs : int64 (i * 60 * 1000 ),
5562
+ })
5563
+ }
5564
+
5565
+ lbls := make ([]labels.Labels , 0 , len (samples ))
5566
+ for j := 0 ; j < 10 ; j ++ {
5567
+ for i := 0 ; i < len (samples ); i ++ {
5568
+ lbls = append (lbls , labels .FromStrings (labels .MetricName , metricNames [i % len (metricNames )], "a" , fmt .Sprintf ("aaa%v" , j )))
5569
+ }
5570
+ }
5571
+
5572
+ for i := len (samples ); i < len (lbls ); i ++ {
5573
+ samples = append (samples , samples [i % len (samples )])
5574
+ }
5575
+
5576
+ for _ , u := range users {
5577
+ ctx := user .InjectOrgID (context .Background (), u )
5578
+ req := cortexpb .ToWriteRequest (lbls , samples , nil , nil , cortexpb .API )
5579
+ _ , err = i .Push (ctx , req )
5580
+ require .NoError (t , err )
5581
+
5582
+ i .compactBlocks (ctx , false , nil )
5583
+
5584
+ s := & mockQueryStreamServer {ctx : ctx }
5585
+
5586
+ err = i .QueryStream (& client.QueryRequest {
5587
+ StartTimestampMs : 0 ,
5588
+ EndTimestampMs : math .MaxInt64 ,
5589
+ Matchers : []* client.LabelMatcher {
5590
+ {
5591
+ Type : client .EQUAL ,
5592
+ Name : "__name__" ,
5593
+ Value : strings .Repeat ("a" , int (maxBytes / 2 )), // make sure the size it bigger than the max size
5594
+ },
5595
+ },
5596
+ }, s )
5597
+ }
5598
+
5599
+ err = testutil .GatherAndCompare (r , bytes .NewBufferString (`
5600
+ # HELP cortex_ingester_expanded_postings_cache_evicts_total Total number of evictions in the cache, excluding items that got evicted due to TTL.
5601
+ # TYPE cortex_ingester_expanded_postings_cache_evicts_total counter
5602
+ cortex_ingester_expanded_postings_cache_evicts_total{cache="block",reason="full"} 1
5603
+ cortex_ingester_expanded_postings_cache_evicts_total{cache="head",reason="full"} 1
5604
+ ` ), "cortex_ingester_expanded_postings_cache_evicts_total" )
5605
+ require .NoError (t , err )
5606
+ }
5607
+
5526
5608
func TestExpendedPostingsCache (t * testing.T ) {
5527
5609
cfg := defaultIngesterTestConfig (t )
5528
5610
cfg .BlocksStorageConfig .TSDB .BlockRanges = []time.Duration {2 * time .Hour }
0 commit comments