{"record":{"id":"5256ee6e6b34d5fa","repo":"grafana/k6","slug":"metric-s-does-not-exist-in-the-script","errorCode":null,"errorMessage":"metric '%s' does not exist in the script","messagePattern":"metric '(.+?)' does not exist in the script","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/metrics/engine/engine.go","lineNumber":69,"sourceCode":"\treturn me, nil\n}\n\n// CreateIngester returns a pseudo-Output that uses the given metric samples to\n// update the engine's inner state.\nfunc (me *MetricsEngine) CreateIngester() *OutputIngester {\n\treturn &OutputIngester{\n\t\tlogger:        me.logger.WithField(\"component\", \"metrics-engine-ingester\"),\n\t\tmetricsEngine: me,\n\t\tcardinality:   newCardinalityControl(),\n\t}\n}\n\nfunc (me *MetricsEngine) getThresholdMetricOrSubmetric(name string) (*metrics.Metric, error) {\n\tmetricDefinition, submetricDefinition, _ := strings.Cut(name, \"{\")\n\n\tmetric := me.registry.Get(metricDefinition)\n\tif metric == nil {\n\t\treturn nil, fmt.Errorf(\"metric '%s' does not exist in the script\", metricDefinition)\n\t}\n\n\tif len(submetricDefinition) == 0 { // no sub-metric\n\t\treturn metric, nil\n\t}\n\n\tif submetricDefinition[len(submetricDefinition)-1] != '}' {\n\t\treturn nil, fmt.Errorf(\"missing ending bracket, sub-metric format needs to be 'metric{key:value}'\")\n\t}\n\tsm, err := metric.AddSubmetric(submetricDefinition[:len(submetricDefinition)-1])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif sm.Metric.Observed {\n\t\t// Do not repeat warnings for the same sub-metrics\n\t\treturn sm.Metric, nil\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/metrics/engine/engine.go#L51-L87","documentation":"A threshold (or submetric) was defined in the test options for a metric name that is not present in the metric registry. getThresholdMetricOrSubmetric splits the name at '{' and looks up the base metric name; the lookup returned nil, meaning no metric with that name was ever emitted or registered.","triggerScenarios":"Thrown at internal/metrics/engine/engine.go:69 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the metric name spelling in options.thresholds","Register/emit the metric (e.g. via a custom Trend/Counter/Rate/Gauge or by enabling the relevant built-in metric)","Remove the threshold for the nonexistent metric"],"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"}