-
Notifications
You must be signed in to change notification settings - Fork 50
Conversation
API Developer Docs Preview: Ready https://wordpress.github.io/openverse-api/_preview/792 Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again. You can check the GitHub pages deployment action list to see the current status of the deployments. |
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.
Looks good to me!
|
||
* `standard`: The default rate limit that anyone is able to unlock simply by authenticating. Slightly higher and much more useful limit for an application. | ||
* `enhanced`: A selectively granted rate limit that allows for significantly higher burst and sustained requests. | ||
* `exempt`: A rate limit model that exists purely to accommodate internal infrastructural needs. For example, the server that renders the frontend can use tokens of this tier to prevent itself from being rate limited by the API during server side rendering. Likewise, when we need to circumvent the throttling to do load testing, we use a key of this tier. |
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.
These tiers are so well-named.
I'm having trouble initializing the API:
|
@obulat you need to rebuild the $ docker-compose build web |
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.
Looks good, thanks for the extra documentation! I just have two notes.
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.
I wasn't able to get the testing steps to work locally, even when I set my application to exempt
I was still getting throttled with that key 😕 I feel like I must be doing something wrong, but I'm not sure where. I'm confident in the code though, and I know this is currently blocking. If someone else was able to get the testing steps working please let me know!
To verify some things, @AetherUnbound, as it concerns me that you weren't able to get it to work. Did you run migrations ( I left out the instructions to run the migration from the PR description, sorry if that is the issue! |
I did run the migration, but that was after I made the application 🤔 do you think that would have had an effect? I'll try recreate + init! |
I'm not sure! It would be a bad sign if it did cause a problem as that would be one of the situations we'll run into when we migrate some of the existing "exempted" applications 🤔 |
Which reminds me... we will have to be careful when we deploy this PR. We'll have to run the migrations, then update the rate_limit_model for currently exempted applications, then deploy the rest of the PR. Interesting to note that with automated deployments we won't be able to follow this manual process... in those cases we'd have to split this PR into two:
We are still months from that scenario but it is something for us to start thinking about now so we're not caught off guard when the time does come. |
Ah okay, I got it working! I also had to set the throttled application as "verified". One other thing to note though, the Admin UI required that I set a value for |
It's not an issue, we can just set it to public I guess? Or we could fix it in this PR and include a data migration to update existing applications to have public set explicitly. I'm not sure why it's able to be empty 🤔 The column is configured like this:
https://github.com/jazzband/django-oauth-toolkit/blob/master/oauth2_provider/models.py#L106 Kind of strange, no? |
What is the correct path for running migrations? I couldn't pass the API healthcheck, so I ran |
@obulat can you run |
I can no longer reproduce the API error; it works well after I ran the migrations inside the web shell. But it was something about missing relations in the database. |
I checked this again on #808 (which is off of |
Fixes
Fixes #585 by @sarayourfriend
Unblocks WordPress/openverse-frontend#1558
Description
Removes the throttle exemption classes and switches to just using the scoped OAuth tokens. While that is also bespoke, it already exists and this allows us to delete a substantial amount of hot-path code 🙂
I wrote some documentation to describe the state of the throttling and authentication world. Please read that, then read this section unless you're already familiar with concepts like rate limit models and throttle scopes (and how they're related).
This PR adds a new rate limit model of "exempt" and ties it to a scope with
None
throttling configuration, which is the same as setting it to infinity. This truly exempts the requester from all rate limiting, just like how the frontend is currently exempting itself via IP address.In the interest of now having to coordinate a complicated deployment, I've left the IP based throttling in for now.
Before deploying this PR we MUST update the WordPress.com/Jetpack application to have the exempt rate limit model in order to maintain the current behavior of that application.
Testing Instructions
Note that in addition to below I've also added comprehensive unit tests to the throttling module. If you notice anything missing, please let me know so I can add it.
Please also review the documentation I added and let me know if it needs any clarification.
To test this locally, I recommend using the load testing script from this PR: WordPress/openverse#257
Update settings.py to:
host.docker.internal
on Docker Desktop or172.17.0.1
otherwise.Next create an application and token by following the authentication flow on your local API. Open up Django admin to be able to move the application between the different rate limit models.
I would start by first testing anonymous rate limiting by putting a bogus api key in the load testing script. Confirm that you're quickly rate limited.
Next, use your actual key. Fiddle with the
api.sh
variables of requests and concurrency until you surpass the rate limit. This is testing the "standard" model.Move the application into the "enhanced" model and do the same. You should be able to overwhelm this throttle by setting the api load testing script to make a little over 200 requests, maybe slightly more due to throttle race conditions. Use 300 and you'll definitely see it rate limit.
Now move the application into the "exempt" model and repeat. You can make the number of requests as high as you want, but you'll never get throttled.
Add your local IP to the
ip-whitelist
in your local redis. I don't know what the best way to find this IP is, it might be different per computer. I just put a breakpoint in a request and check to see what the IP of the request is from inside the API.Run
just exec cache bash
thenredis-cli
. Add your IP toip-whitelist
by running:Note the quotes are significant here!
Without restarting your API (because the cache is not persistent between restarts on local), make the same anonymous api load testing requests and confirm that you are likewise never throttled.
We will remove this final behavior in a subsequent PR once the frontend has been migrated to use API keys to circumvent the rate limiting.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin