Alerting: Allow NoData and ExecErrState to be fully blank on recording rules (#87868)

* Allow empty NoData and ExecErrState on recording rules

* remove TODO about this
This commit is contained in:
Alexander Weaver 2024-05-15 09:35:54 -05:00 committed by GitHub
parent fa63e03df3
commit 1badcf4b63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View File

@ -498,12 +498,14 @@ func (alertRule *AlertRule) ValidateAlertRule(cfg setting.UnifiedAlertingSetting
return fmt.Errorf("%w: cannot have Panel ID without a Dashboard UID", ErrAlertRuleFailedValidation)
}
if _, err := ErrStateFromString(string(alertRule.ExecErrState)); err != nil {
return err
}
if !alertRule.IsRecordingRule() {
if _, err := ErrStateFromString(string(alertRule.ExecErrState)); err != nil {
return err
}
if _, err := NoDataStateFromString(string(alertRule.NoDataState)); err != nil {
return err
if _, err := NoDataStateFromString(string(alertRule.NoDataState)); err != nil {
return err
}
}
if alertRule.For < 0 {

View File

@ -619,10 +619,8 @@ func TestIntegrationInsertAlertRules(t *testing.T) {
rrs := gen.GenerateMany(n)
for i := range rrs {
rrs[i].Condition = ""
// TODO: These fields do not apply to recording rules - for now, we just use the default values of them. This is validated at the storage level.
// TODO: Consider making it so recording rules allow for empty string here, or use some other sentinel value in the future.
rrs[i].NoDataState = models.NoData
rrs[i].ExecErrState = models.ErrorErrState
rrs[i].NoDataState = ""
rrs[i].ExecErrState = ""
rrs[i].For = 0
rrs[i].NotificationSettings = nil
rrs[i].Record = &models.Record{
@ -679,8 +677,8 @@ func TestIntegrationInsertAlertRules(t *testing.T) {
for _, rule := range dbRules {
if rule.IsRecordingRule() {
require.Empty(t, rule.Condition)
require.Equal(t, models.NoData, rule.NoDataState)
require.Equal(t, models.ErrorErrState, rule.ExecErrState)
require.Equal(t, models.NoDataState(""), rule.NoDataState)
require.Equal(t, models.ExecutionErrorState(""), rule.ExecErrState)
require.Zero(t, rule.For)
require.Nil(t, rule.NotificationSettings)
}