Alerting: Prevent simplified routing zero duration GroupInterval and RepeatInterval (#86561)

Prevent zero duration GroupInterval and RepeatInterval
This commit is contained in:
Matthew Jacobson 2024-04-18 21:08:38 -04:00 committed by GitHub
parent 71445002b7
commit a20197229e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -81,11 +81,11 @@ func (s *NotificationSettings) Validate() error {
if s.GroupWait != nil && *s.GroupWait < 0 { if s.GroupWait != nil && *s.GroupWait < 0 {
return errors.New("group wait must be a positive duration") return errors.New("group wait must be a positive duration")
} }
if s.GroupInterval != nil && *s.GroupInterval < 0 { if s.GroupInterval != nil && *s.GroupInterval <= 0 {
return errors.New("group interval must be a positive duration") return errors.New("group interval must be greater than zero")
} }
if s.RepeatInterval != nil && *s.RepeatInterval < 0 { if s.RepeatInterval != nil && *s.RepeatInterval <= 0 {
return errors.New("repeat interval must be a positive duration") return errors.New("repeat interval must be greater than zero")
} }
return nil return nil
} }

View File

@ -74,6 +74,11 @@ func TestValidate(t *testing.T) {
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(-1*time.Second))), notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(-1*time.Second))),
expErrorContains: "group interval", expErrorContains: "group interval",
}, },
{
name: "group interval zero is invalid",
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(0*time.Second))),
expErrorContains: "group interval",
},
{ {
name: "repeat interval empty is valid", name: "repeat interval empty is valid",
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(nil)), notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(nil)),
@ -87,6 +92,11 @@ func TestValidate(t *testing.T) {
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(-1*time.Second))), notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(-1*time.Second))),
expErrorContains: "repeat interval", expErrorContains: "repeat interval",
}, },
{
name: "repeat interval zero is invalid",
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(0*time.Second))),
expErrorContains: "repeat interval",
},
} }
for _, tt := range testCases { for _, tt := range testCases {