MCPcopy
hub / github.com/grafana/k6 / parseThresholdExpression

Function parseThresholdExpression

metrics/thresholds_parser.go:72–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

70// whitespace -> " "
71// ```
72func 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
107const (

Callers 5

ParseMethod · 0.85
ValidateMethod · 0.85
TestThresholdRunFunction · 0.85

Calls 3

scanThresholdExpressionFunction · 0.85
ErrorfMethod · 0.80

Tested by 3

TestThresholdRunFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…