@@ -308,7 +308,7 @@ func TestStatsCacheQuerySamples(t *testing.T) {
308
308
rcm , _ , err := NewResultsCacheMiddleware (
309
309
log .NewNopLogger (),
310
310
cfg ,
311
- constSplitter (day ),
311
+ splitter (day ),
312
312
mockLimits {},
313
313
PrometheusCodec ,
314
314
PrometheusResponseExtractor {},
@@ -1258,7 +1258,7 @@ func TestResultsCache(t *testing.T) {
1258
1258
rcm , _ , err := NewResultsCacheMiddleware (
1259
1259
log .NewNopLogger (),
1260
1260
cfg ,
1261
- constSplitter (day ),
1261
+ splitter (day ),
1262
1262
mockLimits {},
1263
1263
PrometheusCodec ,
1264
1264
PrometheusResponseExtractor {},
@@ -1299,7 +1299,7 @@ func TestResultsCacheRecent(t *testing.T) {
1299
1299
rcm , _ , err := NewResultsCacheMiddleware (
1300
1300
log .NewNopLogger (),
1301
1301
cfg ,
1302
- constSplitter (day ),
1302
+ splitter (day ),
1303
1303
mockLimits {maxCacheFreshness : 10 * time .Minute },
1304
1304
PrometheusCodec ,
1305
1305
PrometheusResponseExtractor {},
@@ -1364,7 +1364,7 @@ func TestResultsCacheMaxFreshness(t *testing.T) {
1364
1364
rcm , _ , err := NewResultsCacheMiddleware (
1365
1365
log .NewNopLogger (),
1366
1366
cfg ,
1367
- constSplitter (day ),
1367
+ splitter (day ),
1368
1368
fakeLimits ,
1369
1369
PrometheusCodec ,
1370
1370
PrometheusResponseExtractor {},
@@ -1381,7 +1381,7 @@ func TestResultsCacheMaxFreshness(t *testing.T) {
1381
1381
req := parsedRequest .WithStartEnd (int64 (modelNow )- (50 * 1e3 ), int64 (modelNow )- (10 * 1e3 ))
1382
1382
1383
1383
// fill cache
1384
- key := constSplitter (day ).GenerateCacheKey ("1" , req )
1384
+ key := splitter (day ).GenerateCacheKey (ctx , "1" , req )
1385
1385
rc .(* resultsCache ).put (ctx , key , []tripperware.Extent {mkExtent (int64 (modelNow )- (600 * 1e3 ), int64 (modelNow ))})
1386
1386
1387
1387
resp , err := rc .Do (ctx , req )
@@ -1401,7 +1401,7 @@ func Test_resultsCache_MissingData(t *testing.T) {
1401
1401
rm , _ , err := NewResultsCacheMiddleware (
1402
1402
log .NewNopLogger (),
1403
1403
cfg ,
1404
- constSplitter (day ),
1404
+ splitter (day ),
1405
1405
mockLimits {},
1406
1406
PrometheusCodec ,
1407
1407
PrometheusResponseExtractor {},
@@ -1438,7 +1438,7 @@ func Test_resultsCache_MissingData(t *testing.T) {
1438
1438
require .False (t , hit )
1439
1439
}
1440
1440
1441
- func TestConstSplitter_generateCacheKey (t * testing.T ) {
1441
+ func TestSplitter_generateCacheKey (t * testing.T ) {
1442
1442
t .Parallel ()
1443
1443
1444
1444
tests := []struct {
@@ -1460,7 +1460,10 @@ func TestConstSplitter_generateCacheKey(t *testing.T) {
1460
1460
tt := tt
1461
1461
t .Run (fmt .Sprintf ("%s - %s" , tt .name , tt .interval ), func (t * testing.T ) {
1462
1462
t .Parallel ()
1463
- if got := constSplitter (tt .interval ).GenerateCacheKey ("fake" , tt .r ); got != tt .want {
1463
+ ctx := user .InjectOrgID (context .Background (), "1" )
1464
+ got := splitter (tt .interval ).GenerateCacheKey (ctx , "fake" , tt .r )
1465
+
1466
+ if got != tt .want {
1464
1467
t .Errorf ("generateKey() = %v, want %v" , got , tt .want )
1465
1468
}
1466
1469
})
@@ -1513,7 +1516,7 @@ func TestResultsCacheShouldCacheFunc(t *testing.T) {
1513
1516
rcm , _ , err := NewResultsCacheMiddleware (
1514
1517
log .NewNopLogger (),
1515
1518
cfg ,
1516
- constSplitter (day ),
1519
+ splitter (day ),
1517
1520
mockLimits {maxCacheFreshness : 10 * time .Minute },
1518
1521
PrometheusCodec ,
1519
1522
PrometheusResponseExtractor {},
@@ -1545,7 +1548,7 @@ func TestResultsCacheFillCompatibility(t *testing.T) {
1545
1548
rcm , _ , err := NewResultsCacheMiddleware (
1546
1549
log .NewNopLogger (),
1547
1550
cfg ,
1548
- constSplitter (day ),
1551
+ splitter (day ),
1549
1552
mockLimits {maxCacheFreshness : 10 * time .Minute },
1550
1553
PrometheusCodec ,
1551
1554
PrometheusResponseExtractor {},
@@ -1563,7 +1566,9 @@ func TestResultsCacheFillCompatibility(t *testing.T) {
1563
1566
// Check cache and make sure we write response in old format even though the response is new format.
1564
1567
tenantIDs , err := tenant .TenantIDs (ctx )
1565
1568
require .NoError (t , err )
1566
- cacheKey := cache .HashKey (constSplitter (day ).GenerateCacheKey (tenant .JoinTenantIDs (tenantIDs ), parsedRequest ))
1569
+ key := splitter (day ).GenerateCacheKey (ctx , tenant .JoinTenantIDs (tenantIDs ), parsedRequest )
1570
+
1571
+ cacheKey := cache .HashKey (key )
1567
1572
found , bufs , _ := c .Fetch (ctx , []string {cacheKey })
1568
1573
require .Equal (t , []string {cacheKey }, found )
1569
1574
require .Len (t , bufs , 1 )
0 commit comments