{"record":{"id":"96292e2fcc23e6d1","repo":"VictoriaMetrics/VictoriaMetrics","slug":"target-label-must-be-set-for-action-keep-if-con","errorCode":null,"errorMessage":"`target_label` must be set for `action=keep_if_contains`","messagePattern":"`target_label` must be set for `action=keep_if_contains`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/promrelabel/config.go","lineNumber":293,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"`replacement` cannot be used with `action=graphite`; see https://docs.victoriametrics.com/victoriametrics/vmagent/#graphite-relabeling\")\n\t\t}\n\t\tif rc.Regex != nil {\n\t\t\treturn nil, fmt.Errorf(\"`regex` cannot be used for `action=graphite`; see https://docs.victoriametrics.com/victoriametrics/vmagent/#graphite-relabeling\")\n\t\t}\n\tcase \"replace\":\n\t\tif targetLabel == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"missing `target_label` for `action=replace`\")\n\t\t}\n\tcase \"replace_all\":\n\t\tif len(sourceLabels) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"missing `source_labels` for `action=replace_all`\")\n\t\t}\n\t\tif targetLabel == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"missing `target_label` for `action=replace_all`\")\n\t\t}\n\tcase \"keep_if_contains\":\n\t\tif targetLabel == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"`target_label` must be set for `action=keep_if_contains`\")\n\t\t}\n\t\tif len(sourceLabels) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"`source_labels` must contain at least a single entry for `action=keep_if_contains`\")\n\t\t}\n\t\tif rc.Regex != nil {\n\t\t\treturn nil, fmt.Errorf(\"`regex` cannot be used for `action=keep_if_contains`\")\n\t\t}\n\tcase \"drop_if_contains\":\n\t\tif targetLabel == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"`target_label` must be set for `action=drop_if_contains`\")\n\t\t}\n\t\tif len(sourceLabels) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"`source_labels` must contain at least a single entry for `action=drop_if_contains`\")\n\t\t}\n\t\tif rc.Regex != nil {\n\t\t\treturn nil, fmt.Errorf(\"`regex` cannot be used for `action=drop_if_contains`\")\n\t\t}\n\tcase \"keep_if_equal\":","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/promrelabel/config.go#L275-L311","documentation":"`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.","triggerScenarios":"ParseRelabelConfigs (or newTestRegexRelabelConfig) is given a config with `action: keep_if_contains` and an empty `target_label`.","commonSituations":"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.","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"],"exampleFix":"// before\n- action: keep_if_contains\n  source_labels: [pod]\n// after\n- action: keep_if_contains\n  target_label: pod\n  source_labels: [pod]","handlingStrategy":"validation","validationCode":"def validate_relabel(cfg):\n    if cfg.get('action') == 'keep_if_contains' and not cfg.get('target_label'):\n        raise ValueError('target_label must be set for action=keep_if_contains')\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["promrelabel","config-validation","relabeling","victoriametrics"],"backgroundTag":"invalid-relabel-config","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}