From 17805e463401ef9fd3b4688d426f29d4f9e398cd Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 23 Jan 2018 11:17:41 -0800 Subject: [PATCH] Move autopilot health loop into leader operations --- agent/consul/autopilot/autopilot.go | 11 +++++++---- agent/consul/server.go | 3 --- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/agent/consul/autopilot/autopilot.go b/agent/consul/autopilot/autopilot.go index dd7e5c0785..a23412fc2f 100644 --- a/agent/consul/autopilot/autopilot.go +++ b/agent/consul/autopilot/autopilot.go @@ -64,9 +64,10 @@ func NewAutopilot(logger *log.Logger, delegate Delegate, interval, healthInterva func (a *Autopilot) Start() { a.shutdownCh = make(chan struct{}) a.waitGroup = sync.WaitGroup{} - a.waitGroup.Add(1) + a.waitGroup.Add(2) go a.run() + go a.serverHealthLoop() } func (a *Autopilot) Stop() { @@ -299,15 +300,17 @@ func (a *Autopilot) handlePromotions(promotions []raft.Server) error { return nil } -// ServerHealthLoop monitors the health of the servers in the cluster -func (a *Autopilot) ServerHealthLoop(shutdownCh <-chan struct{}) { +// serverHealthLoop monitors the health of the servers in the cluster +func (a *Autopilot) serverHealthLoop() { + defer a.waitGroup.Done() + // Monitor server health until shutdown ticker := time.NewTicker(a.healthInterval) defer ticker.Stop() for { select { - case <-shutdownCh: + case <-a.shutdownCh: return case <-ticker.C: if err := a.updateClusterHealth(); err != nil { diff --git a/agent/consul/server.go b/agent/consul/server.go index 59d072741f..831e0973af 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -418,9 +418,6 @@ func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store) (* // Initialize Autopilot s.initAutopilot(config) - // Start the server health checking. - go s.autopilot.ServerHealthLoop(s.shutdownCh) - return s, nil }