diff --git a/pkg/querier/tripperware/instantquery/limits.go b/pkg/querier/tripperware/instantquery/limits.go index ec84ad9b29..d782866148 100644 --- a/pkg/querier/tripperware/instantquery/limits.go +++ b/pkg/querier/tripperware/instantquery/limits.go @@ -10,6 +10,7 @@ import ( "github.com/cortexproject/cortex/pkg/querier/tripperware" "github.com/cortexproject/cortex/pkg/tenant" + "github.com/cortexproject/cortex/pkg/util/promql" "github.com/cortexproject/cortex/pkg/util/spanlogger" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -50,7 +51,7 @@ func (l limitsMiddleware) Do(ctx context.Context, r tripperware.Request) (trippe } // Enforce query length across all selectors in the query. - length := tripperware.FindNonOverlapQueryLength(expr, 0, 0, l.lookbackDelta) + length := promql.FindNonOverlapQueryLength(expr, 0, 0, l.lookbackDelta) if length > maxQueryLength { return nil, httpgrpc.Errorf(http.StatusBadRequest, validation.ErrQueryTooLong, length, maxQueryLength) } diff --git a/pkg/querier/tripperware/queryrange/limits.go b/pkg/querier/tripperware/queryrange/limits.go index bccebc4d5a..a4d991aba8 100644 --- a/pkg/querier/tripperware/queryrange/limits.go +++ b/pkg/querier/tripperware/queryrange/limits.go @@ -13,6 +13,7 @@ import ( "github.com/cortexproject/cortex/pkg/querier/tripperware" "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" + "github.com/cortexproject/cortex/pkg/util/promql" "github.com/cortexproject/cortex/pkg/util/spanlogger" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -87,7 +88,7 @@ func (l limitsMiddleware) Do(ctx context.Context, r tripperware.Request) (trippe } // Enforce query length across all selectors in the query. - length := tripperware.FindNonOverlapQueryLength(expr, 0, 0, l.lookbackDelta) + length := promql.FindNonOverlapQueryLength(expr, 0, 0, l.lookbackDelta) if length > maxQueryLength { return nil, httpgrpc.Errorf(http.StatusBadRequest, validation.ErrQueryTooLong, length, maxQueryLength) } diff --git a/pkg/ruler/compat.go b/pkg/ruler/compat.go index 4a02540ef6..dfb7054669 100644 --- a/pkg/ruler/compat.go +++ b/pkg/ruler/compat.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/prometheus/prometheus/promql" "time" "github.com/go-kit/log" @@ -15,7 +16,6 @@ import ( "github.com/prometheus/prometheus/model/metadata" "github.com/prometheus/prometheus/model/value" "github.com/prometheus/prometheus/notifier" - "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/storage" @@ -25,8 +25,8 @@ import ( "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/querier" "github.com/cortexproject/cortex/pkg/querier/stats" - "github.com/cortexproject/cortex/pkg/util" util_log "github.com/cortexproject/cortex/pkg/util/log" + promql_util "github.com/cortexproject/cortex/pkg/util/promql" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -167,10 +167,9 @@ func EngineQueryFunc(engine promql.QueryEngine, q storage.Queryable, overrides R // Fail the query in the engine. if err == nil { // Enforce query length across all selectors in the query. - min, max := promql.FindMinMaxTime(&parser.EvalStmt{Expr: expr, Start: util.TimeFromMillis(0), End: util.TimeFromMillis(0), LookbackDelta: lookbackDelta}) - diff := util.TimeFromMillis(max).Sub(util.TimeFromMillis(min)) - if diff > maxQueryLength { - return nil, validation.LimitError(fmt.Sprintf(validation.ErrQueryTooLong, diff, maxQueryLength)) + length := promql_util.FindNonOverlapQueryLength(expr, 0, 0, lookbackDelta) + if length > maxQueryLength { + return nil, validation.LimitError(fmt.Sprintf(validation.ErrQueryTooLong, length, maxQueryLength)) } } } diff --git a/pkg/querier/tripperware/promql.go b/pkg/util/promql/promql.go similarity index 99% rename from pkg/querier/tripperware/promql.go rename to pkg/util/promql/promql.go index 3447a24078..a0d3f81883 100644 --- a/pkg/querier/tripperware/promql.go +++ b/pkg/util/promql/promql.go @@ -1,4 +1,4 @@ -package tripperware +package promql import ( "math" diff --git a/pkg/querier/tripperware/promql_test.go b/pkg/util/promql/promql_test.go similarity index 99% rename from pkg/querier/tripperware/promql_test.go rename to pkg/util/promql/promql_test.go index 8f65f77fdb..ed35b89c2e 100644 --- a/pkg/querier/tripperware/promql_test.go +++ b/pkg/util/promql/promql_test.go @@ -1,4 +1,4 @@ -package tripperware +package promql import ( "testing"