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

feature 2023.x: Expand NacosLoadBalancer to conveniently support custom service list filtering and load balancing algorithms #3794

Conversation

zhangbinhub
Copy link
Contributor

@zhangbinhub zhangbinhub commented Jul 9, 2024

Expand NacosLoadBalancer to conveniently support custom service list filtering and load balancing algorithms

Describe what this PR does / why we need it

At present, neither the official loadbalancer provided by Spring Cloud nor the existing NacosLoadBalancer can meet personalized load balancing requirements.

  • The official offers RandomLoadBalancer and RoundRobinLoadBalancer
  • SCA provides a NacosLoadBalancer based on Nacos weights

In order to conveniently and quickly meet various personalized load balancing needs, NacosLoadBalancer has been extended to support custom service list filters and custom load balancing algorithms.

Does this pull request fix one issue?

NONE

Describe how you did it

  1. Add interface com.alibaba.cloud.nacos.loadbalancer.ServiceInstanceFilter to expand the service list filter.
  2. Add interface com.alibaba.cloud.nacos.loadbalancer.LoadBalancerAlgorithm to expand the load balancing algorithm.
  3. Add class com.alibaba.cloud.nacos.loadbalancer.DefaultLoadBalancerAlgorithm implementation of default load balancing algorithm, and register as a Bean in LoadBalancerNacosAutoConfiguration.
  4. Adjust the construction method and creation process of NacosLoadBalancer, and add relevant logic for custom service list filtering and custom load balancing algorithm in the getInstanceResponse method.

Describe how to verify it

  1. Set the environment variable spring.cloud.loadbalance.nacos.enabled to true to enable NacosLoadBalancer.
  2. When custom service instance list filter, implement the interface ServiceInstanceFilter and register it as a bean.
  3. When expanding the load balancing algorithm, implement the interface LoadBalancerAlgorithm and register it as a bean.

Special notes for reviews

NONE

@zhangbinhub zhangbinhub changed the title Expand NacosLoadBalancer to conveniently support custom service list … Jul 9, 2024
@zhangbinhub
Copy link
Contributor Author

@yuluo-yx Please review this new feature. If you think it's good, I will update it to the 2021. x and 2022. x branches.

Copy link
Collaborator

@yuluo-yx yuluo-yx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @zhangbinhub

@yuluo-yx
Copy link
Collaborator

@yuluo-yx Please review this new feature. If you think it's good, I will update it to the 2021. x and 2022. x branches.

cc @ruansheng8 @steverao

@yuluo-yx yuluo-yx changed the title feature: Expand NacosLoadBalancer to conveniently support custom service list … Jul 16, 2024
Copy link
Collaborator

@ruansheng8 ruansheng8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ruansheng8 ruansheng8 merged commit e9ba0af into alibaba:2023.x Jul 16, 2024
3 checks passed
@zhangbinhub zhangbinhub deleted the support-customer-loadbalancer-FilterAndAlgorithms-2023.x branch July 22, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants