diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f747d7f90..535c61807d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/querier/querier_test.go b/pkg/querier/querier_test.go index 5b7c574659a..9f7887f9076 100644 --- a/pkg/querier/querier_test.go +++ b/pkg/querier/querier_test.go @@ -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 @@ -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, @@ -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, @@ -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, @@ -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, @@ -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), diff --git a/pkg/util/validation/limits.go b/pkg/util/validation/limits.go index 1a99f9d8f16..5179555a454 100644 --- a/pkg/util/validation/limits.go +++ b/pkg/util/validation/limits.go @@ -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" @@ -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"` @@ -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 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 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.") @@ -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.