-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Multi-Proxy and Load Balancer Strategy Support
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
- Loading branch information
1 parent
18ae198
commit 585ed7f
Showing
16 changed files
with
484 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/gatewayd-io/gatewayd/config" | ||
gerr "github.com/gatewayd-io/gatewayd/errors" | ||
) | ||
|
||
type LoadBalancerStrategy interface { | ||
NextProxy() (IProxy, *gerr.GatewayDError) | ||
} | ||
|
||
func NewLoadBalancerStrategy(server *Server) (LoadBalancerStrategy, *gerr.GatewayDError) { | ||
switch server.LoadbalancerStrategyName { | ||
case config.RoundRobinStrategy: | ||
return NewRoundRobin(server), nil | ||
default: | ||
return nil, gerr.ErrLoadBalancerStrategyNotFound | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package network | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/gatewayd-io/gatewayd/config" | ||
gerr "github.com/gatewayd-io/gatewayd/errors" | ||
) | ||
|
||
// TestNewLoadBalancerStrategy tests the NewLoadBalancerStrategy function to ensure it correctly | ||
// initializes the load balancer strategy based on the strategy name provided in the server configuration. | ||
// It covers both valid and invalid strategy names. | ||
func TestNewLoadBalancerStrategy(t *testing.T) { | ||
serverValid := &Server{ | ||
LoadbalancerStrategyName: config.RoundRobinStrategy, | ||
Proxies: []IProxy{MockProxy{}}, | ||
} | ||
|
||
// Test case 1: Valid strategy name | ||
strategy, err := NewLoadBalancerStrategy(serverValid) | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
|
||
_, ok := strategy.(*RoundRobin) | ||
if !ok { | ||
t.Errorf("Expected strategy to be of type RoundRobin") | ||
} | ||
|
||
// Test case 2: InValid strategy name | ||
serverInvalid := &Server{ | ||
LoadbalancerStrategyName: "InvalidStrategy", | ||
Proxies: []IProxy{MockProxy{}}, | ||
} | ||
|
||
strategy, err = NewLoadBalancerStrategy(serverInvalid) | ||
if !errors.Is(err, gerr.ErrLoadBalancerStrategyNotFound) { | ||
t.Errorf("Expected ErrLoadBalancerStrategyNotFound, got %v", err) | ||
} | ||
if strategy != nil { | ||
t.Errorf("Expected strategy to be nil for invalid strategy name") | ||
} | ||
} |
Oops, something went wrong.