(next QueryExecutor, overrides RulesLimits, userID string, lookbackDelta time.Duration)
| 220 | } |
| 221 | |
| 222 | func 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 | |
| 249 | func metricsQueryFunc(qf rules.QueryFunc, queries, failedQueries prometheus.Counter) rules.QueryFunc { |
| 250 | return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) { |
no test coverage detected