parseThresholdExpression parses a threshold condition expression, as defined in a JS script (for instance p(95)<1000), into a thresholdExpression instance. It is expected to be of the form: `aggregation_method operator value`. As defined by the following BNF: ``` assertion -> aggregation_
(input string)
| 70 | // whitespace -> " " |
| 71 | // ``` |
| 72 | func parseThresholdExpression(input string) (*thresholdExpression, error) { |
| 73 | // Scanning makes no assumption on the underlying values, and only |
| 74 | // checks that the expression has the right format. |
| 75 | method, operator, value, err := scanThresholdExpression(input) |
| 76 | if err != nil { |
| 77 | return nil, fmt.Errorf("failed parsing threshold expression %q; reason: %w", input, err) |
| 78 | } |
| 79 | |
| 80 | parsedMethod, parsedMethodValue, err := parseThresholdAggregationMethod(method) |
| 81 | if err != nil { |
| 82 | err = fmt.Errorf("failed parsing threshold expression's %q left hand side; "+ |
| 83 | "reason: %w", input, err, |
| 84 | ) |
| 85 | return nil, err |
| 86 | } |
| 87 | |
| 88 | parsedValue, err := strconv.ParseFloat(value, 64) |
| 89 | if err != nil { |
| 90 | err = fmt.Errorf("failed parsing threshold expresion's %q right hand side; "+ |
| 91 | "reason: %w", input, err, |
| 92 | ) |
| 93 | return nil, err |
| 94 | } |
| 95 | |
| 96 | condition := &thresholdExpression{ |
| 97 | AggregationMethod: parsedMethod, |
| 98 | AggregationValue: parsedMethodValue, |
| 99 | Operator: operator, |
| 100 | Value: parsedValue, |
| 101 | } |
| 102 | |
| 103 | return condition, nil |
| 104 | } |
| 105 | |
| 106 | // Define accepted threshold expression operators tokens |
| 107 | const ( |
searching dependent graphs…