Skip to content

Commit

Permalink
proxy: refactor loadbalanced endpoint selection (#2652)
Browse files Browse the repository at this point in the history
Rename setRequestURLForLoadBalancedBackend to selectEndpoint and move loadbalancing context creation inside

Followup on #2648

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Oct 5, 2023
1 parent 98ad969 commit 26018f6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,18 @@ func setRequestURLForDynamicBackend(u *url.URL, stateBag map[string]interface{})
}
}

func setRequestURLForLoadBalancedBackend(u *url.URL, rt *routing.Route, lbctx *routing.LBContext) *routing.LBEndpoint {
func selectEndpoint(ctx *context, registry *routing.EndpointRegistry) *routing.LBEndpoint {
rt := ctx.route

lbctx := &routing.LBContext{
Request: ctx.request,
Route: rt,
LBEndpoints: rt.LBEndpoints,
Params: ctx.StateBag(),
Registry: registry,
}
e := rt.LBAlgorithm.Apply(lbctx)
u.Scheme = e.Scheme
u.Host = e.Host

return &e
}

Expand All @@ -490,7 +498,9 @@ func mapRequest(ctx *context, requestContext stdlibcontext.Context, removeHopHea
setRequestURLFromRequest(u, r)
setRequestURLForDynamicBackend(u, stateBag)
case eskip.LBBackend:
endpoint = setRequestURLForLoadBalancedBackend(u, rt, &routing.LBContext{Request: r, Route: rt, LBEndpoints: rt.LBEndpoints, Params: stateBag, Registry: registry})
endpoint = selectEndpoint(ctx, registry)
u.Scheme = endpoint.Scheme
u.Host = endpoint.Host
default:
u.Scheme = rt.Scheme
u.Host = rt.Host
Expand Down

0 comments on commit 26018f6

Please sign in to comment.