{"record":{"id":"1aceef2d96b46d95","repo":"grafana/k6","slug":"invalid-metric-s-in-threshold-definitions-w","errorCode":null,"errorMessage":"invalid metric '%s' in threshold definitions: %w","messagePattern":"invalid metric '(.+?)' in threshold definitions: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/metrics/engine/engine.go","lineNumber":130,"sourceCode":"\t}\n}\n\n// InitSubMetricsAndThresholds parses the thresholds from the test Options and\n// initializes both the thresholds themselves, as well as any submetrics that\n// were referenced in them.\nfunc (me *MetricsEngine) InitSubMetricsAndThresholds(options lib.Options, onlyLogErrors bool) error {\n\tfor metricName, thresholds := range options.Thresholds {\n\t\tmetric, err := me.getThresholdMetricOrSubmetric(metricName)\n\n\t\tif onlyLogErrors {\n\t\t\tif err != nil {\n\t\t\t\tme.logger.WithError(err).Warnf(\"Invalid metric '%s' in threshold definitions\", metricName)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid metric '%s' in threshold definitions: %w\", metricName, err)\n\t\t}\n\n\t\tmetric.Thresholds = thresholds\n\t\tme.metricsWithThresholds = append(me.metricsWithThresholds, metric)\n\n\t\t// Mark the metric (and the parent metric, if we're dealing with a\n\t\t// submetric) as observed, so they are shown in the end-of-test summary,\n\t\t// even if they don't have any metric samples during the test run\n\t\tme.markObserved(metric)\n\t\tif metric.Sub != nil {\n\t\t\tme.markObserved(metric.Sub.Parent)\n\t\t}\n\t}\n\n\t// TODO: refactor out of here when https://github.com/grafana/k6/issues/1321\n\t// lands and there is a better way to enable a metric with tag\n\tif options.SystemTags.Has(metrics.TagExpectedResponse) {\n\t\t_, err := me.getThresholdMetricOrSubmetric(\"http_req_duration{expected_response:true}\")","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/metrics/engine/engine.go#L112-L148","documentation":"While initializing thresholds from the test options, resolving the named metric or submetric failed (e.g. nonexistent metric or malformed submetric). InitSubMetricsAndThresholds wraps the underlying error from getThresholdMetricOrSubmetric; when onlyLogErrors is set the same condition is logged as a warning instead.","triggerScenarios":"Thrown at internal/metrics/engine/engine.go:130 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix or remove the invalid threshold entry in options.thresholds","Ensure the metric name and optional {key:value} submetric syntax are correct"],"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"}