thanos-io/thanos · error

parsing relabel configuration

Error message

parsing relabel configuration

What it means

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.

Solutions

  1. Fix the YAML syntax: ensure the content is a list of relabel rules, e.g. '- action: keep\n regex: ...'.
  2. Validate the file with 'promtool check config' or load it into a small Go snippet calling yaml.Unmarshal into []*relabel.Config first.
  3. Check field names and types against prometheus/common/model relabel.Config (action, source_labels, target_label, regex, separator, replacement, modulus).
  4. Ensure the file was read fully/encoded correctly (no BOM, no HTML error page from a bad URL fetch).

Example fix

// before (invalid: mapping instead of list)
// action: drop
//   source_labels: [a]
// after
// - action: drop
//   source_labels: [a]
Defensive patterns

Strategy: validation

Validate before calling

// Go: pre-validate relabel YAML before calling ParseRelabelConfig
var cfgs []*relabel.Config
if err := yaml.UnmarshalStrict(contentYaml, &cfgs); err != nil {
    return fmt.Errorf("invalid relabel YAML: %w", err)
}

Type guard

func isListYaml(b []byte) bool {
    var l []interface{}
    return yaml.Unmarshal(b, &l) == nil && l != nil
}

Try / catch

cfgs, err := block.ParseRelabelConfig(contentYaml, supportedActions)
if err != nil {
    return fmt.Errorf("relabel config file %q: %w", path, err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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").

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/c66aea32a91e897e. Report an issue: GitHub.

Appendix: source

Thrown at pkg/block/fetcher.go:1402

		delete(f.deletionMarkMap, u)
	}

	f.mtx.Unlock()

	return nil
}

var (
	SelectorSupportedRelabelActions = map[relabel.Action]struct{}{relabel.Keep: {}, relabel.Drop: {}, relabel.HashMod: {}}
)

// ParseRelabelConfig parses relabel configuration.
// If supportedActions not specified, all relabel actions are valid.
func ParseRelabelConfig(contentYaml []byte, supportedActions map[relabel.Action]struct{}) ([]*relabel.Config, error) {
	var relabelConfig []*relabel.Config
	if err := yaml.Unmarshal(contentYaml, &relabelConfig); err != nil {
		return nil, errors.Wrap(err, "parsing relabel configuration")
	}
	for _, cfg := range relabelConfig {
		if err := cfg.Validate(prommodel.UTF8Validation); err != nil {
			return nil, errors.Wrap(err, "validate relabel config")
		}
	}

	if supportedActions != nil {
		for _, cfg := range relabelConfig {
			if _, ok := supportedActions[cfg.Action]; !ok {
				return nil, errors.Errorf("unsupported relabel action: %v", cfg.Action)
			}
		}
	}

	return relabelConfig, nil
}

View on GitHub (pinned to 35b8b99117)