Request buffering middleware
This commit is contained in:
parent
d426126a92
commit
a81171d5f1
44 changed files with 2155 additions and 5 deletions
|
@ -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")),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue