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: enable multi pool client connections #577

Conversation

sinadarbouy
Copy link
Collaborator

@sinadarbouy sinadarbouy commented Jul 14, 2024

Ticket(s)

#398
Closes #512

Description

This pull request introduces significant updates to enhance the handling of proxies within the server configuration and adds support for load balancing strategies. Below are the key changes and features included in this pull request:

Changes

Configuration Changes:

  • Updated the configuration files (config.go, constants.go, types.go) to include new fields for multiple proxies and load balancer strategies.
  • Added default values for new fields in config.go.
  • Enhanced the global configuration validation to ensure proper referencing of clients, pools, and proxies.
  • Important: The structure of the gatewayd.yaml configuration has changed to reflect the new support for multiple proxies and load balancer strategies. Specifically, the configuration now includes a loadBalancer section where rules and strategies are grouped together for clarity.

Load Balancer Implementation:

  • Implemented loadbalancer.go to handle load balancing strategy selection.
  • Introduced round-robin.go to implement the Round Robin load balancing strategy.
  • Created tests for load balancer strategies (loadbalancer_test.go, round-robin_test.go).

Configuration Examples:

  • Updated gatewayd.yaml to include examples of multiple proxies and load balancer configuration.
# GatewayD Global Configuration

loggers:
  default:
...

metrics:
  default:
...

clients:
  default:
...
  default-2:
...

pools:
  default:
...
  default-2:
...

proxies:
  default:
...
  default-2:
...

servers:
  default:
    network: tcp
    address: 0.0.0.0:15432
    proxies:
      - "default"
      - "default-2"
    loadBalancer:
      strategy: ROUND_ROBIN
      # Not yet implemented.
      # loadBalancingRules:
      #   - condition: "default"
      #     percentages:
      #       - proxy: "default"
      #         percentage: 70
      #       - proxy: "default-2"
      #         percentage: 30

api:
...

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

@sinadarbouy sinadarbouy force-pushed the feature/enable-multi-pool-client-connections branch from 04334b8 to d35c2ab Compare July 14, 2024 17:26
config/config.go Outdated Show resolved Hide resolved
gatewayd.yaml Outdated Show resolved Hide resolved
gatewayd.yaml Outdated Show resolved Hide resolved
network/loadbalancer.go Outdated Show resolved Hide resolved
network/server.go Outdated Show resolved Hide resolved
network/round-robin.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
network/loadbalancer_test.go Outdated Show resolved Hide resolved
network/loadbalancer_test.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
network/server.go Show resolved Hide resolved
@ccoVeille
Copy link

LGTM 👍

@sinadarbouy sinadarbouy force-pushed the feature/enable-multi-pool-client-connections branch from f90c704 to 391ee7d Compare July 17, 2024 20:26
@sinadarbouy sinadarbouy marked this pull request as ready for review July 17, 2024 20:35
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.

Thanks for your awesome contribution! 🙏 This paves the way for further development.

I have left a few comments.

errors/errors.go Outdated Show resolved Hide resolved
errors/errors.go Outdated Show resolved Hide resolved
gatewayd.yaml Outdated Show resolved Hide resolved
network/constants.go Outdated Show resolved Hide resolved
network/loadbalancer.go Outdated Show resolved Hide resolved
network/server.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
@sinadarbouy sinadarbouy force-pushed the feature/enable-multi-pool-client-connections branch 2 times, most recently from 016dac1 to 491cad3 Compare July 23, 2024 18:32
network/round-robin.go Outdated Show resolved Hide resolved
network/round-robin_test.go Outdated Show resolved Hide resolved
This commit introduces significant updates to enhance the handling of proxies within the server configuration and adds support for load balancing strategies.

Changes:
- Updated API tests to reflect changes from a single `Proxy` to a list of `Proxies`.
- Adjusted initialization and configuration of proxies in `run.go` to support multiple proxies and load balancer strategies.
- Updated configuration files to include new fields for multiple proxies and load balancer strategies.
- Enhanced global configuration validation for clients, pools, and proxies.
- Added new `loadBalancer` section in `gatewayd.yaml` for rules and strategies.
- Implemented load balancing strategy selection and Round Robin strategy.
- Added tests for load balancer strategies.
- Added new error type `ErrorCodeLoadBalancerStrategyNotFound`.
- Improved proxy connection handling and added informative comments.

Configuration Example:
- Updated `gatewayd.yaml` to reflect new support for multiple proxies and load balancer strategies.
- Ensure to update your configuration files accordingly.

Testing:
- Updated existing tests and added new tests for multi-proxy and load balancing functionality.
- Verified configuration validation for proxies and load balancers.

Impact:
- Improved flexibility and scalability of server configuration.
- Enabled robust proxy management and efficient load distribution.

Update errors/errors.go

Co-authored-by: Mostafa Moradian <[email protected]>
Signed-off-by: sina <[email protected]>

fixed review problems
@sinadarbouy sinadarbouy force-pushed the feature/enable-multi-pool-client-connections branch from 491cad3 to 585ed7f Compare July 23, 2024 20:11
Copy link

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

LGTM 🤞

- Change pools, clients, and proxies to use map[string]map[string] instead of map[string]
- Update related code for compatibility with new nested map structure
remvoed server 2 from gatewatd.yaml file
…iles

Updated variable names in the API, test files, run command, and configuration files to improve code readability and maintainability. Key changes include:

1. **api.go**:
   - Renamed `configurationGroupPools` to `configGroupPools` for clarity.

