Skip to content

Conversation

@sinadarbouy
Copy link
Collaborator

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

  • I have added a descriptive title to this PR.
  • I have squashed related commits together.
  • I have rebased my branch on top of the latest main branch.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added docstring(s) to my code.
  • I have made corresponding changes to the documentation (docs).
  • I have updated docs using make gen-docs command.
  • I have added tests for my changes.
  • I have signed all the commits.

Legal Checklist

Copy link
Member

@mostafa mostafa left a comment

Choose a reason for hiding this comment

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

LGTM! And thanks for your contribution! 🙏

I was thinking about making the proxy name a key in a map for faster access, instead of looping through the array of proxies, but maybe foer another PR.

@mostafa mostafa merged commit bfb0a81 into gatewayd-io:main Aug 10, 2024
@mostafa mostafa mentioned this pull request Oct 6, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants