From aa84cc781fa1efccd797588fa387d84f14dc6eaa Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Sat, 16 Dec 2017 14:37:57 +0100 Subject: [PATCH] Identify services using both the ID and the Node This aligns Fabio with the Consul docs[0] which state that a serviceID has to be unique per agent but not cluster wide. Fixes #383 [0] https://www.consul.io/api/agent/service.html#id --- registry/consul/passing.go | 2 +- registry/consul/service.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/registry/consul/passing.go b/registry/consul/passing.go index 7fe5063d6..a8f66ec59 100644 --- a/registry/consul/passing.go +++ b/registry/consul/passing.go @@ -34,7 +34,7 @@ func passingServices(checks []*api.HealthCheck, status []string) []*api.HealthCh log.Printf("[DEBUG] 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" { + if c.CheckID == "_service_maintenance:"+svc.ServiceID && c.Node == svc.Node && c.Status == "critical" { log.Printf("[DEBUG] consul: Skipping service %q since it is in maintenance mode: %s", svc.ServiceID, c.Output) goto skip } diff --git a/registry/consul/service.go b/registry/consul/service.go index 98df8fceb..5ed8bc830 100644 --- a/registry/consul/service.go +++ b/registry/consul/service.go @@ -39,7 +39,10 @@ func servicesConfig(client *api.Client, checks []*api.HealthCheck, tagPrefix str // map service name to list of service passing for which the health check is ok m := map[string]map[string]bool{} for _, check := range checks { - name, id := check.ServiceName, check.ServiceID + // Make the node part of the id, because according to the Consul docs + // the ServiceID is unique per agent but not cluster wide + // https://www.consul.io/api/agent/service.html#id + name, id := check.ServiceName, check.ServiceID+check.Node if _, ok := m[name]; !ok { m[name] = map[string]bool{} @@ -85,7 +88,7 @@ func serviceConfig(client *api.Client, name string, passing map[string]bool, tag for _, svc := range svcs { // check if the instance is in the list of instances // which passed the health check - if _, ok := passing[svc.ServiceID]; !ok { + if _, ok := passing[svc.ServiceID+svc.Node]; !ok { continue }