2. **api_helpers_test.go, api_test.go**:
   - Updated to use `config.DefaultConfigurationBlock` instead of `config.DefaultPool` and `config.DefaultProxy` for better naming consistency.

3. **run.go**:
   - Changed iteration variables to `configGroup` and `configBlockName` for better descriptive naming.
   - Updated logging and error handling to use `configBlockName`.
   - Modified span attribute naming for tracing proxy creation.

4. **config.go**:
   - Updated `DefaultPool`, `DefaultClient`, and `DefaultProxy` to `DefaultConfigurationBlock` in the `LoadDefaults` function.
   - Enhanced configuration parsing logic to handle `DefaultConfigurationBlock` appropriately and ensure robust error handling.

5. **constants.go**:
   - Renamed `DefaultClient`, `DefaultPool`, and `DefaultProxy` to `DefaultConfigurationBlock`.
   - Retained other configuration constants for environment prefix, tracer name, and configuration filenames.

These changes enhance the codebase by standardizing variable names, improving readability, and making the code easier to maintain.
- Enhanced the Client struct by adding YAML tags to all fields, ensuring compatibility with YAML parsers.
- Added YAML tags to the Size field in the Pool struct.
- Included YAML tags for the HealthCheckPeriod field in the Proxy struct.

These changes address limitations of the YAML parser and ensure proper serialization and deserialization of configuration data.
@sinadarbouy
Copy link
Collaborator Author

recent changes I made to the structure configuration. We were having issues, especially when dealing with multiple servers. If a second server went down, no logs were being generated. This happened because the logger was expecting a second instance (default-2), and when it wasn’t there, the logger wouldn’t work, and we couldn’t see any logs. Adding a second logger instance made the errors visible. Also, the metrics system was looking for default-2 and throwing errors when it couldn’t find it.

To fix this, I changed the structure to match what was originally suggested in issue #398. Now, each server, client, pool, and proxy can have its own logger and metrics configuration, which should make things more reliable and scalable.

gatewayd.yaml Outdated Show resolved Hide resolved
gatewayd.yaml Outdated Show resolved Hide resolved
gatewayd.yaml Show resolved Hide resolved
api/api.go Outdated Show resolved Hide resolved
pools[name] = map[string]interface{}{
"cap": p.Cap(),
"size": p.Size(),
pools := make(map[string]any)
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: plugins should be updated as well, as they rely on this API.

api/api_test.go Outdated Show resolved Hide resolved
cmd/run.go Outdated Show resolved Hide resolved
config/types.go Show resolved Hide resolved
backoff: 1s # duration
backoffMultiplier: 2.0 # 0 means no backoff
disableBackoffCaps: false
activeWrites:

Choose a reason for hiding this comment

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

The fact this node appears let me think (I might be wrong) this is a breaking changes.

Is it true? Ia everyone OK with that?

Copy link
Member

@mostafa mostafa Jul 28, 2024

Choose a reason for hiding this comment

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

This change is backward incompatible by design. We can have backward compatibility, but it will increase maintenance overhead in the long run. I'll add a warning to the release notes for this.

backoff: 1s # duration
backoffMultiplier: 2.0 # 0 means no backoff
disableBackoffCaps: false
standbyReads:

Choose a reason for hiding this comment

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

I find no reference of this on the code, while I found activeWrites.

Based on the code, I would say the code will look for any node.

So, is there a need to enforce people to use activeWrites node?

Couldn't we work on a logic of weight or something like that?(maybe another PR) So when no weight each node are equivalent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The activeWrites and standbyReads can be any name. When we created the nested structure for Clients, Pools, and Proxies, we needed to set names for them. I didn’t want to use default because we already have a default for the configuration group, which would be confusing. Therefore, I used activeWrites (copied from the issue description). Now, the default name for the configuration block (nested name for Clients, Pools, Proxies) is activeWrites. That’s why you will find references to activeWrites. standbyReads was added to gateway.yaml to follow the issue structure, meaning that the gateway can support multiple Proxies(maybe its better to remove it).

@mostafa
Copy link
Member

mostafa commented Jul 28, 2024

The GetServers endpoint in the API should return the running loadbalancer config as well:
https://github.com/gatewayd-io/gatewayd/pull/577/files#diff-bf98d5fab5bcfabded9769069e7318683f549ec91cff84c5f87a9ae3a3ca3d8dR280

@mostafa mostafa changed the title Feature/enable multi pool client connections Feature: enable multi pool client connections Jul 28, 2024
- Modified the GetServers endpoint to return the current load balancer configuration for each server.
- Added a new field "loadBalancer" to the server details, including the load balancer strategy name.
- Updated unit tests to validate the new "loadBalancer" field in the API response.
- Adjusted test setup to include the default load balancer strategy configuration.
Renamed short variable names used in type assertions to longer, more descriptive names to resolve golint warnings about variable name length.
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! 🎉

@sinadarbouy Thanks for all your efforts and contribution! 🙏
@ccoVeille Thanks for the reviews! 🙏
@likecodingloveproblems Thanks for the initial PR! 🙏

I'll merge this PR and more load balancing strategies and features can be added in future PRs. We may also need to create seprate PRs for those features (and fixes).

@mostafa mostafa merged commit fd147b4 into gatewayd-io:main Jul 28, 2024
5 checks passed
@mostafa mostafa linked an issue Jul 28, 2024 that may be closed by this pull request
6 tasks
@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.

Enable multi-pool client connections
4 participants