From f0cb17f4cb882ee76f2d35eaa8ce0496c1848470 Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Thu, 29 Aug 2019 10:22:51 +0200 Subject: [PATCH] do not surface left servers in catalog --- agent/metadata/server.go | 4 ++++ agent/router/router.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/agent/metadata/server.go b/agent/metadata/server.go index 2532fa3bfa9b..15035c3c4507 100644 --- a/agent/metadata/server.go +++ b/agent/metadata/server.go @@ -64,6 +64,10 @@ func (s *Server) String() string { return fmt.Sprintf("%s (Addr: %s/%s) (DC: %s)", s.Name, networkStr, addrStr, s.Datacenter) } +func (s *Server) HasLeft() bool { + return s.Status == serf.StatusLeft +} + var versionFormat = regexp.MustCompile(`\d+\.\d+\.\d+`) // IsConsulServer returns true if a serf member is a consul server diff --git a/agent/router/router.go b/agent/router/router.go index 426ca1628389..d723b4506aea 100644 --- a/agent/router/router.go +++ b/agent/router/router.go @@ -406,6 +406,12 @@ func (r *Router) GetDatacentersByDistance() ([]string, error) { continue } + if parts.HasLeft() { + r.logger.Printf("[DEBUG]: consul: server %q in area %q left, skipping", + m.Name, areaID) + continue + } + existing := index[parts.Datacenter] if parts.Datacenter == r.localDatacenter { // Everything in the local datacenter looks like zero RTT.