-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: custom /query rate limit when using personal API key #28184
base: master
Are you sure you want to change the base?
Conversation
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.
PR Summary
This PR adds a new team property api_query_rate_limit
to enable customizable rate limits for API queries when using personal API keys. Here are the key changes:
- Added
api_query_rate_limit
CharField to Team model with validation for rate limit formats like '100/hour', '5/min' - Modified
PersonalApiKeyRateThrottle
class to support custom rate limits through newload_team_rate_limit
method - Added validation function
validate_rate_limit
in utils.py to ensure proper rate limit format using regex pattern - Created migration 0559 to add the new nullable field with max length of 32 characters
- Added test cases to verify rate limit format validation rejects invalid formats like '1/week' while accepting valid ones like '1/s'
The implementation looks solid but there are a few potential concerns:
- Consider adding documentation on supported rate limit formats and validation rules
- The commented-out test exception in query.py should be removed
- May want to add validation to prevent extremely high rate limits that could impact system stability
10 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile
"set custom rate limit", extra={"rate_limit_cache_key": rate_limit_cache_key, "rate_limit": self.rate} | ||
) | ||
|
||
self.num_requests, self.duration = self.parse_rate(self.rate) |
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.
logic: parse_rate() could raise ValueError for invalid rate string formats. Add error handling here.
1121456
to
a1e3353
Compare
ebbf909
to
db97a9c
Compare
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.
lgtm!
83184fe
to
5d6fab2
Compare
Problem
Some users want to send more than 120 queries per hour.
Changes
Does this work well for both Cloud and self-hosted?
Yes.
How did you test this code?
Added test and check locally.