-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add support loadBalancerKey in RibbonRoutingFilter of Zuul for Canary test #2439
Add support loadBalancerKey in RibbonRoutingFilter of Zuul for Canary test #2439
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2439 +/- ##
==========================================
+ Coverage 68.27% 68.69% +0.42%
==========================================
Files 236 234 -2
Lines 8308 8232 -76
Branches 1031 1021 -10
==========================================
- Hits 5672 5655 -17
+ Misses 2248 2193 -55
+ Partials 388 384 -4
Continue to review full report at Codecov.
|
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.
Could you also provide some documentation on how one would use this?
} | ||
|
||
public RibbonCommandContext(String serviceId, String method, String uri, | ||
Boolean retryable, MultiValueMap<String, String> headers, | ||
MultiValueMap<String, String> params, InputStream requestEntity, | ||
List<RibbonRequestCustomizer> requestCustomizers) { | ||
this(serviceId, method, uri, retryable, headers, params, requestEntity, | ||
requestCustomizers, null); | ||
requestCustomizers, null, null); | ||
} | ||
|
||
public RibbonCommandContext(String serviceId, String method, String uri, |
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.
To avoid breaking anyone I think we should create a new constructor with the new parameter. You could also mark the old constructor deprecated if it is not necessary anymore.
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.
Okay. I will add a new constructor and some documentation soon.
I have a idea about how to add loadBalancerKey in Feign a year ago, see #1272 (comment) . |
defcc62
to
6447c3d
Compare
@ryanjbaxter I've updated code and added some documentation |
@lowzj Hi. Thanks for your comment. Personally I think that those changes (passing |
6447c3d
to
838f9b7
Compare
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.
Would it be possible to add a test that shows how this would be used with Zuul? For example adding the IRule and then making sure the request is routed correctly?
} | ||
|
||
@Deprecated |
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.
Can I change my mind on this? Sorry, maybe we should keep this constructor around since the command key is optional based on the use case. Sorry again.
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.
NP.
@ryanjbaxter I've added the integration test for loadBalancerKey support. Also deleted |
@@ -124,7 +124,7 @@ public void testHttpClientWithFeign() { | |||
public void testRibbonLoadBalancingHttpClient() { | |||
RibbonCommandContext context = new RibbonCommandContext("foo"," GET", "http://localhost", | |||
false, new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), | |||
null, new ArrayList<RibbonRequestCustomizer>(), 0l); | |||
null, new ArrayList<RibbonRequestCustomizer>(), 0l, null); |
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.
you can change these tests back to using the old constructor now
acd4a03
to
25781a8
Compare
@ryanjbaxter I've fixed. |
Thanks,but it doesn't work when I use RetryableRibbonLoadBalancingHttpClient, which pass serviceId instead of loadBalancerKey |
Background
To support canary testing in Zuul, we need to pass the information called
loadBalancerKey
to Ribbon that could be used inIRule
to choose a server for special treatment. But it was not easy until Ribbon 2.2.2 because it doesn't passloadBalancerKey
inClientRequest
toserverLocator(loadBalancerKey)
inLoadBalancerCommand
.From Ribbon 2.2.3 (currently 2.2.4 is the latest), it is possible by Ribbon's PR now.
This PR is about supporting to pass
loadBalancerKey
from Zuul to Ribbon.Description
This PR doesn't change any behavior of Zuul unless there is
loadBalancerKey
inRequestContext
of Zuul.If
RibbonRoutingFilter
findsloadBalancerKey
fromRequestContext
, it will pass it intoRibbonCommandContext
. AndContextAwareRequest
will include this value fromRibbonCommandContext
and it will be passed toLoadBalancerCommand
finally.How to Use
User can add
loadBalancerKey
intoRequestContrext
in his own pre-filter like below.Because user can access much information of HTTP request like headers and query params in pre-filter, user can use any information of HTTP request to determine
loadBalancerKey
.The value for
loadBalancerKey
could be anyObject
and it will be passed whenIRule
is called. User can use this value to determine the address for special routing.Note
There is another subclass of
AbstractLoadBalancerAwareClient
-FeignLoadBalancer
. I think that we can support the same feature for Feign with the similar way. But there is no easy way for user to add his own logic for addingloadBalancerKey
. So we need to consider more about how to support it in Feign.