-
-
Notifications
You must be signed in to change notification settings - Fork 61
ref(ratelimiter): Reduce redis socket timeout and emit metric on timeout #7662
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
Conversation
Reduce the rate limiter Redis socket timeout from 0.5s to 0.1s to fail faster when Redis is slow or unavailable. Additionally, emit a metric (ratelimiter_redis_timeout) when a timeout occurs to enable monitoring. Co-Authored-By: Claude Opus 4.5 <[email protected]>
| pipe.expire(query_bucket, max_query_duration_s) | ||
| pipe.execute() | ||
| except Exception as ex: | ||
| logger.exception(ex) |
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.
you don't want to log this exeption. it just becomes a sentry error and we want to avoid that.
Only emit metric for Redis timeout errors without logging, since timeouts are expected when Redis is slow and logging would be noisy. Other exceptions continue to be logged. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
Also, I don't think this is where we want to try/catch things. All of these errors happen in the allocation policy and this is not the only rate limiter that we use. (We also use a sliding window rate limiter for different policies). I think this change is better made in |
The metric is already emitted in the dedicated RedisTimeoutError handler, so no need to check for it again in the generic Exception handler. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Consolidate the error return path by using a finally block to check if an exception occurred and return the fail-open stats. Co-Authored-By: Claude Opus 4.5 <[email protected]>
a3c3671 to
c7f29b1
Compare
Move the RedisTimeoutError handling from rate_limit.py to allocation_policies/__init__.py. This covers all rate limiters (including sliding window) since they all go through the allocation policy base class. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
ratelimiter_redis_timeoutwhen a Redis timeout occurs, tagged with the function (start_requestorfinish_request) where it happenedTest plan
ratelimiter_redis_timeoutmetric🤖 Generated with Claude Code