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

feat: Adds rate limiting to metric POST endpoints #5075

Merged
merged 5 commits into from
Oct 18, 2023
Merged

Conversation

chriswk
Copy link
Member

@chriswk chriswk commented Oct 17, 2023

What

The heaviest requests we serve are the register and metrics POSTs from our SDKs/clients.
This PR adds ratelimiting to /api/client/register, /api/client/metrics, /api/frontend/register and /api/frontend/metrics with a default set to 6000 requests per minute (or 100 rps) for each of the endpoints.

It will be overrideable by the environment variables documented.

Points of discussion

@kwasniew already suggested using featuretoggles with variants to control the rate per clientId. I struggled to see if we could dynamically update the middleware after initialisation, so this attempt will need a restart of the pod to update the request limit.

@chriswk chriswk self-assigned this Oct 17, 2023
@vercel
Copy link

vercel bot commented Oct 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 10:38am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 10:38am

Copy link
Contributor

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

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

I like it, but I'd consider renaming the variables for easier configuration

src/lib/create-config.ts Outdated Show resolved Hide resolved
src/lib/routes/util.ts Outdated Show resolved Hide resolved
@chriswk chriswk force-pushed the feat/rateLimitMetrics branch from d92a752 to 9499986 Compare October 18, 2023 10:26
@chriswk chriswk merged commit b06613d into main Oct 18, 2023
12 of 14 checks passed
@chriswk chriswk deleted the feat/rateLimitMetrics branch October 18, 2023 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants