diff --git a/component/common/relabel/relabel.go b/component/common/relabel/relabel.go index 990e5024bdd2..a1acaf3b83c3 100644 --- a/component/common/relabel/relabel.go +++ b/component/common/relabel/relabel.go @@ -146,16 +146,13 @@ func (rc *Config) Validate() error { if rc.Modulus == 0 && rc.Action == HashMod { return fmt.Errorf("relabel configuration for hashmod requires non-zero modulus") } - if (rc.Action == Replace || rc.Action == KeepEqual || rc.Action == DropEqual || rc.Action == HashMod || rc.Action == Lowercase || rc.Action == Uppercase) && rc.TargetLabel == "" { + if (rc.Action == Replace || rc.Action == HashMod || rc.Action == Lowercase || rc.Action == Uppercase || rc.Action == KeepEqual || rc.Action == DropEqual) && rc.TargetLabel == "" { return fmt.Errorf("relabel configuration for %s action requires 'target_label' value", rc.Action) } - if (rc.Action == KeepEqual || rc.Action == DropEqual) && rc.SourceLabels == nil { - return fmt.Errorf("relabel configuration for %s action requires 'source_labels' value", rc.Action) - } - if (rc.Action == Replace || rc.Action == Lowercase || rc.Action == Uppercase) && !relabelTarget.MatchString(rc.TargetLabel) { + if (rc.Action == Replace || rc.Action == Lowercase || rc.Action == Uppercase || rc.Action == KeepEqual || rc.Action == DropEqual) && !relabelTarget.MatchString(rc.TargetLabel) { return fmt.Errorf("%q is invalid 'target_label' for %s action", rc.TargetLabel, rc.Action) } - if (rc.Action == Lowercase || rc.Action == Uppercase) && rc.Replacement != DefaultRelabelConfig.Replacement { + if (rc.Action == Lowercase || rc.Action == Uppercase || rc.Action == KeepEqual || rc.Action == DropEqual) && rc.Replacement != DefaultRelabelConfig.Replacement { return fmt.Errorf("'replacement' can not be set for %s action", rc.Action) } if rc.Action == LabelMap && !relabelTarget.MatchString(rc.Replacement) { diff --git a/component/common/relabel/relabel_test.go b/component/common/relabel/relabel_test.go index 35d141994bea..0a5d0c987954 100644 --- a/component/common/relabel/relabel_test.go +++ b/component/common/relabel/relabel_test.go @@ -38,14 +38,6 @@ func TestParseConfig(t *testing.T) { `, expectErr: true, }, - { - name: "missing dropequal source", - cfg: ` - action = "dropequal" - target_label = "foo" - `, - expectErr: true, - }, { name: "missing keepequal target", cfg: ` @@ -54,14 +46,6 @@ func TestParseConfig(t *testing.T) { `, expectErr: true, }, - { - name: "missing keepequal source", - cfg: ` - action = "keepequal" - target_label = "foo" - `, - expectErr: true, - }, { name: "unknown action", cfg: `