Skip to content

Commit 0b40a84

Browse files
committed
Reimplement fall back to default load balancing
1 parent a233372 commit 0b40a84

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/code.cloudfoundry.org/gorouter/proxy/round_tripper/proxy_round_tripper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (rt *roundTripper) RoundTrip(originalRequest *http.Request) (*http.Response
137137
if headerValue != "" {
138138
iter.(*route.HashBased).HeaderValue = headerValue
139139
} else {
140-
iter = reqInfo.RoutePool.FallBackToDefaultLoadBalancing(rt.logger, stickyEndpointID, mustBeSticky, rt.config.LoadBalanceAZPreference, rt.config.Zone)
140+
iter = reqInfo.RoutePool.FallBackToDefaultLoadBalancing(rt.config.LoadBalance, rt.logger, stickyEndpointID, mustBeSticky, rt.config.LoadBalanceAZPreference, rt.config.Zone)
141141
}
142142
}
143143
}

src/code.cloudfoundry.org/gorouter/route/pool.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,20 @@ func (p *EndpointPool) Endpoints(logger *slog.Logger, initial string, mustBeStic
491491
}
492492
}
493493

494-
func (p *EndpointPool) FallBackToDefaultLoadBalancing(logger *slog.Logger, initial string, mustBeSticky bool, azPreference string, az string) EndpointIterator {
494+
func (p *EndpointPool) FallBackToDefaultLoadBalancing(defaultLBAlgo string, logger *slog.Logger, initial string, mustBeSticky bool, azPreference string, az string) EndpointIterator {
495495
logger.Info("hash-based-routing-header-not-found",
496496
slog.String("poolLBAlgorithm", p.LoadBalancingAlgorithm),
497497
slog.String("Host", p.host),
498498
slog.String("Path", p.contextPath))
499+
500+
switch defaultLBAlgo {
501+
case config.LOAD_BALANCE_LC:
502+
logger.Debug("endpoint-iterator-with-least-connection-lb-algo")
503+
return NewLeastConnection(logger, p, initial, mustBeSticky, azPreference == config.AZ_PREF_LOCAL, az)
504+
case config.LOAD_BALANCE_RR:
505+
logger.Debug("endpoint-iterator-with-round-robin-lb-algo")
506+
return NewRoundRobin(logger, p, initial, mustBeSticky, azPreference == config.AZ_PREF_LOCAL, az)
507+
}
499508
return NewRoundRobin(logger, p, initial, mustBeSticky, azPreference == config.AZ_PREF_LOCAL, az)
500509
}
501510

0 commit comments

Comments
 (0)