-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle auto downsampling in codec (#3073)
* correctly handle auto downsampling in codec Signed-off-by: Ben Ye <yb532204897@gmail.com> * address comments Signed-off-by: Ben Ye <yb532204897@gmail.com>
- Loading branch information
Showing
7 changed files
with
159 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package queryfrontend | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cortexproject/cortex/pkg/querier/queryrange" | ||
|
||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestGenerateCacheKey(t *testing.T) { | ||
splitter := newThanosCacheKeyGenerator(hour) | ||
|
||
for _, tc := range []struct { | ||
name string | ||
req queryrange.Request | ||
expected string | ||
}{ | ||
{ | ||
name: "non thanos req", | ||
req: &queryrange.PrometheusRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 60 * seconds, | ||
}, | ||
expected: "up:60000:0", | ||
}, | ||
{ | ||
name: "non downsampling resolution specified", | ||
req: &ThanosRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 60 * seconds, | ||
}, | ||
expected: "up:60000:0:2", | ||
}, | ||
{ | ||
name: "10s step", | ||
req: &ThanosRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 10 * seconds, | ||
}, | ||
expected: "up:10000:0:2", | ||
}, | ||
{ | ||
name: "1m downsampling resolution", | ||
req: &ThanosRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 10 * seconds, | ||
MaxSourceResolution: 60 * seconds, | ||
}, | ||
expected: "up:10000:0:2", | ||
}, | ||
{ | ||
name: "5m downsampling resolution, different cache key", | ||
req: &ThanosRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 10 * seconds, | ||
MaxSourceResolution: 300 * seconds, | ||
}, | ||
expected: "up:10000:0:1", | ||
}, | ||
{ | ||
name: "1h downsampling resolution, different cache key", | ||
req: &ThanosRequest{ | ||
Query: "up", | ||
Start: 0, | ||
Step: 10 * seconds, | ||
MaxSourceResolution: hour, | ||
}, | ||
expected: "up:10000:0:0", | ||
}, | ||
} { | ||
key := splitter.GenerateCacheKey("", tc.req) | ||
testutil.Equals(t, tc.expected, key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters