Update exported status metric to properly reflect alerting status of a monitor
continuous-integration/drone/push Build is failing Details

It was using the result of the individual check and not the monitor as a whole
This commit is contained in:
IamTheFij 2020-07-14 17:09:56 -07:00
parent 5dc5ba5257
commit aad9eaa32f
3 changed files with 7 additions and 6 deletions

View File

@ -33,7 +33,7 @@ func checkMonitors(config *Config) error {
hasAlert := alertNotice != nil
// Track status metrics
Metrics.SetMonitorStatus(monitor.Name, success)
Metrics.SetMonitorStatus(monitor.Name, monitor.IsUp())
Metrics.CountCheck(monitor.Name, success, hasAlert)
// Should probably consider refactoring everything below here

View File

@ -85,12 +85,13 @@ func (monitor *Monitor) Check() (bool, *AlertNotice) {
return isSuccess, alertNotice
}
func (monitor Monitor) isUp() bool {
// IsUp returns the status of the current monitor
func (monitor Monitor) IsUp() bool {
return monitor.alertCount == 0
}
func (monitor *Monitor) success() (notice *AlertNotice) {
if !monitor.isUp() {
if !monitor.IsUp() {
// Alert that we have recovered
notice = monitor.createAlertNotice(true)
}

View File

@ -56,7 +56,7 @@ func TestMonitorShouldCheck(t *testing.T) {
}
}
// TestMonitorIsUp tests the Monitor.isUp()
// TestMonitorIsUp tests the Monitor.IsUp()
func TestMonitorIsUp(t *testing.T) {
cases := []struct {
monitor Monitor
@ -71,9 +71,9 @@ func TestMonitorIsUp(t *testing.T) {
for _, c := range cases {
log.Printf("Testing case %s", c.name)
actual := c.monitor.isUp()
actual := c.monitor.IsUp()
if actual != c.expected {
t.Errorf("isUp(%v), expected=%t actual=%t", c.name, c.expected, actual)
t.Errorf("IsUp(%v), expected=%t actual=%t", c.name, c.expected, actual)
log.Printf("Case failed: %s", c.name)
}
log.Println("-----")