Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update ruler logic
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <benye@amazon.com>
yeya24 committed Jun 17, 2024
1 parent cf5d57b commit 78e3303
Showing 5 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/querier/tripperware/instantquery/limits.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 2 additions & 1 deletion pkg/querier/tripperware/queryrange/limits.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 5 additions & 6 deletions pkg/ruler/compat.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tripperware
package promql

import (
"math"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tripperware
package promql

import (
"testing"

0 comments on commit 78e3303

Please sign in to comment.