SubQueryStepSizeCheck ensures the query doesn't contain too small step size in subqueries.
(query string, defaultSubQueryInterval time.Duration, maxStep int64)
| 20 | |
| 21 | // SubQueryStepSizeCheck ensures the query doesn't contain too small step size in subqueries. |
| 22 | func SubQueryStepSizeCheck(query string, defaultSubQueryInterval time.Duration, maxStep int64) error { |
| 23 | expr, err := cortexparser.ParseExpr(query) |
| 24 | if err != nil { |
| 25 | // If query fails to parse, we don't throw step size error |
| 26 | // but fail query later on querier. |
| 27 | return nil |
| 28 | } |
| 29 | parser.Inspect(expr, func(node parser.Node, nodes []parser.Node) error { |
| 30 | e, ok := node.(*parser.SubqueryExpr) |
| 31 | if !ok { |
| 32 | return nil |
| 33 | } |
| 34 | step := e.Step |
| 35 | if e.Step == 0 { |
| 36 | step = defaultSubQueryInterval |
| 37 | } |
| 38 | |
| 39 | if e.Range/step > time.Duration(maxStep) { |
| 40 | err = httpgrpc.Errorf(http.StatusBadRequest, ErrSubQueryStepTooSmall, maxStep) |
| 41 | } |
| 42 | return err |
| 43 | }) |
| 44 | return err |
| 45 | } |
no outgoing calls