-
Notifications
You must be signed in to change notification settings - Fork 239
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
base: main
Are you sure you want to change the base?
Conversation
In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically. |
Can you fill out the PR description? Otherwise, this looks good to me 👍 |
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 | ||
} | ||
|
There was a problem hiding this comment.
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
No description provided.