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

Conversation

tpaschalis
Copy link
Member

PR Description

This PR updates the validation rules for all *.relabel blocks to be aligned with the validations in upstream Prometheus's UnmarshalYAML method.

Which issue(s) this PR fixes

Fixes #4837

Notes to the Reviewer

I don't think there's something else to sync for loki.relabel since it's not really using much of Promtail code

PR Checklist

  • CHANGELOG.md updated (N/A)
  • Documentation added (N/A)
  • Tests updated (N/A)
  • Config converters updated (N?A)

@@ -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.

Comment on lines -152 to -154
if (rc.Action == KeepEqual || rc.Action == DropEqual) && rc.SourceLabels == nil {
return fmt.Errorf("relabel configuration for %s action requires 'source_labels' value", rc.Action)
}
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.

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.

Signed-off-by: Paschalis Tsilias <[email protected]>
@tpaschalis tpaschalis marked this pull request as ready for review October 23, 2023 10:17
@tpaschalis tpaschalis requested a review from a team as a code owner October 23, 2023 10:17
@tpaschalis tpaschalis requested a review from thampiotr October 23, 2023 10:17
Copy link
Contributor

@thampiotr thampiotr left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@tpaschalis tpaschalis merged commit 4307695 into grafana:main Oct 23, 2023
7 checks passed
@github-actions github-actions bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Feb 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync loki.relabel with Promtail 2.8.4
2 participants