Rework servers load-balancer to use the WRR
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
67d9c8da0b
commit
fadee5e87b
70 changed files with 2085 additions and 2211 deletions
|
@ -425,14 +425,14 @@
|
|||
mode = "foobar"
|
||||
path = "foobar"
|
||||
port = 42
|
||||
interval = "foobar"
|
||||
timeout = "foobar"
|
||||
interval = "10s"
|
||||
timeout = "10s"
|
||||
hostname = "foobar"
|
||||
[http.services.Service0.loadBalancer.healthCheck.headers]
|
||||
name0 = "foobar"
|
||||
name1 = "foobar"
|
||||
[http.services.Service0.loadBalancer.responseForwarding]
|
||||
flushInterval = "foobar"
|
||||
flushInterval = "10s"
|
||||
|
||||
[tcp]
|
||||
[tcp.routers]
|
||||
|
|
|
@ -9,6 +9,19 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultHealthCheckInterval is the default value for the ServerHealthCheck interval.
|
||||
DefaultHealthCheckInterval = ptypes.Duration(30 * time.Second)
|
||||
// DefaultHealthCheckTimeout is the default value for the ServerHealthCheck timeout.
|
||||
DefaultHealthCheckTimeout = ptypes.Duration(5 * time.Second)
|
||||
|
||||
// DefaultPassHostHeader is the default value for the ServersLoadBalancer passHostHeader.
|
||||
DefaultPassHostHeader = true
|
||||
|
||||
// DefaultFlushInterval is the default value for the ResponseForwarding flush interval.
|
||||
DefaultFlushInterval = ptypes.Duration(100 * time.Millisecond)
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
||||
// HTTPConfiguration contains all the HTTP configuration parameters.
|
||||
|
@ -178,8 +191,11 @@ func (l *ServersLoadBalancer) Mergeable(loadBalancer *ServersLoadBalancer) bool
|
|||
|
||||
// SetDefaults Default values for a ServersLoadBalancer.
|
||||
func (l *ServersLoadBalancer) SetDefaults() {
|
||||
defaultPassHostHeader := true
|
||||
defaultPassHostHeader := DefaultPassHostHeader
|
||||
l.PassHostHeader = &defaultPassHostHeader
|
||||
|
||||
l.ResponseForwarding = &ResponseForwarding{}
|
||||
l.ResponseForwarding.SetDefaults()
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
@ -191,7 +207,12 @@ type ResponseForwarding struct {
|
|||
// This configuration is ignored when ReverseProxy recognizes a response as a streaming response;
|
||||
// for such responses, writes are flushed to the client immediately.
|
||||
// Default: 100ms
|
||||
FlushInterval string `json:"flushInterval,omitempty" toml:"flushInterval,omitempty" yaml:"flushInterval,omitempty" export:"true"`
|
||||
FlushInterval ptypes.Duration `json:"flushInterval,omitempty" toml:"flushInterval,omitempty" yaml:"flushInterval,omitempty" export:"true"`
|
||||
}
|
||||
|
||||
// SetDefaults Default values for a ResponseForwarding.
|
||||
func (r *ResponseForwarding) SetDefaults() {
|
||||
r.FlushInterval = DefaultFlushInterval
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
@ -212,15 +233,13 @@ func (s *Server) SetDefaults() {
|
|||
|
||||
// ServerHealthCheck holds the HealthCheck configuration.
|
||||
type ServerHealthCheck struct {
|
||||
Scheme string `json:"scheme,omitempty" toml:"scheme,omitempty" yaml:"scheme,omitempty" export:"true"`
|
||||
Mode string `json:"mode,omitempty" toml:"mode,omitempty" yaml:"mode,omitempty" export:"true"`
|
||||
Path string `json:"path,omitempty" toml:"path,omitempty" yaml:"path,omitempty" export:"true"`
|
||||
Method string `json:"method,omitempty" toml:"method,omitempty" yaml:"method,omitempty" export:"true"`
|
||||
Port int `json:"port,omitempty" toml:"port,omitempty,omitzero" yaml:"port,omitempty" export:"true"`
|
||||
// TODO change string to ptypes.Duration
|
||||
Interval string `json:"interval,omitempty" toml:"interval,omitempty" yaml:"interval,omitempty" export:"true"`
|
||||
// TODO change string to ptypes.Duration
|
||||
Timeout string `json:"timeout,omitempty" toml:"timeout,omitempty" yaml:"timeout,omitempty" export:"true"`
|
||||
Scheme string `json:"scheme,omitempty" toml:"scheme,omitempty" yaml:"scheme,omitempty" export:"true"`
|
||||
Mode string `json:"mode,omitempty" toml:"mode,omitempty" yaml:"mode,omitempty" export:"true"`
|
||||
Path string `json:"path,omitempty" toml:"path,omitempty" yaml:"path,omitempty" export:"true"`
|
||||
Method string `json:"method,omitempty" toml:"method,omitempty" yaml:"method,omitempty" export:"true"`
|
||||
Port int `json:"port,omitempty" toml:"port,omitempty,omitzero" yaml:"port,omitempty" export:"true"`
|
||||
Interval ptypes.Duration `json:"interval,omitempty" toml:"interval,omitempty" yaml:"interval,omitempty" export:"true"`
|
||||
Timeout ptypes.Duration `json:"timeout,omitempty" toml:"timeout,omitempty" yaml:"timeout,omitempty" export:"true"`
|
||||
Hostname string `json:"hostname,omitempty" toml:"hostname,omitempty" yaml:"hostname,omitempty"`
|
||||
FollowRedirects *bool `json:"followRedirects" toml:"followRedirects" yaml:"followRedirects" export:"true"`
|
||||
Headers map[string]string `json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty" export:"true"`
|
||||
|
@ -231,6 +250,8 @@ func (h *ServerHealthCheck) SetDefaults() {
|
|||
fr := true
|
||||
h.FollowRedirects = &fr
|
||||
h.Mode = "http"
|
||||
h.Interval = DefaultHealthCheckInterval
|
||||
h.Timeout = DefaultHealthCheckTimeout
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
|
|
@ -148,16 +148,16 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
"traefik.http.services.Service0.loadbalancer.healthcheck.headers.name0": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.headers.name1": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.hostname": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.interval": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.interval": "1s",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.path": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.method": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.port": "42",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.scheme": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.mode": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.timeout": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.timeout": "1s",
|
||||
"traefik.http.services.Service0.loadbalancer.healthcheck.followredirects": "true",
|
||||
"traefik.http.services.Service0.loadbalancer.passhostheader": "true",
|
||||
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "1s",
|
||||
"traefik.http.services.Service0.loadbalancer.server.scheme": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.server.port": "8080",
|
||||
"traefik.http.services.Service0.loadbalancer.sticky.cookie.name": "foobar",
|
||||
|
@ -165,16 +165,16 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name0": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name1": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.hostname": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.interval": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.interval": "1s",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.path": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.method": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.port": "42",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.scheme": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.mode": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.timeout": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.timeout": "1s",
|
||||
"traefik.http.services.Service1.loadbalancer.healthcheck.followredirects": "true",
|
||||
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
|
||||
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "1s",
|
||||
"traefik.http.services.Service1.loadbalancer.server.scheme": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.server.port": "8080",
|
||||
"traefik.http.services.Service1.loadbalancer.sticky": "false",
|
||||
|
@ -656,8 +656,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
Path: "foobar",
|
||||
Method: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Interval: ptypes.Duration(time.Second),
|
||||
Timeout: ptypes.Duration(time.Second),
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
|
@ -667,7 +667,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
},
|
||||
PassHostHeader: func(v bool) *bool { return &v }(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
FlushInterval: ptypes.Duration(time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -685,8 +685,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
Path: "foobar",
|
||||
Method: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Interval: ptypes.Duration(time.Second),
|
||||
Timeout: ptypes.Duration(time.Second),
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
|
@ -696,7 +696,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
},
|
||||
PassHostHeader: func(v bool) *bool { return &v }(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
FlushInterval: ptypes.Duration(time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1148,8 +1148,8 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
Path: "foobar",
|
||||
Method: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Interval: ptypes.Duration(time.Second),
|
||||
Timeout: ptypes.Duration(time.Second),
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
|
@ -1158,7 +1158,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
},
|
||||
PassHostHeader: func(v bool) *bool { return &v }(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
FlushInterval: ptypes.Duration(time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1175,8 +1175,8 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
Path: "foobar",
|
||||
Method: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Interval: ptypes.Duration(time.Second),
|
||||
Timeout: ptypes.Duration(time.Second),
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
|
@ -1185,7 +1185,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
},
|
||||
PassHostHeader: func(v bool) *bool { return &v }(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
FlushInterval: ptypes.Duration(time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1332,14 +1332,14 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name1": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Hostname": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Interval": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Interval": "1000000000",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Path": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Method": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Port": "42",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Scheme": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "1000000000",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.PassHostHeader": "true",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "1000000000",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.server.Port": "8080",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.server.Scheme": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.Sticky.Cookie.Name": "foobar",
|
||||
|
@ -1348,14 +1348,14 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name0": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name1": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Hostname": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Interval": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Interval": "1000000000",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Path": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Method": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Port": "42",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Scheme": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "1000000000",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.PassHostHeader": "true",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "1000000000",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.Port": "8080",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar",
|
||||
|
|
|
@ -15,6 +15,12 @@ const (
|
|||
StatusWarning = "warning"
|
||||
)
|
||||
|
||||
// Status of the servers.
|
||||
const (
|
||||
StatusUp = "UP"
|
||||
StatusDown = "DOWN"
|
||||
)
|
||||
|
||||
// Configuration holds the information about the currently running traefik instance.
|
||||
type Configuration struct {
|
||||
Routers map[string]*RouterInfo `json:"routers,omitempty"`
|
||||
|
|
|
@ -2,9 +2,11 @@ package runtime_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/config/runtime"
|
||||
)
|
||||
|
@ -49,7 +51,7 @@ func TestPopulateUsedBy(t *testing.T) {
|
|||
{URL: "http://127.0.0.1:8086"},
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Interval: "500ms",
|
||||
Interval: ptypes.Duration(500 * time.Millisecond),
|
||||
Path: "/health",
|
||||
},
|
||||
},
|
||||
|
@ -159,7 +161,7 @@ func TestPopulateUsedBy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Interval: "500ms",
|
||||
Interval: ptypes.Duration(500 * time.Millisecond),
|
||||
Path: "/health",
|
||||
},
|
||||
},
|
||||
|
@ -177,7 +179,7 @@ func TestPopulateUsedBy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Interval: "500ms",
|
||||
Interval: ptypes.Duration(500 * time.Millisecond),
|
||||
Path: "/health",
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue