Request buffering middleware
This commit is contained in:
parent
d426126a92
commit
a81171d5f1
44 changed files with 2155 additions and 5 deletions
|
@ -40,6 +40,7 @@ func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configurat
|
|||
"getLoadBalancer": p.getLoadBalancer,
|
||||
"getMaxConn": p.getMaxConn,
|
||||
"getHealthCheck": p.getHealthCheck,
|
||||
"getBuffering": p.getBuffering,
|
||||
|
||||
// Frontend functions
|
||||
"getFrontendRule": p.getFrontendRule,
|
||||
|
@ -296,6 +297,20 @@ func (p *Provider) getHealthCheck(tags []string) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getBuffering(tags []string) *types.Buffering {
|
||||
if !p.hasAttributePrefix(label.SuffixBackendBuffering, tags) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: p.getInt64Attribute(label.SuffixBackendBufferingMaxRequestBodyBytes, tags, 0),
|
||||
MaxResponseBodyBytes: p.getInt64Attribute(label.SuffixBackendBufferingMaxResponseBodyBytes, tags, 0),
|
||||
MemRequestBodyBytes: p.getInt64Attribute(label.SuffixBackendBufferingMemRequestBodyBytes, tags, 0),
|
||||
MemResponseBodyBytes: p.getInt64Attribute(label.SuffixBackendBufferingMemResponseBodyBytes, tags, 0),
|
||||
RetryExpression: p.getAttribute(label.SuffixBackendBufferingRetryExpression, tags, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getRedirect(tags []string) *types.Redirect {
|
||||
if p.hasAttribute(label.SuffixFrontendRedirectEntryPoint, tags) {
|
||||
return &types.Redirect{
|
||||
|
|
|
@ -1002,6 +1002,52 @@ func TestProviderGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProviderGetBuffering(t *testing.T) {
|
||||
p := &Provider{
|
||||
Prefix: "traefik",
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
tags []string
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no tags",
|
||||
tags: []string{},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when has proper tags",
|
||||
tags: []string{
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes + "=10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes + "=2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes + "=10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes + "=2097152",
|
||||
label.TraefikBackendBufferingRetryExpression + "=IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
result := p.getBuffering(test.tags)
|
||||
|
||||
assert.Equal(t, test.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderGetRedirect(t *testing.T) {
|
||||
p := &Provider{
|
||||
Prefix: "traefik",
|
||||
|
|
|
@ -24,6 +24,7 @@ func (p *Provider) buildConfiguration(containersInspected []dockerData) *types.C
|
|||
"getProtocol": getFuncStringLabel(label.TraefikProtocol, label.DefaultProtocol),
|
||||
"getMaxConn": getMaxConn,
|
||||
"getHealthCheck": getHealthCheck,
|
||||
"getBuffering": getBuffering,
|
||||
"getCircuitBreaker": getCircuitBreaker,
|
||||
"getLoadBalancer": getLoadBalancer,
|
||||
|
||||
|
|
|
@ -214,6 +214,20 @@ func getHealthCheck(container dockerData) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func getBuffering(container dockerData) *types.Buffering {
|
||||
if !label.HasPrefix(container.Labels, label.TraefikBackendBuffering) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: label.GetInt64Value(container.Labels, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: label.GetInt64Value(container.Labels, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemRequestBodyBytes: label.GetInt64Value(container.Labels, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MemResponseBodyBytes: label.GetInt64Value(container.Labels, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: label.GetStringValue(container.Labels, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func getRedirect(container dockerData) *types.Redirect {
|
||||
if label.Has(container.Labels, label.TraefikFrontendRedirectEntryPoint) {
|
||||
return &types.Redirect{
|
||||
|
|
|
@ -108,6 +108,11 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
|||
label.TraefikBackendLoadBalancerStickinessCookieName: "chocolate",
|
||||
label.TraefikBackendMaxConnAmount: "666",
|
||||
label.TraefikBackendMaxConnExtractorFunc: "client.ip",
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingRetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
|
||||
label.TraefikFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
label.TraefikFrontendEntryPoints: "http,https",
|
||||
|
@ -284,6 +289,13 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1421,6 +1433,54 @@ func TestDockerGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDockerGetBuffering(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
container docker.ContainerJSON
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no health check labels",
|
||||
container: containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{})),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when buffering labels are set",
|
||||
container: containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingRetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
})),
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseContainer(test.container)
|
||||
|
||||
actual := getBuffering(dData)
|
||||
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDockerGetHeaders(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
|
@ -117,6 +117,11 @@ func TestSwarmBuildConfiguration(t *testing.T) {
|
|||
label.TraefikBackendLoadBalancerStickinessCookieName: "chocolate",
|
||||
label.TraefikBackendMaxConnAmount: "666",
|
||||
label.TraefikBackendMaxConnExtractorFunc: "client.ip",
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingRetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
|
||||
label.TraefikFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
label.TraefikFrontendEntryPoints: "http,https",
|
||||
|
@ -292,6 +297,13 @@ func TestSwarmBuildConfiguration(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
networks: map[string]*docker.NetworkResource{
|
||||
|
|
|
@ -25,6 +25,7 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types
|
|||
"getLoadBalancer": getLoadBalancer,
|
||||
"getMaxConn": getMaxConn,
|
||||
"getHealthCheck": getHealthCheck,
|
||||
"getBuffering": getBuffering,
|
||||
"getServers": getServers,
|
||||
|
||||
// TODO Deprecated [breaking]
|
||||
|
@ -174,6 +175,20 @@ func getHealthCheck(instance ecsInstance) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func getBuffering(instance ecsInstance) *types.Buffering {
|
||||
if !hasPrefix(instance, label.TraefikBackendBuffering) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemRequestBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MemResponseBodyBytes: getInt64Value(instance, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: getStringValue(instance, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func getServers(instances []ecsInstance) map[string]types.Server {
|
||||
var servers map[string]types.Server
|
||||
|
||||
|
|
|
@ -136,6 +136,11 @@ func TestBuildConfiguration(t *testing.T) {
|
|||
label.TraefikBackendLoadBalancerStickinessCookieName: aws.String("chocolate"),
|
||||
label.TraefikBackendMaxConnAmount: aws.String("666"),
|
||||
label.TraefikBackendMaxConnExtractorFunc: aws.String("client.ip"),
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: aws.String("10485760"),
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: aws.String("2097152"),
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: aws.String("10485760"),
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: aws.String("2097152"),
|
||||
label.TraefikBackendBufferingRetryExpression: aws.String("IsNetworkError() && Attempts() <= 2"),
|
||||
|
||||
label.TraefikFrontendAuthBasic: aws.String("test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"),
|
||||
label.TraefikFrontendEntryPoints: aws.String("http,https"),
|
||||
|
@ -222,6 +227,13 @@ func TestBuildConfiguration(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
Frontends: map[string]*types.Frontend{
|
||||
|
@ -948,6 +960,53 @@ func TestGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetBuffering(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
instance ecsInstance
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no buffering labels",
|
||||
instance: ecsInstance{
|
||||
containerDefinition: &ecs.ContainerDefinition{
|
||||
DockerLabels: map[string]*string{},
|
||||
}},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when health check labels are set",
|
||||
instance: ecsInstance{
|
||||
containerDefinition: &ecs.ContainerDefinition{
|
||||
DockerLabels: map[string]*string{
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: aws.String("10485760"),
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: aws.String("2097152"),
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: aws.String("10485760"),
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: aws.String("2097152"),
|
||||
label.TraefikBackendBufferingRetryExpression: aws.String("IsNetworkError() && Attempts() <= 2"),
|
||||
}}},
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actual := getBuffering(test.instance)
|
||||
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServers(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
|
@ -90,6 +90,47 @@ func circuitBreaker(exp string) func(*types.Backend) {
|
|||
}
|
||||
}
|
||||
|
||||
func buffering(opts ...func(*types.Buffering)) func(*types.Backend) {
|
||||
return func(b *types.Backend) {
|
||||
if b.Buffering == nil {
|
||||
b.Buffering = &types.Buffering{}
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(b.Buffering)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func maxRequestBodyBytes(value int64) func(*types.Buffering) {
|
||||
return func(b *types.Buffering) {
|
||||
b.MaxRequestBodyBytes = value
|
||||
}
|
||||
}
|
||||
|
||||
func memRequestBodyBytes(value int64) func(*types.Buffering) {
|
||||
return func(b *types.Buffering) {
|
||||
b.MemRequestBodyBytes = value
|
||||
}
|
||||
}
|
||||
|
||||
func maxResponseBodyBytes(value int64) func(*types.Buffering) {
|
||||
return func(b *types.Buffering) {
|
||||
b.MaxResponseBodyBytes = value
|
||||
}
|
||||
}
|
||||
|
||||
func memResponseBodyBytes(value int64) func(*types.Buffering) {
|
||||
return func(b *types.Buffering) {
|
||||
b.MemResponseBodyBytes = value
|
||||
}
|
||||
}
|
||||
|
||||
func retrying(exp string) func(*types.Buffering) {
|
||||
return func(b *types.Buffering) {
|
||||
b.RetryExpression = exp
|
||||
}
|
||||
}
|
||||
|
||||
// Frontend
|
||||
|
||||
func buildFrontends(opts ...func(*types.Frontend) string) map[string]*types.Frontend {
|
||||
|
|
|
@ -295,6 +295,8 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
|||
}
|
||||
}
|
||||
|
||||
templateObjects.Backends[r.Host+pa.Path].Buffering = getBuffering(service)
|
||||
|
||||
if service.Annotations[label.TraefikBackendLoadBalancerMethod] == "drr" {
|
||||
templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Method = "drr"
|
||||
}
|
||||
|
@ -538,3 +540,16 @@ func getFrontendRedirect(i *v1beta1.Ingress) *types.Redirect {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBuffering(service *v1.Service) *types.Buffering {
|
||||
if label.HasPrefix(service.Annotations, label.TraefikBackendBuffering) {
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: label.GetInt64Value(service.Annotations, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MemRequestBodyBytes: label.GetInt64Value(service.Annotations, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: label.GetInt64Value(service.Annotations, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemResponseBodyBytes: label.GetInt64Value(service.Annotations, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: label.GetStringValue(service.Annotations, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -431,6 +431,9 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
iRule(
|
||||
iHost("bar"),
|
||||
iPaths(onePath(iBackend("service2", intstr.FromInt(802))))),
|
||||
iRule(
|
||||
iHost("baz"),
|
||||
iPaths(onePath(iBackend("service3", intstr.FromInt(803))))),
|
||||
),
|
||||
),
|
||||
}
|
||||
|
@ -456,6 +459,19 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
clusterIP("10.0.0.2"),
|
||||
sPorts(sPort(802, ""))),
|
||||
),
|
||||
buildService(
|
||||
sName("service3"),
|
||||
sNamespace("testing"),
|
||||
sUID("3"),
|
||||
sAnnotation(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
sAnnotation(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
sAnnotation(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
sAnnotation(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
sAnnotation(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
sSpec(
|
||||
clusterIP("10.0.0.3"),
|
||||
sPorts(sPort(803, ""))),
|
||||
),
|
||||
}
|
||||
|
||||
endpoints := []*v1.Endpoints{
|
||||
|
@ -481,6 +497,17 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
eAddresses(eAddress("10.15.0.2")),
|
||||
ePorts(ePort(8080, "http"))),
|
||||
),
|
||||
buildEndpoint(
|
||||
eNamespace("testing"),
|
||||
eName("service3"),
|
||||
eUID("3"),
|
||||
subset(
|
||||
eAddresses(eAddress("10.14.0.1")),
|
||||
ePorts(ePort(8080, "http"))),
|
||||
subset(
|
||||
eAddresses(eAddress("10.12.0.1")),
|
||||
ePorts(ePort(8080, "http"))),
|
||||
),
|
||||
}
|
||||
|
||||
watchChan := make(chan interface{})
|
||||
|
@ -510,6 +537,19 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
server("http://10.15.0.2:8080", weight(1))),
|
||||
lbMethod("wrr"), lbSticky(),
|
||||
),
|
||||
backend("baz",
|
||||
servers(
|
||||
server("http://10.14.0.1:8080", weight(1)),
|
||||
server("http://10.12.0.1:8080", weight(1))),
|
||||
lbMethod("wrr"),
|
||||
buffering(
|
||||
maxRequestBodyBytes(10485760),
|
||||
memRequestBodyBytes(2097152),
|
||||
maxResponseBodyBytes(10485760),
|
||||
memResponseBodyBytes(2097152),
|
||||
retrying("IsNetworkError() && Attempts() <= 2"),
|
||||
),
|
||||
),
|
||||
),
|
||||
frontends(
|
||||
frontend("foo/bar",
|
||||
|
@ -522,7 +562,13 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
frontend("bar",
|
||||
headers(),
|
||||
passHostHeader(),
|
||||
routes(route("bar", "Host:bar"))),
|
||||
routes(route("bar", "Host:bar")),
|
||||
),
|
||||
frontend("baz",
|
||||
headers(),
|
||||
passHostHeader(),
|
||||
routes(route("baz", "Host:baz")),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
@ -15,6 +15,12 @@ const (
|
|||
pathBackendServers = "/servers/"
|
||||
pathBackendServerURL = "/url"
|
||||
pathBackendServerWeight = "/weight"
|
||||
pathBackendBuffering = "/buffering/"
|
||||
pathBackendBufferingMaxResponseBodyBytes = pathBackendBuffering + "maxresponsebodybytes"
|
||||
pathBackendBufferingMemResponseBodyBytes = pathBackendBuffering + "memresponsebodybytes"
|
||||
pathBackendBufferingMaxRequestBodyBytes = pathBackendBuffering + "maxrequestbodybytes"
|
||||
pathBackendBufferingMemRequestBodyBytes = pathBackendBuffering + "memrequestbodybytes"
|
||||
pathBackendBufferingRetryExpression = pathBackendBuffering + "retryexpression"
|
||||
|
||||
pathFrontends = "/frontends/"
|
||||
pathFrontendBackend = "/backend"
|
||||
|
|
|
@ -60,6 +60,7 @@ func (p *Provider) buildConfiguration() *types.Configuration {
|
|||
"getLoadBalancer": p.getLoadBalancer,
|
||||
"getMaxConn": p.getMaxConn,
|
||||
"getHealthCheck": p.getHealthCheck,
|
||||
"getBuffering": p.getBuffering,
|
||||
"getSticky": p.getSticky, // Deprecated [breaking]
|
||||
"hasStickinessLabel": p.hasStickinessLabel, // Deprecated [breaking]
|
||||
"getStickinessCookieName": p.getStickinessCookieName, // Deprecated [breaking]
|
||||
|
@ -273,6 +274,25 @@ func (p *Provider) getHealthCheck(rootPath string) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getBuffering(rootPath string) *types.Buffering {
|
||||
pathsBuffering := p.list(rootPath, pathBackendBuffering)
|
||||
|
||||
var buffering *types.Buffering
|
||||
if len(pathsBuffering) > 0 {
|
||||
if buffering == nil {
|
||||
buffering = &types.Buffering{}
|
||||
}
|
||||
|
||||
buffering.MaxRequestBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMaxRequestBodyBytes)
|
||||
buffering.MaxResponseBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMaxResponseBodyBytes)
|
||||
buffering.MemRequestBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMemRequestBodyBytes)
|
||||
buffering.MemResponseBodyBytes = p.getInt64(0, rootPath, pathBackendBufferingMemResponseBodyBytes)
|
||||
buffering.RetryExpression = p.get("", rootPath, pathBackendBufferingRetryExpression)
|
||||
}
|
||||
|
||||
return buffering
|
||||
}
|
||||
|
||||
func (p *Provider) getTLSSection(prefix string) []*tls.Configuration {
|
||||
var tlsSection []*tls.Configuration
|
||||
|
||||
|
|
|
@ -76,6 +76,11 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
withPair(pathBackendHealthCheckInterval, "30s"),
|
||||
withPair(pathBackendMaxConnAmount, "5"),
|
||||
withPair(pathBackendMaxConnExtractorFunc, "client.ip"),
|
||||
withPair(pathBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
withPair("servers/server1/url", "http://172.17.0.2:80"),
|
||||
withPair("servers/server1/weight", "0"),
|
||||
withPair("servers/server2/weight", "0")),
|
||||
|
@ -162,6 +167,13 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
Port: 80,
|
||||
Interval: "30s",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
Frontends: map[string]*types.Frontend{
|
||||
|
@ -1700,6 +1712,47 @@ func TestProviderGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProviderGetBufferingReal(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
rootPath string
|
||||
kvPairs []*store.KVPair
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "when all configuration keys defined",
|
||||
rootPath: "traefik/backends/foo",
|
||||
kvPairs: filler("traefik",
|
||||
backend("foo",
|
||||
withPair(pathBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withPair(pathBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withPair(pathBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"))),
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
p := newProviderMock(test.kvPairs)
|
||||
|
||||
result := p.getBuffering(test.rootPath)
|
||||
|
||||
assert.Equal(t, test.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderGetTLSes(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
|
@ -24,6 +24,12 @@ const (
|
|||
SuffixBackendLoadBalancerStickinessCookieName = SuffixBackendLoadBalancer + ".stickiness.cookieName"
|
||||
SuffixBackendMaxConnAmount = "backend.maxconn.amount"
|
||||
SuffixBackendMaxConnExtractorFunc = "backend.maxconn.extractorfunc"
|
||||
SuffixBackendBuffering = "backend.buffering"
|
||||
SuffixBackendBufferingMaxRequestBodyBytes = SuffixBackendBuffering + ".maxRequestBodyBytes"
|
||||
SuffixBackendBufferingMemRequestBodyBytes = SuffixBackendBuffering + ".memRequestBodyBytes"
|
||||
SuffixBackendBufferingMaxResponseBodyBytes = SuffixBackendBuffering + ".maxResponseBodyBytes"
|
||||
SuffixBackendBufferingMemResponseBodyBytes = SuffixBackendBuffering + ".memResponseBodyBytes"
|
||||
SuffixBackendBufferingRetryExpression = SuffixBackendBuffering + ".retryExpression"
|
||||
SuffixFrontend = "frontend"
|
||||
SuffixFrontendAuthBasic = "frontend.auth.basic"
|
||||
SuffixFrontendBackend = "frontend.backend"
|
||||
|
@ -80,6 +86,12 @@ const (
|
|||
TraefikBackendLoadBalancerStickinessCookieName = Prefix + SuffixBackendLoadBalancerStickinessCookieName
|
||||
TraefikBackendMaxConnAmount = Prefix + SuffixBackendMaxConnAmount
|
||||
TraefikBackendMaxConnExtractorFunc = Prefix + SuffixBackendMaxConnExtractorFunc
|
||||
TraefikBackendBuffering = Prefix + SuffixBackendBuffering
|
||||
TraefikBackendBufferingMaxRequestBodyBytes = Prefix + SuffixBackendBufferingMaxRequestBodyBytes
|
||||
TraefikBackendBufferingMemRequestBodyBytes = Prefix + SuffixBackendBufferingMemRequestBodyBytes
|
||||
TraefikBackendBufferingMaxResponseBodyBytes = Prefix + SuffixBackendBufferingMaxResponseBodyBytes
|
||||
TraefikBackendBufferingMemResponseBodyBytes = Prefix + SuffixBackendBufferingMemResponseBodyBytes
|
||||
TraefikBackendBufferingRetryExpression = Prefix + SuffixBackendBufferingRetryExpression
|
||||
TraefikFrontend = Prefix + SuffixFrontend
|
||||
TraefikFrontendAuthBasic = Prefix + SuffixFrontendAuthBasic
|
||||
TraefikFrontendEntryPoints = Prefix + SuffixFrontendEntryPoints
|
||||
|
|
|
@ -32,6 +32,7 @@ func (p *Provider) buildConfiguration() *types.Configuration {
|
|||
"getLoadBalancer": getLoadBalancer,
|
||||
"getMaxConn": getMaxConn,
|
||||
"getHealthCheck": getHealthCheck,
|
||||
"getBuffering": getBuffering,
|
||||
"getServers": p.getServers,
|
||||
|
||||
// TODO Deprecated [breaking]
|
||||
|
@ -455,6 +456,20 @@ func getHealthCheck(application marathon.Application) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func getBuffering(application marathon.Application) *types.Buffering {
|
||||
if !label.HasPrefixP(application.Labels, label.TraefikBackendBuffering) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: label.GetInt64ValueP(application.Labels, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: label.GetInt64ValueP(application.Labels, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemRequestBodyBytes: label.GetInt64ValueP(application.Labels, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MemResponseBodyBytes: label.GetInt64ValueP(application.Labels, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: label.GetStringValueP(application.Labels, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getServers(application marathon.Application, serviceName string) map[string]types.Server {
|
||||
var servers map[string]types.Server
|
||||
|
||||
|
|
|
@ -190,6 +190,11 @@ func TestBuildConfigurationNonAPIErrors(t *testing.T) {
|
|||
withLabel(label.TraefikBackendLoadBalancerStickinessCookieName, "chocolate"),
|
||||
withLabel(label.TraefikBackendMaxConnAmount, "666"),
|
||||
withLabel(label.TraefikBackendMaxConnExtractorFunc, "client.ip"),
|
||||
withLabel(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
|
||||
withLabel(label.TraefikFrontendAuthBasic, "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"),
|
||||
withLabel(label.TraefikFrontendEntryPoints, "http,https"),
|
||||
|
@ -367,6 +372,13 @@ func TestBuildConfigurationNonAPIErrors(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -494,6 +506,11 @@ func TestBuildConfigurationServicesNonAPIErrors(t *testing.T) {
|
|||
withLabel(label.TraefikBackendLoadBalancerStickinessCookieName, "chocolate"),
|
||||
withLabel(label.TraefikBackendMaxConnAmount, "666"),
|
||||
withLabel(label.TraefikBackendMaxConnExtractorFunc, "client.ip"),
|
||||
withLabel(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
|
||||
withServiceLabel(label.TraefikPort, "80", "containous"),
|
||||
withServiceLabel(label.TraefikProtocol, "https", "containous"),
|
||||
|
@ -674,6 +691,13 @@ func TestBuildConfigurationServicesNonAPIErrors(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1535,6 +1559,49 @@ func TestGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetBuffering(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
application marathon.Application
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no buffering labels",
|
||||
application: application(appPorts(80)),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when buffering labels are set",
|
||||
|
||||
application: application(
|
||||
withLabel(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
),
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actual := getBuffering(test.application)
|
||||
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServers(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
|
@ -26,6 +26,7 @@ func (p *Provider) buildConfiguration(tasks []state.Task) *types.Configuration {
|
|||
"getLoadBalancer": getLoadBalancer,
|
||||
"getMaxConn": getMaxConn,
|
||||
"getHealthCheck": getHealthCheck,
|
||||
"getBuffering": getBuffering,
|
||||
"getServers": p.getServers,
|
||||
"getHost": p.getHost,
|
||||
"getServerPort": p.getServerPort,
|
||||
|
@ -300,6 +301,20 @@ func getHealthCheck(task state.Task) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func getBuffering(task state.Task) *types.Buffering {
|
||||
if !hasPrefix(task, label.TraefikBackendBuffering) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: getInt64Value(task, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: getInt64Value(task, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemRequestBodyBytes: getInt64Value(task, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MemResponseBodyBytes: getInt64Value(task, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: getStringValue(task, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provider) getServers(tasks []state.Task) map[string]types.Server {
|
||||
var servers map[string]types.Server
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuildConfigurationNew(t *testing.T) {
|
||||
func TestBuildConfiguration(t *testing.T) {
|
||||
p := &Provider{
|
||||
Domain: "docker.localhost",
|
||||
ExposedByDefault: true,
|
||||
|
@ -132,6 +132,11 @@ func TestBuildConfigurationNew(t *testing.T) {
|
|||
withLabel(label.TraefikBackendLoadBalancerStickinessCookieName, "chocolate"),
|
||||
withLabel(label.TraefikBackendMaxConnAmount, "666"),
|
||||
withLabel(label.TraefikBackendMaxConnExtractorFunc, "client.ip"),
|
||||
withLabel(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
|
||||
withLabel(label.TraefikFrontendAuthBasic, "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"),
|
||||
withLabel(label.TraefikFrontendEntryPoints, "http,https"),
|
||||
|
@ -307,6 +312,13 @@ func TestBuildConfigurationNew(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -810,6 +822,55 @@ func TestGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetBuffering(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
task state.Task
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no buffering labels",
|
||||
task: aTask("ID1",
|
||||
withIP("10.10.10.10"),
|
||||
withInfo("name1", withPorts(withPort("TCP", 80, "WEB"))),
|
||||
withDefaultStatus(),
|
||||
),
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when health check labels are set",
|
||||
task: aTask("ID1",
|
||||
withLabel(label.TraefikBackendBufferingMaxResponseBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemResponseBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingMaxRequestBodyBytes, "10485760"),
|
||||
withLabel(label.TraefikBackendBufferingMemRequestBodyBytes, "2097152"),
|
||||
withLabel(label.TraefikBackendBufferingRetryExpression, "IsNetworkError() && Attempts() <= 2"),
|
||||
withIP("10.10.10.10"),
|
||||
withInfo("name1", withPorts(withPort("TCP", 80, "WEB"))),
|
||||
withDefaultStatus(),
|
||||
),
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actual := getBuffering(test.task)
|
||||
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServers(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
|
@ -24,6 +24,7 @@ func (p *Provider) buildConfiguration(services []rancherData) *types.Configurati
|
|||
"getLoadBalancer": getLoadBalancer,
|
||||
"getMaxConn": getMaxConn,
|
||||
"getHealthCheck": getHealthCheck,
|
||||
"getBuffering": getBuffering,
|
||||
"getServers": getServers,
|
||||
|
||||
// TODO Deprecated [breaking]
|
||||
|
@ -235,6 +236,20 @@ func getHealthCheck(service rancherData) *types.HealthCheck {
|
|||
}
|
||||
}
|
||||
|
||||
func getBuffering(service rancherData) *types.Buffering {
|
||||
if !label.HasPrefix(service.Labels, label.TraefikBackendBuffering) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Buffering{
|
||||
MaxRequestBodyBytes: label.GetInt64Value(service.Labels, label.TraefikBackendBufferingMaxRequestBodyBytes, 0),
|
||||
MaxResponseBodyBytes: label.GetInt64Value(service.Labels, label.TraefikBackendBufferingMaxResponseBodyBytes, 0),
|
||||
MemRequestBodyBytes: label.GetInt64Value(service.Labels, label.TraefikBackendBufferingMemRequestBodyBytes, 0),
|
||||
MemResponseBodyBytes: label.GetInt64Value(service.Labels, label.TraefikBackendBufferingMemResponseBodyBytes, 0),
|
||||
RetryExpression: label.GetStringValue(service.Labels, label.TraefikBackendBufferingRetryExpression, ""),
|
||||
}
|
||||
}
|
||||
|
||||
func getServers(service rancherData) map[string]types.Server {
|
||||
var servers map[string]types.Server
|
||||
|
||||
|
|
|
@ -50,6 +50,11 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
label.TraefikBackendLoadBalancerStickinessCookieName: "chocolate",
|
||||
label.TraefikBackendMaxConnAmount: "666",
|
||||
label.TraefikBackendMaxConnExtractorFunc: "client.ip",
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingRetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
|
||||
label.TraefikFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
||||
label.TraefikFrontendEntryPoints: "http,https",
|
||||
|
@ -228,6 +233,13 @@ func TestProviderBuildConfiguration(t *testing.T) {
|
|||
Port: 880,
|
||||
Interval: "6",
|
||||
},
|
||||
Buffering: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -856,6 +868,56 @@ func TestGetHealthCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetBuffering(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
service rancherData
|
||||
expected *types.Buffering
|
||||
}{
|
||||
{
|
||||
desc: "should return nil when no buffering labels",
|
||||
service: rancherData{
|
||||
Labels: map[string]string{},
|
||||
Health: "healthy",
|
||||
State: "active",
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when buffering labels are set",
|
||||
service: rancherData{
|
||||
Labels: map[string]string{
|
||||
label.TraefikBackendBufferingMaxResponseBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemResponseBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingMaxRequestBodyBytes: "10485760",
|
||||
label.TraefikBackendBufferingMemRequestBodyBytes: "2097152",
|
||||
label.TraefikBackendBufferingRetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
Health: "healthy",
|
||||
State: "active",
|
||||
},
|
||||
expected: &types.Buffering{
|
||||
MaxResponseBodyBytes: 10485760,
|
||||
MemResponseBodyBytes: 2097152,
|
||||
MaxRequestBodyBytes: 10485760,
|
||||
MemRequestBodyBytes: 2097152,
|
||||
RetryExpression: "IsNetworkError() && Attempts() <= 2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actual := getBuffering(test.service)
|
||||
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServers(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue