-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added LBEndpoint field in routing.LBContext struct #2648
Conversation
proxy/proxy.go
Outdated
@@ -469,6 +469,8 @@ func setRequestURLForDynamicBackend(u *url.URL, stateBag map[string]interface{}) | |||
} | |||
|
|||
func setRequestURLForLoadBalancedBackend(u *url.URL, rt *routing.Route, lbctx *routing.LBContext) *routing.LBEndpoint { | |||
lbctx.LBEndpoints = rt.LBEndpoints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this either at the place where context is created or maybe better move context creation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this either at the place where context is
I like this idea, I've done that.
or maybe better move context creation here.
I like this way less, because I need to redeclare a lot variables from func mapRequest(...
in func setRequestURLForLoadBalancedBackend(...
diff --git a/proxy/proxy.go b/proxy/proxy.go
index 80b41df3..dddf641f 100644
--- a/proxy/proxy.go
+++ b/proxy/proxy.go
@@ -468,7 +468,13 @@ func setRequestURLForDynamicBackend(u *url.URL, stateBag map[string]interface{})
}
}
-func setRequestURLForLoadBalancedBackend(u *url.URL, rt *routing.Route, lbctx *routing.LBContext) *routing.LBEndpoint {
+func setRequestURLForLoadBalancedBackend(ctx *context, registry *routing.EndpointRegistry) *routing.LBEndpoint {
+ r := ctx.request
+ rt := ctx.route
+ stateBag := ctx.StateBag()
+ u := r.URL
+ lbctx := &routing.LBContext{Request: r, Route: rt, LBEndpoints: rt.LBEndpoints, Params: stateBag, Registry: registry}
+
e := rt.LBAlgorithm.Apply(lbctx)
u.Scheme = e.Scheme
u.Host = e.Host
@@ -490,7 +496,7 @@ 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 = setRequestURLForLoadBalancedBackend(ctx, registry)
default:
u.Scheme = rt.Scheme
u.Host = rt.Host
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually better because it nicely contains all endpoint selection logic and creates a place to extend in the future.
Also
u.Scheme = e.Scheme
u.Host = e.Host
can be moved out of setRequestURLForLoadBalancedBackend as its not related to endpoint selection,
setRequestURLForLoadBalancedBackend could be renamed to selectLoadBalancedEndpoint (or something alike)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The routing.Route field of routing.LBContext struct will be eventually removed because loadbalancer in general does not require the full information about route, only about endpoints to balance load between. Signed-off-by: Roman Zavodskikh <[email protected]>
6369d6e
to
c4f2b12
Compare
👍 |
1 similar comment
👍 |
Rename setRequestURLForLoadBalancedBackend to selectEndpoint and move loadbalancing context creation inside Followup on #2648 Signed-off-by: Alexander Yastrebov <[email protected]>
Rename setRequestURLForLoadBalancedBackend to selectEndpoint and move loadbalancing context creation inside Followup on #2648 Signed-off-by: Alexander Yastrebov <[email protected]>
The routing.Route field of routing.LBContext struct will be eventually removed because loadbalancer in general does not require the full information about route, only about endpoints to balance load between.
You can think about this PR as preliminary one for the #2634