feat: Implement persistence bypass based on caller type#7656
Conversation
…imiter Signed-off-by: fimanishi <fimanishi@gmail.com>
Signed-off-by: fimanishi <fimanishi@gmail.com>
Signed-off-by: fimanishi <fimanishi@gmail.com>
✅ Code Review UpdateThe test bug has been fixed! The new commit successfully addresses the issue: What was fixed:
Remaining Minor Items: The performance consideration about re-reading the bypass list on every request is still present, but this is a minor optimization that doesn't block the PR. Dynamic config reads are typically cached, so the overhead should be minimal. PR Status: Ready for merge once CI passes ✅ |
Signed-off-by: fimanishi <fimanishi@gmail.com>
✅ Code Review Complete - All Issues ResolvedSummary: This PR is ready for merge once CI completes. All code review findings have been addressed through iterative improvements. Changes Made Through Review Iterations:Commit 1: Initial Implementation (
Commit 2: Fix and improve wrappers_test (
Commit 3: Improve bypass performance (
Final Implementation Quality:✅ Correctness: Properly handles all caller types with explicit config Waiting for: CI checks to complete before merge. |
✅ Excellent Performance Optimization!The latest commit addresses the performance concern perfectly! What Changed: // Before: checked on every request
callerInfo := types.GetCallerInfoFromContext(ctx)
if c.shouldBypassRateLimit(callerInfo.GetCallerType()) {
return c.wrapped.Method(ctx, request)
}
if ok := c.rateLimiter.Allow(); !ok {
err = ErrPersistenceLimitExceeded
return
}
// After: only checked when rate limit is exceeded
if ok := c.rateLimiter.Allow(); !ok {
callerInfo := types.GetCallerInfoFromContext(ctx)
if c.shouldBypassRateLimit(callerInfo.GetCallerType()) {
return c.wrapped.Method(ctx, request)
}
err = ErrPersistenceLimitExceeded
return
}Performance Impact:
This is a smart optimization that eliminates the overhead I mentioned while keeping all the benefits of dynamic bypass configuration. Great work! 🎉 Status: All code review concerns have been addressed. PR looks excellent! |
Signed-off-by: fimanishi <fimanishi@gmail.com>
✅ Additional Test Coverage AddedThe latest commit adds comprehensive test coverage for other persistence managers: New Tests Added:
Test Pattern:
Current PR Status:
Excellent work ensuring comprehensive test coverage across all persistence managers! This gives high confidence in the feature's correctness. |
Code Review Status UpdateClarification on Performance Optimization: The code review tool flagged the performance concern as "unresolved", but this is incorrect. The performance optimization from commit Current Implementation (Optimized): if ok := c.rateLimiter.Allow(); !ok {
// Bypass check ONLY happens when rate limit is exceeded
callerInfo := types.GetCallerInfoFromContext(ctx)
if c.shouldBypassRateLimit(callerInfo.GetCallerType()) {
return c.wrapped.Method(ctx, request)
}
err = ErrPersistenceLimitExceeded
return
}
// Normal path when rate limits are not exceeded
return c.wrapped.Method(ctx, request)Performance Characteristics:
Test Coverage:
Conclusion: All code review concerns have been fully addressed. The PR is production-ready. |
Code Review ✅ Approved 1 resolved / 2 findingsWell-implemented feature with comprehensive tests. The minor performance concern about reading dynamic config on every request follows the established codebase pattern and remains as a minor suggestion. 💡 Performance: Bypass list is re-read from dynamic config on every request📄 common/persistence/wrappers/templates/ratelimited.tmpl:69 The bypassCallerTypes := c.dc.GetListProperty(dynamicproperties.PersistenceRateLimiterBypassCallerTypes)()While Cadence's dynamic config likely has caching, this pattern still involves:
For a high-throughput persistence layer, this could add measurable overhead. Consider:
This is a minor optimization concern since dynamic config reads are typically efficient, but worth noting for a hot path. ✅ 1 resolved✅ Bug: First test assumes "cli" is default bypass type, but default is empty
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
| } | ||
|
|
||
| if ok := c.rateLimiter.Allow(); !ok { | ||
| callerInfo := types.GetCallerInfoFromContext(ctx) |
There was a problem hiding this comment.
Adding this on the limit-path was a nice touch. Nice!
What changed?
Added bypass using callerType to persistence rate limiter #7654
Why?
Persistence rate limiter does not discriminate between call/caller types. There may be situations that we need some requests to be allowed for debugging/mitigation purposes even if the rate limit has been reached. This change allows the definition of a list of caller type to be bypassed in the persistence rate limiter.
How did you test it?
Added tests to common/persistence/wrappers/ratelimited/wrappers_test.go
Potential risks
A new dynamic config "persistence.rateLimiterBypassCallerTypes" was introduced, which accepts a list of strings based on the caller type. Persistence rate limiter will be bypassed if the callerType for the request is in that list
Release notes
Introduced bypass based on callerType for persistence rate limiter
Documentation Changes
N/A
Reviewer Validation
PR Description Quality (check these before reviewing code):
go testinvocation)