Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/relabel: update validation rules from Prometheus #5566

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions component/common/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ordering so it's easier to scan if the Prometheus code has changed something.

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)
}
Comment on lines -152 to -154
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never existed upstream, not sure why I'd added it tbh.

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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were missing these two for this validation.

return fmt.Errorf("'replacement' can not be set for %s action", rc.Action)
}
if rc.Action == LabelMap && !relabelTarget.MatchString(rc.Replacement) {
Expand Down
16 changes: 0 additions & 16 deletions component/common/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand All @@ -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: `
Expand Down