micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.05k stars 1.06k forks source link

LoadBalancer.java: provide the outgoing http request during select() #8823

Open mcac0006 opened 1 year ago

mcac0006 commented 1 year ago

Feature description

I would like to write my own LoadBalancer which selects the right ServerInstance based on the outgoing HTTP request. Sadly, this is currently impossible. While a LoadBalancer has an Object discrminiator on which the LB can rely on:

https://github.com/micronaut-projects/micronaut-core/blob/3adad0002a19c6288f508ae00b01c8b2596203fe/http-client-core/src/main/java/io/micronaut/http/client/LoadBalancer.java#L42

there is no way one could specify the discriminator.

DefaultHttpClient's resolveURI invokes getLoadBalancerDiscriminator():

https://github.com/micronaut-projects/micronaut-core/blob/3adad0002a19c6288f508ae00b01c8b2596203fe/http-client/src/main/java/io/micronaut/http/client/netty/DefaultHttpClient.java#L1504

but getLoadBalancerDiscrminator() is always empty:

https://github.com/micronaut-projects/micronaut-core/blob/3adad0002a19c6288f508ae00b01c8b2596203fe/http-client/src/main/java/io/micronaut/http/client/netty/DefaultHttpClient.java#L1235-L1237

And although it has a protected access modifier, it does not give me any context about the outgoing request, making an extension DefaultHttpClient pointless.


It looks like there was an attempt to give context to the LoadBalancer. Could you help me understand why it has been left this way, and whether there are plans which helps us derive our own discriminator value?

Thank you.

graemerocher commented 1 year ago

Seems reasonable to refactor this code for Micronaut 4 (where breakage is allowed) to take the request

sdelamo commented 1 year ago

I have moved this to the Micronaut Framework 5 project board.