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

Use sanic-limiter to throttle api requests #235

Merged
merged 3 commits into from
Dec 27, 2023
Merged

Conversation

pankajkoti
Copy link
Contributor

@pankajkoti pankajkoti commented Dec 26, 2023

Throttles API requests based on user's IP address.
With this PR, at the moment, we are only throttling /requests endpoint.

closes: #230

Copy link

cloudflare-pages bot commented Dec 26, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9438371
Status: ✅  Deploy successful!
Preview URL: https://9855bce3.ask-astro.pages.dev
Branch Preview URL: https://230-throttle-api.ask-astro.pages.dev

View logs

@pankajkoti
Copy link
Contributor Author

Throttling in action

Screenshot 2023-12-26 at 5 07 54 PM

Copy link
Collaborator

@jlaneve jlaneve left a comment

Choose a reason for hiding this comment

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

I don’t know if these rates are permissive enough - the UI polls the API every few seconds

what’s the intent behind this? can we gate just the “submit prompt” endpoint?

@pankajkoti
Copy link
Contributor Author

pankajkoti commented Dec 26, 2023

I don’t know if these rates are permissive enough - the UI polls the API every few seconds

what’s the intent behind this? can we gate just the “submit prompt” endpoint?

yes, we can very well do route based throttling. I thought the UI would not poll more than a certain number of times per minute for the requests/request_id endpoint, no? Also those limits can be configured via environment variables, I just kept some default values for those.

The context for the intent is here though: https://astronomer.slack.com/archives/C05QJA9LTR9/p1703159886303619 (this has been linked in the issue #230 description)

@pankajastro
Copy link
Collaborator

pankajastro commented Dec 27, 2023

LGTM. This will have no impact on the Slack path since it does not make rest API calls, right?
https://github.com/astronomer/ask-astro/blob/main/api/ask_astro/slack/controllers/mention.py#L119

@pankajkoti
Copy link
Contributor Author

LGTM. This will have no impact on the Slack path since it does not make rest API calls, right? https://github.com/astronomer/ask-astro/blob/main/api/ask_astro/slack/controllers/mention.py#L119

yes, correct it won't impact Slack calls. However, Slack could impose rate limits by itself based on the limits specified here https://api.slack.com/apis/rate-limits

Copy link
Collaborator

@pankajastro pankajastro left a comment

Choose a reason for hiding this comment

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

LGTM

ui/src/routes/+page.server.ts Outdated Show resolved Hide resolved
ui/src/routes/+page.server.ts Outdated Show resolved Hide resolved
ui/src/routes/+page.server.ts Outdated Show resolved Hide resolved
Co-authored-by: Ankit Chaurasia <8670962+sunank200@users.noreply.github.com>
@pankajkoti
Copy link
Contributor Author

Result after throttled requests endpoint post applying review suggestions.
Screenshot 2023-12-27 at 6 05 26 PM

@pankajkoti pankajkoti merged commit 935ee41 into main Dec 27, 2023
7 checks passed
@pankajkoti pankajkoti deleted the 230-throttle-api branch December 27, 2023 12:37
davidgxue added a commit that referenced this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check possibility for throttling Ask Astro requests
4 participants