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:
Ian Fijolek
2022-12-19 11:15:34 -08:00
parent deec04bf0d
commit 7d87c3d036
3 changed files with 38 additions and 24 deletions
+7 -7
View File
@@ -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