Skip to content

Commit

Permalink
Issue #26: Detect when consul agent is down
Browse files Browse the repository at this point in the history
The passingServices function does not detect when
the 'serfHealth' for a node is 'critical' and
subsequently does not filter out services for
this node.
  • Loading branch information
magiconair committed Dec 13, 2015
1 parent e894761 commit 0268ce3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions registry/consul/passing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ func passingServices(checks []*api.HealthCheck) []*api.HealthCheck {

// node or service 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", svc.ServiceID, 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", svc.ServiceID)
log.Printf("[INFO] consul: Skipping service %q since it is in maintenance mode: %s", svc.ServiceID, c.Output)
goto skip
}
}
Expand Down
3 changes: 3 additions & 0 deletions registry/consul/passing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func TestPassingServices(t *testing.T) {
var (
serfPass = &api.HealthCheck{Node: "node", CheckID: "serfHealth", Status: "passing"}
serfFail = &api.HealthCheck{Node: "node", CheckID: "serfHealth", Status: "critical"}
svc1Pass = &api.HealthCheck{Node: "node", CheckID: "service:abc", Status: "passing", ServiceName: "abc", ServiceID: "abc-1"}
svc2Pass = &api.HealthCheck{Node: "node", CheckID: "service:def", Status: "passing", ServiceName: "def", ServiceID: "def-1"}
svc1Maint = &api.HealthCheck{Node: "node", CheckID: "_service_maintenance:abc-1", Status: "critical", ServiceName: "abc", ServiceID: "abc-1"}
Expand All @@ -25,9 +26,11 @@ func TestPassingServices(t *testing.T) {
{[]*api.HealthCheck{svc1Pass}, []*api.HealthCheck{svc1Pass}},
{[]*api.HealthCheck{svc1Pass, svc2Pass}, []*api.HealthCheck{svc1Pass, svc2Pass}},
{[]*api.HealthCheck{serfPass, svc1Pass}, []*api.HealthCheck{svc1Pass}},
{[]*api.HealthCheck{serfFail, svc1Pass}, nil},
{[]*api.HealthCheck{nodeMaint, svc1Pass}, nil},
{[]*api.HealthCheck{svc1Maint, svc1Pass}, nil},
{[]*api.HealthCheck{nodeMaint, svc1Maint, svc1Pass}, nil},
{[]*api.HealthCheck{serfFail, nodeMaint, svc1Maint, svc1Pass}, nil},
{[]*api.HealthCheck{svc1ID2Maint, svc1Pass}, []*api.HealthCheck{svc1Pass}},
{[]*api.HealthCheck{svc1Maint, svc1Pass, svc2Pass}, []*api.HealthCheck{svc2Pass}},
}
Expand Down

0 comments on commit 0268ce3

Please sign in to comment.