forked from fabiolb/fabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passing.go
58 lines (49 loc) · 1.67 KB
/
passing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package consul
import (
"log"
"strings"
"github.com/hashicorp/consul/api"
)
// passingServices filters out health checks for services which have
// passing health checks and where the neither the service instance itself
// nor the node is in maintenance mode.
func passingServices(checks []*api.HealthCheck, status []string) []*api.HealthCheck {
var p []*api.HealthCheck
for _, svc := range checks {
// first filter out non-service checks
if svc.ServiceID == "" || svc.CheckID == "serfHealth" || svc.CheckID == "_node_maintenance" || strings.HasPrefix("_service_maintenance:", svc.CheckID) {
continue
}
// then make sure the service health check is passing
if !contains(status, svc.Status) {
continue
}
// then check whether the agent is still alive and both the
// node and the service are not in maintenance mode.
for _, c := range checks {
if c.CheckID == "serfHealth" && c.Node == svc.Node && c.Status == "critical" {
log.Printf("[INFO] consul: Skipping service %q since agent on node %q is down: %s", svc.ServiceID, svc.Node, c.Output)
goto skip
}
if c.CheckID == "_node_maintenance" && c.Node == svc.Node {
log.Printf("[INFO] consul: Skipping service %q since node %q is in maintenance mode: %s", svc.ServiceID, svc.Node, c.Output)
goto skip
}
if c.CheckID == "_service_maintenance:"+svc.ServiceID && c.Status == "critical" {
log.Printf("[INFO] consul: Skipping service %q since it is in maintenance mode: %s", svc.ServiceID, c.Output)
goto skip
}
}
p = append(p, svc)
skip:
}
return p
}
func contains(slice []string, item string) bool {
for _, a := range slice {
if a == item {
return true
}
}
return false
}