{"record":{"id":"3338d49fb4ee013a","repo":"argoproj/argo-workflows","slug":"metric-label-s-is-invalid-keys-may-only-contai","errorCode":null,"errorMessage":"metric label '%s' is invalid: keys may only contain alphanumeric characters or '_'","messagePattern":"metric label '(.+?)' is invalid: keys may only contain alphanumeric characters or '_'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/metrics/util.go","lineNumber":46,"sourceCode":"\t\tif metric.Gauge.Realtime != nil && *metric.Gauge.Realtime {\n\t\t\tif strings.Contains(metric.Gauge.Value, \"resourcesDuration.\") {\n\t\t\t\treturn errors.New(\"'resourcesDuration.*' metrics cannot be used in real-time\")\n\t\t\t}\n\t\t}\n\t}\n\tif metric.Counter != nil && metric.Counter.Value == \"\" {\n\t\treturn errors.New(\"missing counter.value\")\n\t}\n\tif metric.Histogram != nil && metric.Histogram.Value == \"\" {\n\t\treturn errors.New(\"missing histogram.value\")\n\t}\n\treturn nil\n}\n\nfunc ValidateMetricLabels(metrics map[string]string) error {\n\tfor name := range metrics {\n\t\tif !IsValidMetricName(name) {\n\t\t\treturn fmt.Errorf(invalidMetricLabelError, name)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":28,"sourceCodeEnd":51,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/metrics/util.go#L28-L51","documentation":"ValidateMetricLabels checks that every metric label KEY is a valid Prometheus metric-style name (alphanumerics and '_', no ':'), reusing IsValidMetricName. Label keys with hyphens, dots, or other characters are rejected during template validation, since Prometheus forbids such label keys.","triggerScenarios":"A workflow step/node template's metrics contain a label key like 'job-id:' or 'pod.name' — validateTemplate calls ValidateMetricLabels and returns this error before submission or reconciliation.","commonSituations":"Users copying Kubernetes-style label keys (which allow dots, dashes, slashes) into Prometheus metric labels; auto-generated label keys derived from annotation keys containing '/' or '.'; typos like trailing colons.","solutions":["Rename label keys to use only [a-zA-Z0-9_] characters","Replace '.'/'-'/'/' in label keys with underscores","Move non-conforming metadata to label VALUES (values are free-form) rather than keys","Run argo lint locally to catch invalid label keys before submitting"],"exampleFix":"# before\nlabels:\n  app.kubernetes.io/name: myapp\n# after\nlabels:\n  app_kubernetes_io_name: myapp","handlingStrategy":"validation","validationCode":"func validLabelKeys(labels map[string]string) bool {\n\tfor k := range labels {\n\t\tif !metrics.IsValidMetricName(k) { return false }\n\t}\n\treturn true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only [a-zA-Z0-9_] for metric label keys","Never copy Kubernetes annotation/label keys directly into metric labels","Put free-form data in label values, not keys","Run argo lint locally and in CI before submitting"],"tags":["metrics","validation","labels","prometheus"],"backgroundTag":"invalid-metric-name","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}