From 4a22e009c100e6b73407ab25403b763ef8767aae Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Fri, 9 Feb 2024 09:01:42 -0500 Subject: [PATCH] Backport of Decouple xds capacity controller and raft-autopilot into release/1.18.x (#20551) * backport of commit 1668a314c65deb75f46059e99ac58fd372fc5bb2 * backport of commit d33eda97bef03181cac293c304ed21bd2d06ecb9 --------- Co-authored-by: Derek Menteer --- .changelog/20511.txt | 3 +++ agent/consul/xdscapacity/capacity.go | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .changelog/20511.txt diff --git a/.changelog/20511.txt b/.changelog/20511.txt new file mode 100644 index 0000000000..ba368bc07b --- /dev/null +++ b/.changelog/20511.txt @@ -0,0 +1,3 @@ +```release-note:bug +connect: Remove code coupling where the xDS capacity controller could negatively affect raft autopilot performance. +``` diff --git a/agent/consul/xdscapacity/capacity.go b/agent/consul/xdscapacity/capacity.go index bf3cf4ced0..5fb538344d 100644 --- a/agent/consul/xdscapacity/capacity.go +++ b/agent/consul/xdscapacity/capacity.go @@ -15,6 +15,7 @@ import ( "golang.org/x/time/rate" "github.com/hashicorp/consul/agent/structs" + "github.com/hashicorp/consul/lib/channels" "github.com/hashicorp/consul/lib/retry" ) @@ -72,7 +73,7 @@ type SessionLimiter interface { func NewController(cfg Config) *Controller { return &Controller{ cfg: cfg, - serverCh: make(chan uint32), + serverCh: make(chan uint32, 1), doneCh: make(chan struct{}), } } @@ -109,9 +110,9 @@ func (c *Controller) Run(ctx context.Context) { // SetServerCount updates the number of healthy servers that is used when // determining capacity. It is called by the autopilot delegate. func (c *Controller) SetServerCount(count uint32) { - select { - case c.serverCh <- count: - case <-c.doneCh: + if err := channels.DeliverLatest(count, c.serverCh); err != nil { + // This should not be possible since only one producer should ever exist, but log anyway. + c.cfg.Logger.Error("failed to deliver latest server count to xDS capacity controller") } }