(ctx context.Context, r tripperware.Request)
| 35 | } |
| 36 | |
| 37 | func (l limitsMiddleware) Do(ctx context.Context, r tripperware.Request) (tripperware.Response, error) { |
| 38 | log, ctx := spanlogger.New(ctx, "limits") |
| 39 | defer log.Finish() |
| 40 | |
| 41 | tenantIDs, err := users.TenantIDs(ctx) |
| 42 | if err != nil { |
| 43 | return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()) |
| 44 | } |
| 45 | |
| 46 | // Enforce the max query length. |
| 47 | if maxQueryLength := validation.SmallestPositiveNonZeroDurationPerTenant(tenantIDs, l.MaxQueryLength); maxQueryLength > 0 { |
| 48 | expr, err := cortexparser.ParseExpr(r.GetQuery()) |
| 49 | if err != nil { |
| 50 | return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error()) |
| 51 | } |
| 52 | |
| 53 | // Enforce query length across all selectors in the query. |
| 54 | length := promql.FindNonOverlapQueryLength(expr, 0, 0, l.lookbackDelta) |
| 55 | if length > maxQueryLength { |
| 56 | return nil, httpgrpc.Errorf(http.StatusBadRequest, validation.ErrQueryTooLong, length, maxQueryLength) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return l.next.Do(ctx, r) |
| 61 | } |
nothing calls this directly
no test coverage detected