Add Weighted Round Robin Algorithm to Load Balancer #591
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket(s)
#398
Description
This PR introduces a new load balancing strategy,
Weighted Round Robin, to the existing load balancer module. The changes include:Implementation of Weighted Round Robin:
A new algorithm WeightedRoundRobin is introduced which selects proxies based on predefined weights.
The weights are configured via the LoadBalancingRules in the server's configuration.
Each proxy's selection frequency corresponds to its assigned weight, ensuring a proportional distribution of traffic.
Configuration Changes:
Updated config/types.go to include LoadBalancingRule and Distribution structures to support the new load balancing strategy.
Modified config/constants.go to add WeightedRoundRobinStrategy as a valid load balancing strategy.
Updated gatewayd.yaml to provide an example configuration for the WEIGHTED_ROUND_ROBIN strategy.
Validation:
Added validation logic in config/config.go to ensure load balancing rules are correctly defined and weights are positive.
Extended error handling in errors/errors.go to account for scenarios where no load balancing rules are provided for weighted round robin.
Unit Tests:
Created comprehensive tests in network/weightedroundrobin_test.go to verify the correct behavior of the WeightedRoundRobin implementation under various scenarios, including empty and missing proxies.
Related PRs
Development Checklist
make gen-docscommand.Legal Checklist