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
- Read the wrapped cause to see which rule and field failed validation; fix that specific field.
- Run the config through 'promtool check config' or 'promtool check web-config' to validate rules offline.
- Test regexes with RE2 semantics (https://regex101.com with Go flavor) — e.g. anchor with ^...$ explicitly since Prometheus does not anchor by default.
- 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
- Test all regexes as RE2 (Go) — no backreferences or lookaheads.
- Anchor regexes explicitly with ^ and $ when exact match is intended.
- Use promtool to validate configs before deployment.
- Keep label names within valid syntax; avoid empty source_labels for actions that forbid them.
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
- unsupported relabel action
- error while parsing tsdb selector configuration
- parse limit configuration
- --receive.lazy-retrieval-max-buffered-responses must be > 0
- failed to convert matchers
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)