{"record":{"id":"c66aea32a91e897e","repo":"thanos-io/thanos","slug":"parsing-relabel-configuration","errorCode":null,"errorMessage":"parsing relabel configuration","messagePattern":"parsing relabel configuration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/fetcher.go","lineNumber":1402,"sourceCode":"\n\t\tdelete(f.deletionMarkMap, u)\n\t}\n\n\tf.mtx.Unlock()\n\n\treturn nil\n}\n\nvar (\n\tSelectorSupportedRelabelActions = map[relabel.Action]struct{}{relabel.Keep: {}, relabel.Drop: {}, relabel.HashMod: {}}\n)\n\n// ParseRelabelConfig parses relabel configuration.\n// If supportedActions not specified, all relabel actions are valid.\nfunc ParseRelabelConfig(contentYaml []byte, supportedActions map[relabel.Action]struct{}) ([]*relabel.Config, error) {\n\tvar relabelConfig []*relabel.Config\n\tif err := yaml.Unmarshal(contentYaml, &relabelConfig); err != nil {\n\t\treturn nil, errors.Wrap(err, \"parsing relabel configuration\")\n\t}\n\tfor _, cfg := range relabelConfig {\n\t\tif err := cfg.Validate(prommodel.UTF8Validation); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"validate relabel config\")\n\t\t}\n\t}\n\n\tif supportedActions != nil {\n\t\tfor _, cfg := range relabelConfig {\n\t\t\tif _, ok := supportedActions[cfg.Action]; !ok {\n\t\t\t\treturn nil, errors.Errorf(\"unsupported relabel action: %v\", cfg.Action)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn relabelConfig, nil\n}\n","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/fetcher.go#L1384-L1420","documentation":"ParseRelabelConfig unmarshals a YAML slice of Prometheus relabel configs ([]*relabel.Config) and wraps yaml.Unmarshal failures with 'parsing relabel configuration'. It is thrown when the supplied relabel configuration bytes are not valid YAML or do not match the relabel.Config schema.","triggerScenarios":"Calling block.ParseRelabelConfig(contentYaml, supportedActions) with contentYaml that fails yaml.Unmarshal — e.g. invalid YAML syntax, wrong top-level type (a map instead of a list), or fields whose types don't match relabel.Config.","commonSituations":"Users pass a relabel YAML file with wrong indentation, a single mapping instead of a list of rule mappings, or use unknown/misspelled keys; string-vs-int confusion (e.g. separator: 5 instead of \"5\").","solutions":["Fix the YAML syntax: ensure the content is a list of relabel rules, e.g. '- action: keep\\n  regex: ...'.","Validate the file with 'promtool check config' or load it into a small Go snippet calling yaml.Unmarshal into []*relabel.Config first.","Check field names and types against prometheus/common/model relabel.Config (action, source_labels, target_label, regex, separator, replacement, modulus).","Ensure the file was read fully/encoded correctly (no BOM, no HTML error page from a bad URL fetch)."],"exampleFix":"// before (invalid: mapping instead of list)\n// action: drop\n//   source_labels: [a]\n// after\n// - action: drop\n//   source_labels: [a]","handlingStrategy":"validation","validationCode":"// Go: pre-validate relabel YAML before calling ParseRelabelConfig\nvar cfgs []*relabel.Config\nif err := yaml.UnmarshalStrict(contentYaml, &cfgs); err != nil {\n    return fmt.Errorf(\"invalid relabel YAML: %w\", err)\n}","typeGuard":"func isListYaml(b []byte) bool {\n    var l []interface{}\n    return yaml.Unmarshal(b, &l) == nil && l != nil\n}","tryCatchPattern":"cfgs, err := block.ParseRelabelConfig(contentYaml, supportedActions)\nif err != nil {\n    return fmt.Errorf(\"relabel config file %q: %w\", path, err)\n}","preventionTips":["Keep relabel files as top-level YAML lists of mappings.","Lint relabel files with promtool check config in CI.","Avoid hand-editing YAML; generate and validate via tooling.","Check for BOM/encoding issues when reading config from URLs."],"tags":["yaml","relabel","configuration","thanos"],"backgroundTag":"yaml-parse-error","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"}