MCPcopy Index your code
hub / github.com/cortexproject/cortex / wrapWithMiddleware

Function wrapWithMiddleware

pkg/ruler/compat.go:222–247  ·  view source on GitHub ↗
(next QueryExecutor, overrides RulesLimits, userID string, lookbackDelta time.Duration)

Source from the content-addressed store, hash-verified

220}
221
222func wrapWithMiddleware(next QueryExecutor, overrides RulesLimits, userID string, lookbackDelta time.Duration) rules.QueryFunc {
223 return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
224 // Enforce the max query length.
225 maxQueryLength := overrides.MaxQueryLength(userID)
226 if maxQueryLength > 0 {
227 expr, err := cortexparser.ParseExpr(qs)
228 // If failed to parse expression, skip checking select range.
229 // Fail the query in the engine.
230 if err == nil {
231 // Enforce query length across all selectors in the query.
232 length := promql_util.FindNonOverlapQueryLength(expr, 0, 0, lookbackDelta)
233 if length > maxQueryLength {
234 return nil, validation.LimitError(fmt.Sprintf(validation.ErrQueryTooLong, length, maxQueryLength))
235 }
236 }
237 }
238
239 // Add request ID to the context so that it can be used in logs and metrics for split queries.
240 if requestmeta.RequestIdFromContext(ctx) == "" {
241 ctx = requestmeta.ContextWithRequestId(ctx, uuid.NewString())
242 }
243 ctx = requestmeta.ContextWithRequestSource(ctx, requestmeta.SourceRuler)
244
245 return next(ctx, qs, t)
246 }
247}
248
249func metricsQueryFunc(qf rules.QueryFunc, queries, failedQueries prometheus.Counter) rules.QueryFunc {
250 return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {

Callers 1

engineQueryFuncFunction · 0.85

Calls 5

LimitErrorTypeAlias · 0.92
RequestIdFromContextFunction · 0.92
ContextWithRequestIdFunction · 0.92
ContextWithRequestSourceFunction · 0.92
MaxQueryLengthMethod · 0.65

Tested by

no test coverage detected