@@ -308,7 +308,7 @@ func TestStatsCacheQuerySamples(t *testing.T) {
308308 rcm , _ , err := NewResultsCacheMiddleware (
309309 log .NewNopLogger (),
310310 cfg ,
311- constSplitter (day ),
311+ splitter (day ),
312312 mockLimits {},
313313 PrometheusCodec ,
314314 PrometheusResponseExtractor {},
@@ -1258,7 +1258,7 @@ func TestResultsCache(t *testing.T) {
12581258 rcm , _ , err := NewResultsCacheMiddleware (
12591259 log .NewNopLogger (),
12601260 cfg ,
1261- constSplitter (day ),
1261+ splitter (day ),
12621262 mockLimits {},
12631263 PrometheusCodec ,
12641264 PrometheusResponseExtractor {},
@@ -1299,7 +1299,7 @@ func TestResultsCacheRecent(t *testing.T) {
12991299 rcm , _ , err := NewResultsCacheMiddleware (
13001300 log .NewNopLogger (),
13011301 cfg ,
1302- constSplitter (day ),
1302+ splitter (day ),
13031303 mockLimits {maxCacheFreshness : 10 * time .Minute },
13041304 PrometheusCodec ,
13051305 PrometheusResponseExtractor {},
@@ -1364,7 +1364,7 @@ func TestResultsCacheMaxFreshness(t *testing.T) {
13641364 rcm , _ , err := NewResultsCacheMiddleware (
13651365 log .NewNopLogger (),
13661366 cfg ,
1367- constSplitter (day ),
1367+ splitter (day ),
13681368 fakeLimits ,
13691369 PrometheusCodec ,
13701370 PrometheusResponseExtractor {},
@@ -1381,7 +1381,7 @@ func TestResultsCacheMaxFreshness(t *testing.T) {
13811381 req := parsedRequest .WithStartEnd (int64 (modelNow )- (50 * 1e3 ), int64 (modelNow )- (10 * 1e3 ))
13821382
13831383 // fill cache
1384- key := constSplitter (day ).GenerateCacheKey ("1" , req )
1384+ key := splitter (day ).GenerateCacheKey (ctx , "1" , req )
13851385 rc .(* resultsCache ).put (ctx , key , []tripperware.Extent {mkExtent (int64 (modelNow )- (600 * 1e3 ), int64 (modelNow ))})
13861386
13871387 resp , err := rc .Do (ctx , req )
@@ -1401,7 +1401,7 @@ func Test_resultsCache_MissingData(t *testing.T) {
14011401 rm , _ , err := NewResultsCacheMiddleware (
14021402 log .NewNopLogger (),
14031403 cfg ,
1404- constSplitter (day ),
1404+ splitter (day ),
14051405 mockLimits {},
14061406 PrometheusCodec ,
14071407 PrometheusResponseExtractor {},
@@ -1438,7 +1438,7 @@ func Test_resultsCache_MissingData(t *testing.T) {
14381438 require .False (t , hit )
14391439}
14401440
1441- func TestConstSplitter_generateCacheKey (t * testing.T ) {
1441+ func TestSplitter_generateCacheKey (t * testing.T ) {
14421442 t .Parallel ()
14431443
14441444 tests := []struct {
@@ -1460,7 +1460,10 @@ func TestConstSplitter_generateCacheKey(t *testing.T) {
14601460 tt := tt
14611461 t .Run (fmt .Sprintf ("%s - %s" , tt .name , tt .interval ), func (t * testing.T ) {
14621462 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 {
14641467 t .Errorf ("generateKey() = %v, want %v" , got , tt .want )
14651468 }
14661469 })
@@ -1513,7 +1516,7 @@ func TestResultsCacheShouldCacheFunc(t *testing.T) {
15131516 rcm , _ , err := NewResultsCacheMiddleware (
15141517 log .NewNopLogger (),
15151518 cfg ,
1516- constSplitter (day ),
1519+ splitter (day ),
15171520 mockLimits {maxCacheFreshness : 10 * time .Minute },
15181521 PrometheusCodec ,
15191522 PrometheusResponseExtractor {},
@@ -1545,7 +1548,7 @@ func TestResultsCacheFillCompatibility(t *testing.T) {
15451548 rcm , _ , err := NewResultsCacheMiddleware (
15461549 log .NewNopLogger (),
15471550 cfg ,
1548- constSplitter (day ),
1551+ splitter (day ),
15491552 mockLimits {maxCacheFreshness : 10 * time .Minute },
15501553 PrometheusCodec ,
15511554 PrometheusResponseExtractor {},
@@ -1563,7 +1566,9 @@ func TestResultsCacheFillCompatibility(t *testing.T) {
15631566 // Check cache and make sure we write response in old format even though the response is new format.
15641567 tenantIDs , err := tenant .TenantIDs (ctx )
15651568 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 )
15671572 found , bufs , _ := c .Fetch (ctx , []string {cacheKey })
15681573 require .Equal (t , []string {cacheKey }, found )
15691574 require .Len (t , bufs , 1 )
0 commit comments