Add default values for AlertEvery
There is also a test error corrected in TestMonitorFailureAlertEvery where the same test conditions were repeated twice.
This commit is contained in:
+7
-7
@@ -12,7 +12,7 @@ import (
|
||||
type Monitor struct { //nolint:maligned
|
||||
// Config values
|
||||
AlertAfter int16 `yaml:"alert_after"`
|
||||
AlertEvery int16 `yaml:"alert_every"`
|
||||
AlertEvery *int16 `yaml:"alert_every"`
|
||||
CheckInterval SecondsOrDuration `yaml:"check_interval"`
|
||||
Name string
|
||||
AlertDown []string `yaml:"alert_down"`
|
||||
@@ -129,16 +129,16 @@ func (monitor *Monitor) failure() (notice *AlertNotice) {
|
||||
|
||||
// Use alert cadence to determine if we should alert
|
||||
switch {
|
||||
case monitor.AlertEvery > 0:
|
||||
// Handle integer number of failures before alerting
|
||||
if failureCount%monitor.AlertEvery == 0 {
|
||||
notice = monitor.createAlertNotice(false)
|
||||
}
|
||||
case monitor.AlertEvery == 0:
|
||||
case monitor.AlertEvery == nil, *monitor.AlertEvery == 0:
|
||||
// Handle alerting on first failure only
|
||||
if failureCount == 0 {
|
||||
notice = monitor.createAlertNotice(false)
|
||||
}
|
||||
case *monitor.AlertEvery > 0:
|
||||
// Handle integer number of failures before alerting
|
||||
if failureCount%*monitor.AlertEvery == 0 {
|
||||
notice = monitor.createAlertNotice(false)
|
||||
}
|
||||
default:
|
||||
// Handle negative numbers indicating an exponential backoff
|
||||
if failureCount >= int16(math.Pow(2, float64(monitor.alertCount))-1) { //nolint:gomnd
|
||||
|
||||
Reference in New Issue
Block a user