{"record":{"id":"5d282935f3dba12b","repo":"thanos-io/thanos","slug":"label-set-contains-a-label-with-empty-name-or-valu","errorCode":null,"errorMessage":"label set contains a label with empty name or value","messagePattern":"label set contains a label with empty name or value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/labelpb/label.go","lineNumber":27,"sourceCode":"import (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"sort\"\n\t\"strings\"\n\t\"sync\"\n\t\"unique\"\n\t\"unsafe\"\n\n\t\"github.com/VictoriaMetrics/easyproto\"\n\t\"github.com/cespare/xxhash/v2\"\n\t\"github.com/pkg/errors\"\n\t\"github.com/prometheus/prometheus/model/labels\"\n)\n\nvar (\n\tErrOutOfOrderLabels = errors.New(\"out of order labels\")\n\tErrEmptyLabels      = errors.New(\"label set contains a label with empty name or value\")\n\tErrDuplicateLabels  = errors.New(\"label set contains duplicate label names\")\n\n\tsep = []byte{'\\xff'}\n)\n\nfunc noAllocString(buf []byte) string {\n\treturn *(*string)(unsafe.Pointer(&buf))\n}\n\nfunc noAllocBytes(buf string) []byte {\n\treturn *(*[]byte)(unsafe.Pointer(&buf))\n}\n\n// ZLabelsFromPromLabels converts Prometheus labels to slice of labelpb.ZLabel in type unsafe manner.\n// It reuses the same memory. Caller should abort using passed labels.Labels.\nfunc ZLabelsFromPromLabels(lset labels.Labels) []ZLabel {\n\treturn *(*[]ZLabel)(unsafe.Pointer(&lset))\n}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/labelpb/label.go#L9-L45","documentation":"ErrEmptyLabels is a sentinel error indicating a label set contains a label with an empty name or an empty value (or the whole set is empty in the receive writer path, where an empty set is also rejected). The capnproto writer's validateLabels returns it to reject writes that would produce ambiguous or unrepresentable series.","triggerScenarios":"Remote-writing a series with an empty label name ({}=value), an empty label value (foo=\"\"), or a series with zero labels through pkg/receive/capnproto_writer.go validateLabels (lbls.Len() == 0) or exemplar label validation.","commonSituations":"Prometheus relabel_configs that drop label values leaving foo=\"\"; client libraries emitting empty metric names; dropping __name__ via metric_relabel_configs; sending exemplars with empty label sets.","solutions":["Drop labels whose value is empty before writing (relabel action: labeldrop or keep only non-empty).","Ensure __name__ / metric name is non-empty in the write payload.","For intentionally empty series, attach at least __name__ so the label set is non-empty."],"exampleFix":"// before\nmetric_relabel_configs:\n  - action: replace\n    source_labels: [missing]\n    target_label: zone\n    # produces zone=\"\"\n// after\nmetric_relabel_configs:\n  - action: labeldrop\n    regex: zone_tmp  # never create empty-valued labels","handlingStrategy":"validation","validationCode":"func hasEmptyLabels(lbls labels.Labels) error {\n\tif lbls.Len() == 0 {\n\t\treturn errors.New(\"empty label set\")\n\t}\n\treturn lbls.Validate(func(l labels.Label) error {\n\t\tif l.Name == \"\" || l.Value == \"\" {\n\t\t\treturn fmt.Errorf(\"empty name or value in %q=%q\", l.Name, l.Value)\n\t\t}\n\t\treturn nil\n\t})\n}","typeGuard":"func isEmptyLabelsErr(err error) bool { return errors.Is(err, labelpb.ErrEmptyLabels) }","tryCatchPattern":"if err := writer.Write(ctx, series); err != nil {\n\tif errors.Is(err, labelpb.ErrEmptyLabels) {\n\t\t// drop empty-valued labels client-side and re-send\n\t\tb := labels.NewBuilder(series.Labels)\n\t\tb.Sort()\n\t\tseries.Labels = dropEmpty(b.Labels())\n\t\treturn writer.Write(ctx, series)\n\t}\n\treturn err\n}","preventionTips":["Use metric_relabel_configs to drop labels with empty values before remote-write.","Never target labels from source_labels that may be absent with replace action.","Validate exemplar label sets client-side before sending."],"tags":["labels","validation","remote-write"],"backgroundTag":"empty-required-field","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}