Re enable ratelimit integration tests
This commit is contained in:
parent
3ed57e01a6
commit
b8ed6f1588
10 changed files with 41 additions and 79 deletions
Binary file not shown.
Before Width: | Height: | Size: 68 KiB |
|
@ -3,8 +3,6 @@
|
||||||
To Control the Number of Requests Going to a Service
|
To Control the Number of Requests Going to a Service
|
||||||
{: .subtitle }
|
{: .subtitle }
|
||||||
|
|
||||||
![RateLimit](../assets/img/middleware/ratelimit.png)
|
|
||||||
|
|
||||||
The RateLimit middleware ensures that services will receive a _fair_ number of requests, and allows you define what is fair.
|
The RateLimit middleware ensures that services will receive a _fair_ number of requests, and allows you define what is fair.
|
||||||
|
|
||||||
## Configuration Example
|
## Configuration Example
|
||||||
|
|
|
@ -309,8 +309,6 @@ func (s *AccessLogSuite) TestAccessLogFrontendRedirect(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
|
func (s *AccessLogSuite) TestAccessLogRateLimit(c *check.C) {
|
||||||
c.Skip("RateLimit is disable for now")
|
|
||||||
|
|
||||||
ensureWorkingDirectoryIsClean()
|
ensureWorkingDirectoryIsClean()
|
||||||
|
|
||||||
expected := []accessLogValue{
|
expected := []accessLogValue{
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
[http.routers]
|
[http.routers]
|
||||||
[http.routers.router1]
|
[http.routers.router1]
|
||||||
Service = "service1"
|
Service = "service1"
|
||||||
Middlewares = ["retry", "ratelimit"]
|
Middlewares = ["retry", "ratelimit-1"]
|
||||||
Rule = "Path(`/ratelimit`)"
|
Rule = "Path(`/ratelimit`)"
|
||||||
[http.routers.router2]
|
[http.routers.router2]
|
||||||
Service = "service2"
|
Service = "service2"
|
||||||
|
@ -44,16 +44,9 @@
|
||||||
attempts = 3
|
attempts = 3
|
||||||
[http.middlewares.basic-auth.basicAuth]
|
[http.middlewares.basic-auth.basicAuth]
|
||||||
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
||||||
[http.middlewares.ratelimit.rateLimit]
|
[http.middlewares.ratelimit-1.rateLimit]
|
||||||
extractorfunc = "client.ip"
|
average = 1
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset1]
|
burst = 2
|
||||||
period = "60s"
|
|
||||||
average = 4
|
|
||||||
burst = 5
|
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset2]
|
|
||||||
period = "3s"
|
|
||||||
average = 1
|
|
||||||
burst = 2
|
|
||||||
|
|
||||||
|
|
||||||
[http.services]
|
[http.services]
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
[http.routers]
|
[http.routers]
|
||||||
[http.routers.router1]
|
[http.routers.router1]
|
||||||
Service = "service1"
|
Service = "service1"
|
||||||
Middlewares = ["retry", "ratelimit"]
|
Middlewares = ["retry", "ratelimit-1"]
|
||||||
Rule = "Path(`/ratelimit`)"
|
Rule = "Path(`/ratelimit`)"
|
||||||
[http.routers.router2]
|
[http.routers.router2]
|
||||||
Service = "service2"
|
Service = "service2"
|
||||||
|
@ -43,17 +43,9 @@
|
||||||
attempts = 3
|
attempts = 3
|
||||||
[http.middlewares.basic-auth.basicAuth]
|
[http.middlewares.basic-auth.basicAuth]
|
||||||
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
||||||
[http.middlewares.ratelimit.rateLimit]
|
[http.middlewares.ratelimit-1.rateLimit]
|
||||||
extractorfunc = "client.ip"
|
average = 1
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset1]
|
burst = 2
|
||||||
period = "60s"
|
|
||||||
average = 4
|
|
||||||
burst = 5
|
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset2]
|
|
||||||
period = "3s"
|
|
||||||
average = 1
|
|
||||||
burst = 2
|
|
||||||
|
|
||||||
|
|
||||||
[http.services]
|
[http.services]
|
||||||
[http.services.service1]
|
[http.services.service1]
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
[http.routers]
|
[http.routers]
|
||||||
[http.routers.router1]
|
[http.routers.router1]
|
||||||
service = "service1"
|
service = "service1"
|
||||||
middlewares = ["retry", "ratelimit"]
|
middlewares = ["retry", "ratelimit-1"]
|
||||||
rule = "Path(`/ratelimit`)"
|
rule = "Path(`/ratelimit`)"
|
||||||
[http.routers.router2]
|
[http.routers.router2]
|
||||||
service = "service2"
|
service = "service2"
|
||||||
|
@ -40,16 +40,9 @@
|
||||||
attempts = 3
|
attempts = 3
|
||||||
[http.middlewares.basic-auth.basicAuth]
|
[http.middlewares.basic-auth.basicAuth]
|
||||||
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
|
||||||
[http.middlewares.ratelimit.rateLimit]
|
[http.middlewares.ratelimit-1.rateLimit]
|
||||||
extractorfunc = "client.ip"
|
average = 1
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset1]
|
burst = 2
|
||||||
period = "60s"
|
|
||||||
average = 4
|
|
||||||
burst = 5
|
|
||||||
[http.middlewares.ratelimit.rateLimit.rateSet.rateset2]
|
|
||||||
period = "3s"
|
|
||||||
average = 1
|
|
||||||
burst = 2
|
|
||||||
|
|
||||||
[http.services]
|
[http.services]
|
||||||
[http.services.service1]
|
[http.services.service1]
|
||||||
|
|
|
@ -55,19 +55,17 @@ frontendRedirect:
|
||||||
- traefik.http.middlewares.redirecthttp.redirectScheme.scheme=http
|
- traefik.http.middlewares.redirecthttp.redirectScheme.scheme=http
|
||||||
- traefik.http.middlewares.redirecthttp.redirectScheme.port=8000
|
- traefik.http.middlewares.redirecthttp.redirectScheme.port=8000
|
||||||
- traefik.http.services.service3.loadbalancer.server.port=80
|
- traefik.http.services.service3.loadbalancer.server.port=80
|
||||||
# TODO: disable temporarily (rateLimit)
|
rateLimit:
|
||||||
#rateLimit:
|
image: containous/whoami
|
||||||
# image: containous/whoami
|
labels:
|
||||||
# labels:
|
- traefik.enable=true
|
||||||
# - traefik.enable=true
|
- traefik.http.routers.rt-rateLimit.entryPoints=httpRateLimit
|
||||||
# - traefik.http.routers.rt-rateLimit.entryPoints=httpRateLimit
|
- traefik.http.routers.rt-rateLimit.rule=Host("ratelimit.docker.local")
|
||||||
# - traefik.http.routers.rt-rateLimit.rule=Host("ratelimit.docker.local")
|
- traefik.http.routers.rt-rateLimit.middlewares=rate
|
||||||
# - traefik.http.routers.rt-rateLimit.middlewares=rate
|
- traefik.http.middlewares.rate.ratelimit
|
||||||
# - traefik.http.middlewares.rate.ratelimit.extractorfunc=client.ip
|
- traefik.http.middlewares.rate.ratelimit.average=1
|
||||||
# - traefik.http.middlewares.rate.ratelimit.rateset.Rate0.average=1
|
- traefik.http.middlewares.rate.ratelimit.burst=2
|
||||||
# - traefik.http.middlewares.rate.ratelimit.rateset.Rate0.burst=2
|
- traefik.http.services.service3.loadbalancer.server.port=80
|
||||||
# - traefik.http.middlewares.rate.ratelimit.rateset.Rate0.period=10s
|
|
||||||
# - traefik.http.services.service3.loadbalancer.server.port=80
|
|
||||||
frontendWhitelist:
|
frontendWhitelist:
|
||||||
image: containous/whoami
|
image: containous/whoami
|
||||||
labels:
|
labels:
|
||||||
|
|
|
@ -41,8 +41,6 @@ func (s *TracingSuite) startZipkin(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
||||||
c.Skip("RateLimit is disable for now")
|
|
||||||
|
|
||||||
s.startZipkin(c)
|
s.startZipkin(c)
|
||||||
defer s.composeProject.Stop(c, "zipkin")
|
defer s.composeProject.Stop(c, "zipkin")
|
||||||
file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{
|
file := s.adaptFile(c, "fixtures/tracing/simple-zipkin.toml", TracingTemplate{
|
||||||
|
@ -88,7 +86,7 @@ func (s *TracingSuite) TestZipkinRateLimit(c *check.C) {
|
||||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit@file"))
|
err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit-1@file"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,8 +155,6 @@ func (s *TracingSuite) startJaeger(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TracingSuite) TestJaegerRateLimit(c *check.C) {
|
func (s *TracingSuite) TestJaegerRateLimit(c *check.C) {
|
||||||
c.Skip("RateLimit is disable for now")
|
|
||||||
|
|
||||||
s.startJaeger(c)
|
s.startJaeger(c)
|
||||||
defer s.composeProject.Stop(c, "jaeger")
|
defer s.composeProject.Stop(c, "jaeger")
|
||||||
file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{
|
file := s.adaptFile(c, "fixtures/tracing/simple-jaeger.toml", TracingTemplate{
|
||||||
|
@ -200,13 +196,11 @@ func (s *TracingSuite) TestJaegerRateLimit(c *check.C) {
|
||||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
time.Sleep(3 * time.Second)
|
|
||||||
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
err = try.GetRequest("http://127.0.0.1:8000/ratelimit", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit@file"))
|
err = try.GetRequest("http://"+s.IP+":16686/api/traces?service=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit-1@file"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TracingSuite) TestJaegerRetry(c *check.C) {
|
func (s *TracingSuite) TestJaegerRetry(c *check.C) {
|
||||||
|
|
|
@ -249,16 +249,14 @@
|
||||||
prefixes = ["foobar", "foobar"]
|
prefixes = ["foobar", "foobar"]
|
||||||
[http.middlewares.Middleware10]
|
[http.middlewares.Middleware10]
|
||||||
[http.middlewares.Middleware10.rateLimit]
|
[http.middlewares.Middleware10.rateLimit]
|
||||||
extractorFunc = "foobar"
|
average = 42
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet]
|
burst = 42
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet.Rate0]
|
[http.middlewares.Middleware10.rateLimit.sourceCriterion]
|
||||||
period = 42000000000
|
requestHeaderName = "foobar"
|
||||||
average = 42
|
requestHost = true
|
||||||
burst = 42
|
[http.middlewares.Middleware10.rateLimit.sourceCriterion.ipStrategy]
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet.Rate1]
|
depth = 42
|
||||||
period = 42000000000
|
excludedIPs = ["foobar", "foobar"]
|
||||||
average = 42
|
|
||||||
burst = 42
|
|
||||||
[http.middlewares.Middleware11]
|
[http.middlewares.Middleware11]
|
||||||
[http.middlewares.Middleware11.redirectRegex]
|
[http.middlewares.Middleware11.redirectRegex]
|
||||||
regex = "foobar"
|
regex = "foobar"
|
||||||
|
|
|
@ -240,16 +240,14 @@
|
||||||
prefixes = ["foobar", "foobar"]
|
prefixes = ["foobar", "foobar"]
|
||||||
[http.middlewares.Middleware10]
|
[http.middlewares.Middleware10]
|
||||||
[http.middlewares.Middleware10.rateLimit]
|
[http.middlewares.Middleware10.rateLimit]
|
||||||
extractorFunc = "foobar"
|
average = 42
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet]
|
burst = 42
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet.Rate0]
|
[http.middlewares.Middleware10.rateLimit.sourceCriterion]
|
||||||
period = 42000000000
|
requestHeaderName = "foobar"
|
||||||
average = 42
|
requestHost = true
|
||||||
burst = 42
|
[http.middlewares.Middleware10.rateLimit.sourceCriterion.ipStrategy]
|
||||||
[http.middlewares.Middleware10.rateLimit.rateSet.Rate1]
|
depth = 42
|
||||||
period = 42000000000
|
excludedIPs = ["foobar", "foobar"]
|
||||||
average = 42
|
|
||||||
burst = 42
|
|
||||||
[http.middlewares.Middleware11]
|
[http.middlewares.Middleware11]
|
||||||
[http.middlewares.Middleware11.redirectRegex]
|
[http.middlewares.Middleware11.redirectRegex]
|
||||||
regex = "foobar"
|
regex = "foobar"
|
||||||
|
|
Loading…
Reference in a new issue