Skip to content
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

load balancing - get(Request request) should be called on delegates #1227

Closed
thewmo opened this issue Apr 19, 2023 · 5 comments · Fixed by #1250
Closed

load balancing - get(Request request) should be called on delegates #1227

thewmo opened this issue Apr 19, 2023 · 5 comments · Fixed by #1250
Assignees
Milestone

Comments

@thewmo
Copy link

thewmo commented Apr 19, 2023

I have a load balancing configuration that combines zone awareness with a method that need access to the request context/headers (sticky session):

@Bean
public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(ConfigurableApplicationContext context) {
    return ServiceInstanceListSupplier.builder()
            // get the service instances from the discovery client (Eureka in our case)
            .withDiscoveryClient()
            // if the request specifies an instance, filter for it
            .withRequestBasedStickySession()
            // of the survivors, pick one that's in our availability zone, if any
            .withZonePreference()
            .build(context);
}

The comments make clear the desired logic - I want same-zone routing, unless the sc-lb-instance-id cookie specifies the ID of an instance in a different zone. Consequently withZonePreference() is specified after request based sticky session. Otherwise it will only ever be possible to "stick" to an instance in the same zone.

However, in debugging this, it appears the ZonePreferenceServiceInstanceListSupplier is only implementing the get() method that does not take a request, and consequently the request is not propagated to the downstream delegate (in this case, the sticky session mechanism). It seems the ZonePreferenceServiceInstanceListSupplier should also implement Flux<List<ServiceInstance>> get(Request request) and propagate the request to the delegate.

While the documentation does not show any examples of combining ServiceInstanceListSuppliers like this, nothing I found in the docs suggest the list suppliers were not intended to be composable in this way.

@thewmo
Copy link
Author

thewmo commented Apr 19, 2023

Potential/proposed fix in 16ecfa1

@Linzyoo
Copy link

Linzyoo commented May 31, 2023

I need this too. When and which branch will it be merged into?

@OlgaMaciaszek
Copy link
Collaborator

Thanks for reporting the issue @thewmo. Will discuss this with the team and get back to you.

@OlgaMaciaszek
Copy link
Collaborator

We agree that this makes sense. I will be marking at as an enhancement. We should update all the suppliers accordingly. The plan would be to make it default on main and opt-in in other branches. Will get it done in July.

@OlgaMaciaszek OlgaMaciaszek added this to the 3.1.7 milestone Jun 26, 2023
@OlgaMaciaszek OlgaMaciaszek changed the title load balancing - zone-aware list supplier cannot be composed with request-requiring list suppliers load balancing - get(Request request) should be called on delegates Jun 27, 2023
@OlgaMaciaszek OlgaMaciaszek linked a pull request Jun 28, 2023 that will close this issue
@OlgaMaciaszek
Copy link
Collaborator

Done, thanks for yuor input @thewmo. @Linzyoo, it's on all the branches, but it's by default inmain and in 3.1.x and 4.0.x, you'll need to swap a property. Have added info to docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants