Update exported status metric to properly reflect alerting status of a monitor
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
It was using the result of the individual check and not the monitor as a whole
This commit is contained in:
parent
5dc5ba5257
commit
aad9eaa32f
2
main.go
2
main.go
@ -33,7 +33,7 @@ func checkMonitors(config *Config) error {
|
|||||||
hasAlert := alertNotice != nil
|
hasAlert := alertNotice != nil
|
||||||
|
|
||||||
// Track status metrics
|
// Track status metrics
|
||||||
Metrics.SetMonitorStatus(monitor.Name, success)
|
Metrics.SetMonitorStatus(monitor.Name, monitor.IsUp())
|
||||||
Metrics.CountCheck(monitor.Name, success, hasAlert)
|
Metrics.CountCheck(monitor.Name, success, hasAlert)
|
||||||
|
|
||||||
// Should probably consider refactoring everything below here
|
// Should probably consider refactoring everything below here
|
||||||
|
@ -85,12 +85,13 @@ func (monitor *Monitor) Check() (bool, *AlertNotice) {
|
|||||||
return isSuccess, 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
|
return monitor.alertCount == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (monitor *Monitor) success() (notice *AlertNotice) {
|
func (monitor *Monitor) success() (notice *AlertNotice) {
|
||||||
if !monitor.isUp() {
|
if !monitor.IsUp() {
|
||||||
// Alert that we have recovered
|
// Alert that we have recovered
|
||||||
notice = monitor.createAlertNotice(true)
|
notice = monitor.createAlertNotice(true)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func TestMonitorShouldCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMonitorIsUp tests the Monitor.isUp()
|
// TestMonitorIsUp tests the Monitor.IsUp()
|
||||||
func TestMonitorIsUp(t *testing.T) {
|
func TestMonitorIsUp(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
monitor Monitor
|
monitor Monitor
|
||||||
@ -71,9 +71,9 @@ func TestMonitorIsUp(t *testing.T) {
|
|||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
log.Printf("Testing case %s", c.name)
|
log.Printf("Testing case %s", c.name)
|
||||||
actual := c.monitor.isUp()
|
actual := c.monitor.IsUp()
|
||||||
if actual != c.expected {
|
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.Printf("Case failed: %s", c.name)
|
||||||
}
|
}
|
||||||
log.Println("-----")
|
log.Println("-----")
|
||||||
|
Loading…
Reference in New Issue
Block a user