VictoriaMetrics/VictoriaMetrics · error
`target_label` must be set for `action=keep_if_contains`
Error message
`target_label` must be set for `action=keep_if_contains`
What it means
`action=keep_if_contains` keeps the target label's value only when it contains all values of the given source labels, so `target_label` is required. The parser rejects the config if `target_label` is empty for this action.
Source
Thrown at lib/promrelabel/config.go:293
return nil, fmt.Errorf("`replacement` cannot be used with `action=graphite`; see https://docs.victoriametrics.com/victoriametrics/vmagent/#graphite-relabeling")
}
if rc.Regex != nil {
return nil, fmt.Errorf("`regex` cannot be used for `action=graphite`; see https://docs.victoriametrics.com/victoriametrics/vmagent/#graphite-relabeling")
}
case "replace":
if targetLabel == "" {
return nil, fmt.Errorf("missing `target_label` for `action=replace`")
}
case "replace_all":
if len(sourceLabels) == 0 {
return nil, fmt.Errorf("missing `source_labels` for `action=replace_all`")
}
if targetLabel == "" {
return nil, fmt.Errorf("missing `target_label` for `action=replace_all`")
}
case "keep_if_contains":
if targetLabel == "" {
return nil, fmt.Errorf("`target_label` must be set for `action=keep_if_contains`")
}
if len(sourceLabels) == 0 {
return nil, fmt.Errorf("`source_labels` must contain at least a single entry for `action=keep_if_contains`")
}
if rc.Regex != nil {
return nil, fmt.Errorf("`regex` cannot be used for `action=keep_if_contains`")
}
case "drop_if_contains":
if targetLabel == "" {
return nil, fmt.Errorf("`target_label` must be set for `action=drop_if_contains`")
}
if len(sourceLabels) == 0 {
return nil, fmt.Errorf("`source_labels` must contain at least a single entry for `action=drop_if_contains`")
}
if rc.Regex != nil {
return nil, fmt.Errorf("`regex` cannot be used for `action=drop_if_contains`")
}
case "keep_if_equal":View on GitHub (pinned to 5079fb58f1)
Solutions
- Set `target_label` to the label whose value should be checked/kept
- Use `action=keep` with a regex if you want sample-level filtering instead
- Ensure YAML keys belong to the same list item
Example fix
// before - action: keep_if_contains source_labels: [pod] // after - action: keep_if_contains target_label: pod source_labels: [pod]
Defensive patterns
Strategy: validation
Validate before calling
def validate_relabel(cfg):
if cfg.get('action') == 'keep_if_contains' and not cfg.get('target_label'):
raise ValueError('target_label must be set for action=keep_if_contains')
return True Prevention
- Set target_label explicitly for keep_if_contains
- Do not confuse sample-level keep with label-level keep_if_contains
- Dry-run the config before applying
When it happens
Trigger: ParseRelabelConfigs (or newTestRegexRelabelConfig) is given a config with `action: keep_if_contains` and an empty `target_label`.
Common situations: Writing a keep_if_contains rule thinking it filters whole samples and thus omitting target_label; copy from graphite-style rules which don't use target_label.
Related errors
- `target_label` cannot be used with `action=graphite`; see ht
- `replacement` cannot be used with `action=graphite`; see htt
- `regex` cannot be used for `action=graphite`; see https://do
- missing `target_label` for `action=replace`
- missing `source_labels` for `action=replace_all`
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/96292e2fcc23e6d1.
Report an issue: GitHub.