Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limiting for frontends #2034

Merged
merged 1 commit into from Sep 9, 2017
Merged

Rate limiting for frontends #2034

merged 1 commit into from Sep 9, 2017

Conversation

bparli
Copy link
Contributor

@bparli bparli commented Aug 31, 2017

Description

This is to add a rate limiting capability in Traefik, as in #643

  • Integrate the oxy ratelimit package
  • Add Rate and RateLimit types for frontend configuration
  • Add rate limiting integration test
  • Update glide/vendor with new package dependencies
  • Add configuration example to basics doc

@@ -42,6 +42,7 @@ func init() {
check.Suite(&SimpleSuite{})
check.Suite(&TimeoutSuite{})
check.Suite(&WebsocketSuite{})
check.Suite(&RateLimitSuite{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this line to be in alphabetical order?

err = try.GetRequest("http://127.0.0.1:80/", 500*time.Millisecond, try.StatusCodeIs(http.StatusTooManyRequests))
c.Assert(err, checker.IsNil)

time.Sleep(3 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explains this line?

@@ -890,6 +891,30 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
}
}

if frontend.RateLimit != nil && len(frontend.RateLimit.RateSet) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you isolate this into a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have this comment addressed with the server.buildRateLimiter function I added. Of course, let me know if you had something else in mind though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you did exactly what I wanted👍

glide.lock Outdated
@@ -331,7 +337,7 @@ imports:
- name: github.com/Masterminds/semver
version: 59c29afe1a994eacb71c833025ca7acf874bb1da
- name: github.com/Masterminds/sprig
version: 9526be0327b26ad31aa70296a7b10704883976d5
version: e039e20e500c2c025d9145be375e27cf42a94174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this update is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this update doesn't seem to be necessary. After looking at this again, I'm actually sure not how to handle it though. For Masterminds/sprig, the versions don't seem to match between glide.yml and glide.lock. I'm not super familiar with glide, but I guess thats why glide went ahead with the update? Any advice is appreciated

glide.lock Outdated
@@ -95,6 +95,8 @@ imports:
- name: github.com/coreos/etcd
version: c400d05d0aa73e21e431c16145e558d624098018
subpackages:
- Godeps/_workspace/src/github.com/ugorji/go/codec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove those lines?

docs/basics.md Outdated
@@ -278,6 +278,32 @@ Security related headers (HSTS headers, SSL redirection, Browser XSS filter, etc

In this example, traffic routed through the first frontend will have the `X-Frame-Options` header set to `DENY`, and the second will only allow HTTPS request through, otherwise will return a 301 HTTPS redirect.

#### Rate limiting

Rate limiting can be configured per frontend. Multiple sets of rates can be added to each frontend, but the time periods must be unique.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put one sentence by line?

docs/basics.md Outdated
burst = 10
```

In the above example, frontend1 is configured to limit requests by the client's ip address. An average of 5 requests every 3 seconds is allowed and an average of 100 requests every 10 seconds. These can "burst" up to 10 and 200 in each period respectively.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put one sentence by line?

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this great PR.
I have just one suggestion about the integration test. 😉

time.Sleep(3 * time.Second)
err = try.GetRequest("http://127.0.0.1:80/", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK))
c.Assert(err, checker.IsNil)
}
Copy link
Contributor

@nmengin nmengin Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe can you set lesser values to frontends.frontend1.ratelimit.rateset.rateset1 (average = 4 and burst = 5?) in the toml file and check if this rateset is respected too in the TestSimpleConfiguration test or in another one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 You're right. Its a good idea to test that first time period too.

@bparli
Copy link
Contributor Author

bparli commented Sep 1, 2017

Thanks for the review and feedback guys. I think I have glide straightened out now

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏 👏

Copy link
Collaborator

@SantoDE SantoDE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great pr :) Brings in a new nifty feature.

LGTM 👼

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job !

LGTM

@trondhindenes
Copy link

I can't find the doc changes in this PR at https://docs.traefik.io/basics/, is there any reason for that?

@ldez
Copy link
Member

ldez commented Dec 7, 2017

@trondhindenes because it's a 1.5 features.
If you want to try 1.5, you can find the documentation here: https://docs.traefik.io/archive/ or http://v1-5.archive.docs.traefik.io/

@trondhindenes
Copy link

gotcha. Thanks!

@tobernguyen
Copy link

How can I use this in Traefik Ingress Controller on my Kubernetes cluster? Is there any way to set the rate limit using Annotations?

@ldez
Copy link
Member

ldez commented Dec 29, 2017

@tobernguyen For now, you cannot define rate limit with annotations.
This feature (k8s annotations for rate limit) come in v1.6: #2612

@tobernguyen
Copy link

@ldez that's awesome! Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement a new or improved feature. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants