Skip to content

Fix max query lookback type #3598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [ENHANCEMENT] Ruler: Add `cortex_prometheus_last_evaluation_samples` to expose the number of samples generated by a rule group per tenant. #3582
* [ENHANCEMENT] Memberlist: add status page (/memberlist) with available details about memberlist-based KV store and memberlist cluster. It's also possible to view KV values in Go struct or JSON format, or download for inspection. #3575
* [ENHANCEMENT] Memberlist: client can now keep a size-bounded buffer with sent and received messages and display them in the admin UI (/memberlist) for troubleshooting. #3581
* [BUGFIX] Allow `-querier.max-query-lookback` use `y|w|d` suffix like deprecated `-store.max-look-back-period`. #3598
* [BUGFIX] Query-Frontend: `cortex_query_seconds_total` now return seconds not nanoseconds. #3589

## 1.6.0-rc.0 in progress
Expand Down
12 changes: 6 additions & 6 deletions pkg/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
now := time.Now()

tests := map[string]struct {
maxQueryLookback time.Duration
maxQueryLookback model.Duration
query string
queryStartTime time.Time
queryEndTime time.Time
Expand All @@ -495,7 +495,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
expectedMetadataEndTime time.Time
}{
"should not manipulate time range for a query on short time range and rate time window close to the limit": {
maxQueryLookback: thirtyDays,
maxQueryLookback: model.Duration(thirtyDays),
query: "rate(foo[29d])",
queryStartTime: now.Add(-time.Hour),
queryEndTime: now,
Expand All @@ -505,7 +505,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
expectedMetadataEndTime: now,
},
"should not manipulate a query on large time range close to the limit and short rate time window": {
maxQueryLookback: thirtyDays,
maxQueryLookback: model.Duration(thirtyDays),
query: "rate(foo[1m])",
queryStartTime: now.Add(-thirtyDays).Add(time.Hour),
queryEndTime: now,
Expand All @@ -515,7 +515,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
expectedMetadataEndTime: now,
},
"should manipulate a query on short time range and rate time window over the limit": {
maxQueryLookback: thirtyDays,
maxQueryLookback: model.Duration(thirtyDays),
query: "rate(foo[31d])",
queryStartTime: now.Add(-time.Hour),
queryEndTime: now,
Expand All @@ -525,7 +525,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
expectedMetadataEndTime: now,
},
"should manipulate a query on large time range over the limit and short rate time window": {
maxQueryLookback: thirtyDays,
maxQueryLookback: model.Duration(thirtyDays),
query: "rate(foo[1m])",
queryStartTime: now.Add(-thirtyDays).Add(-100 * time.Hour),
queryEndTime: now,
Expand All @@ -535,7 +535,7 @@ func TestQuerier_ValidateQueryTimeRange_MaxQueryLookback(t *testing.T) {
expectedMetadataEndTime: now,
},
"should skip executing a query outside the allowed time range": {
maxQueryLookback: thirtyDays,
maxQueryLookback: model.Duration(thirtyDays),
query: "rate(foo[1m])",
queryStartTime: now.Add(-thirtyDays).Add(-100 * time.Hour),
queryEndTime: now.Add(-thirtyDays).Add(-90 * time.Hour),
Expand Down
19 changes: 10 additions & 9 deletions pkg/util/validation/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"time"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/relabel"

"github.com/cortexproject/cortex/pkg/util/flagext"
Expand Down Expand Up @@ -66,13 +67,13 @@ type Limits struct {
MaxGlobalMetadataPerMetric int `yaml:"max_global_metadata_per_metric"`

// Querier enforced limits.
MaxChunksPerQuery int `yaml:"max_chunks_per_query"`
MaxQueryLookback time.Duration `yaml:"max_query_lookback"`
MaxQueryLength time.Duration `yaml:"max_query_length"`
MaxQueryParallelism int `yaml:"max_query_parallelism"`
CardinalityLimit int `yaml:"cardinality_limit"`
MaxCacheFreshness time.Duration `yaml:"max_cache_freshness"`
MaxQueriersPerTenant int `yaml:"max_queriers_per_tenant"`
MaxChunksPerQuery int `yaml:"max_chunks_per_query"`
MaxQueryLookback model.Duration `yaml:"max_query_lookback"`
MaxQueryLength time.Duration `yaml:"max_query_length"`
MaxQueryParallelism int `yaml:"max_query_parallelism"`
CardinalityLimit int `yaml:"cardinality_limit"`
MaxCacheFreshness time.Duration `yaml:"max_cache_freshness"`
MaxQueriersPerTenant int `yaml:"max_queriers_per_tenant"`

// Ruler defaults and limits.
RulerEvaluationDelay time.Duration `yaml:"ruler_evaluation_delay_duration"`
Expand Down Expand Up @@ -123,7 +124,7 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {

f.IntVar(&l.MaxChunksPerQuery, "store.query-chunk-limit", 2e6, "Maximum number of chunks that can be fetched in a single query. This limit is enforced when fetching chunks from the long-term storage. When running the Cortex chunks storage, this limit is enforced in the querier, while when running the Cortex blocks storage this limit is both enforced in the querier and store-gateway. 0 to disable.")
f.DurationVar(&l.MaxQueryLength, "store.max-query-length", 0, "Limit the query time range (end - start time). This limit is enforced in the query-frontend (on the received query), in the querier (on the query possibly split by the query-frontend) and in the chunks storage. 0 to disable.")
f.DurationVar(&l.MaxQueryLookback, "querier.max-query-lookback", 0, "Limit how long back data (series and metadata) can be queried, up until <lookback> duration ago. This limit is enforced in the query-frontend, querier and ruler. If the requested time range is outside the allowed range, the request will not fail but will be manipulated to only query data within the allowed time range. 0 to disable.")
f.Var(&l.MaxQueryLookback, "querier.max-query-lookback", "Limit how long back data (series and metadata) can be queried, up until <lookback> duration ago. This limit is enforced in the query-frontend, querier and ruler. If the requested time range is outside the allowed range, the request will not fail but will be manipulated to only query data within the allowed time range. 0 to disable.")
f.IntVar(&l.MaxQueryParallelism, "querier.max-query-parallelism", 14, "Maximum number of split queries will be scheduled in parallel by the frontend.")
f.IntVar(&l.CardinalityLimit, "store.cardinality-limit", 1e5, "Cardinality limit for index queries. This limit is ignored when running the Cortex blocks storage. 0 to disable.")
f.DurationVar(&l.MaxCacheFreshness, "frontend.max-cache-freshness", 1*time.Minute, "Most recent allowed cacheable result per-tenant, to prevent caching very recent results that might still be in flux.")
Expand Down Expand Up @@ -312,7 +313,7 @@ func (o *Overrides) MaxChunksPerQuery(userID string) int {

// MaxQueryLookback returns the max lookback period of queries.
func (o *Overrides) MaxQueryLookback(userID string) time.Duration {
return o.getOverridesForUser(userID).MaxQueryLookback
return time.Duration(o.getOverridesForUser(userID).MaxQueryLookback)
}

// MaxQueryLength returns the limit of the length (in time) of a query.
Expand Down