1
0
Fork 0

Add p2c load-balancing strategy for servers load-balancer

Co-authored-by: Ian Ross <ifross@gmail.com>
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
Romain 2025-03-10 12:12:04 +01:00 committed by GitHub
parent 550d96ea67
commit 9e029a84c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
50 changed files with 1621 additions and 382 deletions

View file

@ -38,6 +38,7 @@ func TestGetLoadBalancer(t *testing.T) {
desc: "Fails when provided an invalid URL",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: ":",
@ -50,7 +51,9 @@ func TestGetLoadBalancer(t *testing.T) {
{
desc: "Succeeds when there are no servers",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{},
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
},
fwd: &forwarderMock{},
expectError: false,
},
@ -58,7 +61,8 @@ func TestGetLoadBalancer(t *testing.T) {
desc: "Succeeds when sticky.cookie is set",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
Strategy: dynamic.BalancerStrategyWRR,
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
},
fwd: &forwarderMock{},
expectError: false,
@ -140,6 +144,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "Load balances between the two servers",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
PassHostHeader: boolPtr(true),
Servers: []dynamic.Server{
{
@ -165,6 +170,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "StatusBadGateway when the server is not reachable",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: "http://foo",
@ -181,7 +187,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "ServiceUnavailable when no servers are available",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Servers: []dynamic.Server{},
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{},
},
expected: []ExpectedResult{
{
@ -193,7 +200,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "Always call the same server when sticky.cookie is true",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
Strategy: dynamic.BalancerStrategyWRR,
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
Servers: []dynamic.Server{
{
URL: server1.URL,
@ -216,7 +224,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "Sticky Cookie's options set correctly",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{HTTPOnly: true, Secure: true}},
Strategy: dynamic.BalancerStrategyWRR,
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{HTTPOnly: true, Secure: true}},
Servers: []dynamic.Server{
{
URL: server1.URL,
@ -236,6 +245,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "PassHost passes the host instead of the IP",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
PassHostHeader: pointer(true),
Servers: []dynamic.Server{
@ -255,6 +265,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "PassHost doesn't pass the host instead of the IP",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
PassHostHeader: pointer(false),
Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}},
Servers: []dynamic.Server{
@ -274,6 +285,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
desc: "No user-agent",
serviceName: "test",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: hasNoUserAgent.URL,
@ -291,6 +303,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
serviceName: "test",
userAgent: "foobar",
service: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: hasUserAgent.URL,
@ -379,6 +392,7 @@ func Test1xxResponses(t *testing.T) {
info := &runtime.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
Servers: []dynamic.Server{
{
URL: backend.URL,
@ -466,7 +480,9 @@ func TestManager_ServiceBuilders(t *testing.T) {
manager := NewManager(map[string]*runtime.ServiceInfo{
"test@test": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.ServersLoadBalancer{},
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
},
},
},
}, nil, nil, &TransportManager{
@ -505,7 +521,9 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*runtime.ServiceInfo{
"serviceName": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.ServersLoadBalancer{},
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
},
},
},
},
@ -516,7 +534,9 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*runtime.ServiceInfo{
"serviceName@provider-1": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.ServersLoadBalancer{},
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
},
},
},
},
@ -527,7 +547,9 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*runtime.ServiceInfo{
"serviceName@provider-1": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.ServersLoadBalancer{},
LoadBalancer: &dynamic.ServersLoadBalancer{
Strategy: dynamic.BalancerStrategyWRR,
},
},
},
},