From 8d8ad817a613258eee3cdd80c6fc37c01b1c8a49 Mon Sep 17 00:00:00 2001 From: Roman Zavodskikh Date: Wed, 16 Aug 2023 18:14:08 +0200 Subject: [PATCH] Added fadein for powerOfRandomNChoices as well Signed-off-by: Roman Zavodskikh --- loadbalancer/algorithm.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/loadbalancer/algorithm.go b/loadbalancer/algorithm.go index 7404e056e1..7e9f3d292f 100644 --- a/loadbalancer/algorithm.go +++ b/loadbalancer/algorithm.go @@ -244,15 +244,16 @@ func newPowerOfRandomNChoices([]string) routing.LBAlgorithm { // Apply implements routing.LBAlgorithm with power of random N choices algorithm. func (p *powerOfRandomNChoices) Apply(ctx *routing.LBContext) routing.LBEndpoint { - ne := len(ctx.Route.LBEndpoints) + endpoints := ctx.Route.GetHealthyEndpoints() + ne := len(endpoints) p.mx.Lock() defer p.mx.Unlock() - best := ctx.Route.LBEndpoints[p.rnd.Intn(ne)] + best := endpoints[p.rnd.Intn(ne)] for i := 1; i < p.numberOfChoices; i++ { - ce := ctx.Route.LBEndpoints[p.rnd.Intn(ne)] + ce := endpoints[p.rnd.Intn(ne)] if p.getScore(ce) > p.getScore(best) { best = ce