thanos-io/thanos · error

validate relabel config

Error message

validate relabel config

What it means

After successfully unmarshaling, ParseRelabelConfig validates each rule with cfg.Validate(prommodel.UTF8Validation) and wraps failures with 'validate relabel config'. This means the YAML parsed but a rule violates Prometheus relabel semantics (e.g. invalid regex, empty required fields, invalid label names under UTF8 validation).

Solutions

  1. Read the wrapped cause to see which rule and field failed validation; fix that specific field.
  2. Run the config through 'promtool check config' or 'promtool check web-config' to validate rules offline.
  3. Test regexes with RE2 semantics (https://regex101.com with Go flavor) — e.g. anchor with ^...$ explicitly since Prometheus does not anchor by default.
  4. Ensure label names match allowed label-name syntax (or valid UTF-8 names when using UTF8Validation) and required fields per action are present.

Example fix

// before
// - action: drop
//   regex: "[a-"   # invalid RE2
// after
// - action: drop
//   regex: "[a-z]+"
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate each rule the same way the library does, before calling
for _, c := range cfgs {
    if err := c.Validate(prommodel.UTF8Validation); err != nil {
        return fmt.Errorf("rule %q invalid: %w", c, err)
    }
}

Try / catch

cfgs, err := block.ParseRelabelConfig(contentYaml, supportedActions)
if err != nil && strings.Contains(err.Error(), "validate relabel config") {
    return fmt.Errorf("invalid relabel rule (check regex/label names): %w", err)
}

Prevention

When it happens

Trigger: Calling ParseRelabelConfig with a rule whose Validate() fails: invalid regex in 'regex', empty action or target_label where required, invalid UTF-8/label-name characters, replacement incompatible with the action.

Common situations: Hand-written relabel files with malformed regex (unclosed groups), target_label containing invalid characters, or rules copied from an older Prometheus version whose validation rules changed.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at pkg/block/fetcher.go:1406

	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)