{"record":{"id":"6931b5399af4599f","repo":"grafana/k6","slug":"invalid-threshold","errorCode":null,"errorMessage":"invalid threshold","messagePattern":"invalid threshold","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/thresholds.go","lineNumber":236,"sourceCode":"}\n\n// Parse parses the Thresholds and fills each Threshold.parsed field with the result.\n// It effectively asserts they are syntaxically correct.\nfunc (ts *Thresholds) Parse() error {\n\tfor _, t := range ts.Thresholds {\n\t\tparsed, err := parseThresholdExpression(t.Source)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tt.parsed = parsed\n\t}\n\n\treturn nil\n}\n\n// ErrInvalidThreshold indicates a threshold is not valid\nvar ErrInvalidThreshold = errors.New(\"invalid threshold\")\n\n// Validate ensures a threshold definition is consistent with the metric it applies to.\n// Given a metric registry and a metric name to apply the expressions too, Validate will\n// assert that each threshold expression uses an aggregation method that's supported by the\n// provided metric. It returns an error otherwise.\n// Note that this function expects the passed in thresholds to have been parsed already, and\n// have their Parsed (ThresholdExpression) field already filled.\nfunc (ts *Thresholds) Validate(metricName string, r *Registry) error {\n\tparsedMetricName, _, err := ParseMetricName(metricName)\n\tif err != nil {\n\t\tparseErr := fmt.Errorf(\"unable to validate threshold expressions; reason: %w\", err)\n\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)","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/thresholds.go#L218-L254","documentation":"Sentinel error (ErrInvalidThreshold) from Thresholds.Validate: a threshold definition is inconsistent with its metric — either the metric name does not exist in the registry, or the threshold's aggregation method is unsupported for the metric's type. It is stamped with exit code InvalidConfig.","triggerScenarios":"Thrown at metrics/thresholds.go:236 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the metric name in the threshold exists (watch for typos or missing submetric tags)","Use an aggregation method supported by the metric type, e.g. rate/count only on counters, avg/max/p on trends","Ensure custom metrics are declared before thresholds reference them"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}