简体   繁体   中英

Traefik rate-limiting with docker labels

I have problems setting up rateimiting with labels for docker backends using traefik 1.5-rc3

Setting the following labels

# enable rate limitation on frontend per IP. 5 Request avg per 3s, 15 Reqs in a row
# see https://github.com/containous/traefik/blob/v1.5/docs/configuration/commons.md#rate-limiting
      - "traefik.frontend.rateLimit.extractorFunc=client.ip"
      - "traefik.frontend.rateLimit.rateSet.r1.period=3s"
      - "traefik.frontend.rateLimit.rateSet.r1.average=5"
      - "traefik.frontend.rateLimit.rateSet.r1.burst=15"
      - "traefik.frontend.rateLimit.rateSet.r2.period=10s"
      - "traefik.frontend.rateLimit.rateSet.r2.average=50"
      - "traefik.frontend.rateLimit.rateSet.r2.burst=100"

Does not print any rate-limiting output in the logfiles, nor is the configuration visible eg in the /api frontend structure: There is no error message or anything:

time="2018-01-17T16:11:08Z" level=debug msg="Could not load traefik.frontend.whitelistSourceRange labels"
time="2018-01-17T16:11:08Z" level=debug msg="Could not load traefik.frontend.auth.basic labels"
time="2018-01-17T16:11:08Z" level=debug msg="Validation of load balancer method for backend backend-xxx-xxx-1-xxx-xxxx-default failed: invalid load-balancing method ''. Using default method wrr."
time="2018-01-17T16:11:08Z" level=debug msg="Configuration received from provider docker: {"backends":{"backend-xxx-xxx-1-xxx-xxx-default":{"servers":{"service-0":{"url":"http://172.20.0.5:3000","weight":0}},"loadBalancer":{"method":"wrr"}},"backend-xxx-xxx":{"loadBalancer":{"method":"wrr"},"maxConn":{"amount":10,"extractorFunc":"request.host"}}},"frontends":{"frontend-xxx-xxx-1-xxx-xxx-default":{"entryPoints":["http"],"backend":"backend-xxx-xxx-1-xxx-xxx-default","routes":{"service-default":{"rule":"Host:localhost"}},"passHostHeader":true,"priority":0,"basicAuth":[]}}}"

Same configuration in a static configuration toml:

[frontends.xxx.ratelimit]
extractorfunc = "client.ip"
    [frontends.xxx.ratelimit.rateset.rateset1]
    period = "10s"
    average = 100
    burst = 200
    [frontends.xxx.ratelimit.rateset.rateset2]
    period = "3s"
    average = 5
    burst = 10

seems to work, because the logging states Creating load-balancer rate limiter :

{"loadBalancer":{"method":"wrr"}}},"frontends":{"xxx":{"entryPoints":["http"],"backend":"xxx","routes":{"test_1":{"rule":"Host:xxx,localhost"}},"priority":0,"basicAuth":null,"ratelimit":{"rateset":{"rateset1":{"period":10000000000,"average":100,"burst":200},"rateset2":{"period":3000000000,"average":5,"burst":10}},"extractorFunc":"client.ip"}}}}"
...
time="2018-01-17T16:11:08Z" level=debug msg="Creating backend xxx"
time="2018-01-17T16:11:08Z" level=debug msg="Creating load-balancer wrr"
time="2018-01-17T16:11:08Z" level=debug msg="Creating load-balancer rate limiter"
time="2018-01-17T16:11:08Z" level=debug msg="Creating retries max attempts 0"

Looking at the source-code labels seems to be fine.

What am I missing ? I just noted, the different casing on extractorfunc (backend) and extractorFunc (frontend) in the parsing methods.

What needs to be done to setup rate limits via labels?

The PR that you are watching ( https://github.com/containous/traefik/pull/2584 ) is for the 1.6.

You can see the version in the milestone section of the PR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM