{"record":{"id":"bf2edbb3f315cc08","repo":"grafana/k6","slug":"unable-to-validate-threshold-q-on-metric-s-reas","errorCode":null,"errorMessage":"unable to validate threshold %q on metric %s; reason: parsing threshold failed %w","messagePattern":"unable to validate threshold %q on metric (.+?); reason: parsing threshold failed %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/thresholds.go","lineNumber":266,"sourceCode":"\t\treturn errext.WithExitCodeIfNone(parseErr, exitcodes.InvalidConfig)\n\t}\n\n\t// Obtain the metric the thresholds apply to from the registry.\n\t// if the metric doesn't exist, then we return an error indicating\n\t// the InvalidConfig exitcode should be used.\n\tmetric := r.Get(parsedMetricName)\n\tif metric == nil {\n\t\terr := fmt.Errorf(\"%w defined on %s; reason: no metric name %q found\", ErrInvalidThreshold, metricName, metricName)\n\t\treturn errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig)\n\t}\n\n\tfor _, threshold := range ts.Thresholds {\n\t\t// Return a digestable error if we attempt to validate a threshold\n\t\t// that hasn't been parsed yet.\n\t\tif threshold.parsed == nil {\n\t\t\tthresholdExpression, err := parseThresholdExpression(threshold.Source)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to validate threshold %q on metric %s; reason: \"+\n\t\t\t\t\t\"parsing threshold failed %w\", threshold.Source, metricName, err)\n\t\t\t}\n\n\t\t\tthreshold.parsed = thresholdExpression\n\t\t}\n\n\t\t// If the threshold's expression aggregation method is not\n\t\t// supported for the metric we validate against, then we return\n\t\t// an error indicating the InvalidConfig exitcode should be used.\n\t\tif !metric.Type.supportsAggregationMethod(threshold.parsed.AggregationMethod) {\n\t\t\terr := fmt.Errorf(\n\t\t\t\t\"%w %q applied on metric %s; reason: \"+\n\t\t\t\t\t\"unsupported aggregation method %s on metric of type %s. \"+\n\t\t\t\t\t\"supported aggregation methods for this metric are: %s\",\n\t\t\t\tErrInvalidThreshold, threshold.Source, metricName,\n\t\t\t\tthreshold.parsed.AggregationMethod, metric.Type,\n\t\t\t\tstrings.Join(metric.Type.supportedAggregationMethods(), \", \"),\n\t\t\t)","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/thresholds.go#L248-L284","documentation":"Inside Thresholds.Validate, parsing the threshold expression (threshold.parsed via thresholdExpression) failed for the quoted threshold applied to the named metric. The expression string does not conform to the threshold grammar (bad aggregation method, missing/unknown operator, or malformed right-hand-side value).","triggerScenarios":"Thrown at metrics/thresholds.go:266 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the quoted threshold string, e.g. use 'avg<300', 'p(99)<1000', 'count>0', 'rate<0.1'","Ensure the operator is one of > >= <= < == === != and the right side is a plain number","Ensure the aggregation method is valid for the metric type (e.g. no 'avg' on a counter)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}