-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: Add rate limiter to GQL endpoint #750
Conversation
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
📢 Thoughts on this report? Let us know! |
❌ 5 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time. ❌ Failed Test Results:Completed 2262 tests with View the full list of failed testspytest
|
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #750 +/- ##
===========================================
Coverage 96.14000 96.14000
===========================================
Files 812 812
Lines 18430 18459 +29
===========================================
+ Hits 17719 17747 +28
- Misses 711 712 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if user_id: | ||
key = f"rl-user:{user_id}" | ||
else: | ||
key = f"rl-ip:{user_ip}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just fetch the ip here? Seems like we don't use it unless the user id does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will make the change
Purpose/Motivation
This PR aims to add a rate limiter to our graphQL endpoint, with two different "key" mechanisms depending on if the user is logged in or not.
Our first check will check for the user being logged in, and having a "pk" on their user object passed into the request. If they do have this value, we will use it as the basis for their rate limit. If they don't have this value (i.e. their just a guest or not logged in), we will fall back to trying to derive their IP address via some request headers being passed in. From my investigation on which headers are typically defined with an IP address, it seemed to be either via x_forwarded_at or remote_addr. We'll use the former but fallback to the latter if it doesn't exist. In the event none of those exist we're a little S.O.L, but we can monitor on the initial launch and test on stage prior to see if we can "break it" before going to prod
Outside of that stuff though, the rate limiter implementation is pretty straight forward. You get a flat 300 req/min per "key," and we can easily modify and extend this implementation to include daily rate limits too if we want.
Links to relevant tickets
Closes codecov/engineering-team#2148
Testing
Screenshots
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.