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

Reject recording rules with incompatible fields #2000

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rwwiv
Copy link
Contributor

@rwwiv rwwiv commented Jan 23, 2025

No description provided.

@rwwiv rwwiv requested review from a team as code owners January 23, 2025 15:35
Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@cindy
Copy link

cindy commented Jan 28, 2025

Can you fill out the PR description? Otherwise, this looks good to me 👍

Comment on lines +612 to +635
func checkFields(rule *models.ProvisionedAlertRule) error {
if rule.Record != nil {
incompatFieldMsgFmt := `"record" and "%s" cannot be set together`
if rule.For != nil {
return fmt.Errorf(incompatFieldMsgFmt, "for")
}
if rule.NoDataState != nil {
return fmt.Errorf(incompatFieldMsgFmt, "no_data_state")
}
if rule.ExecErrState != nil {
return fmt.Errorf(incompatFieldMsgFmt, "exec_err_state")
}
if rule.Condition != nil {
return fmt.Errorf(incompatFieldMsgFmt, "condition")
}
}

// condition is required if the rule is not a recording rule
if rule.Condition == nil {
return fmt.Errorf(`"condition" is required`)
}
return nil
}

Choose a reason for hiding this comment

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

I think you can achieve this via schema attributes like ConflictsWith and ExactlyOneOf which will give you the terraform validate function and language server some teeth to help users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants