-
Notifications
You must be signed in to change notification settings - Fork 465
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
Fix shadow mode metric is not collected when local cache hit #424
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,14 +61,12 @@ func (this *fixedRateLimitCacheImpl) DoLimit( | |
|
||
// Check if key is over the limit in local cache. | ||
if this.baseRateLimiter.IsOverLimitWithLocalCache(cacheKey.Key) { | ||
|
||
if limits[i].ShadowMode { | ||
logger.Debugf("Cache key %s would be rate limited but shadow mode is enabled on this rule", cacheKey.Key) | ||
} else { | ||
logger.Debugf("cache key is over the limit: %s", cacheKey.Key) | ||
isOverLimitWithLocalCache[i] = true | ||
} | ||
|
||
isOverLimitWithLocalCache[i] = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
continue | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -564,6 +564,7 @@ func TestOverLimitWithLocalCacheShadowRule(t *testing.T) { | |||||||||||
assert.Equal(uint64(3), limits[0].Stats.TotalHits.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.OverLimit.Value()) | ||||||||||||
assert.Equal(uint64(0), limits[0].Stats.OverLimitWithLocalCache.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.ShadowMode.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.NearLimit.Value()) | ||||||||||||
assert.Equal(uint64(2), limits[0].Stats.WithinLimit.Value()) | ||||||||||||
|
||||||||||||
|
@@ -579,15 +580,17 @@ func TestOverLimitWithLocalCacheShadowRule(t *testing.T) { | |||||||||||
// The result should be OK since limit is in ShadowMode | ||||||||||||
assert.Equal( | ||||||||||||
[]*pb.RateLimitResponse_DescriptorStatus{ | ||||||||||||
{Code: pb.RateLimitResponse_OK, CurrentLimit: limits[0].Limit, LimitRemaining: 15, DurationUntilReset: utils.CalculateReset(&limits[0].Limit.Unit, timeSource)}, | ||||||||||||
{Code: pb.RateLimitResponse_OK, CurrentLimit: limits[0].Limit, LimitRemaining: 0, DurationUntilReset: utils.CalculateReset(&limits[0].Limit.Unit, timeSource)}, | ||||||||||||
}, | ||||||||||||
cache.DoLimit(context.Background(), request, limits)) | ||||||||||||
// TODO: How should we handle statistics? Should there be a separate ShadowMode statistics? Should the other Stats remain as if they were unaffected by shadowmode? | ||||||||||||
|
||||||||||||
// Even if you hit the local cache, other metrics should increase normally. | ||||||||||||
assert.Equal(uint64(4), limits[0].Stats.TotalHits.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.OverLimit.Value()) | ||||||||||||
assert.Equal(uint64(0), limits[0].Stats.OverLimitWithLocalCache.Value()) | ||||||||||||
assert.Equal(uint64(2), limits[0].Stats.OverLimit.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.OverLimitWithLocalCache.Value()) | ||||||||||||
assert.Equal(uint64(2), limits[0].Stats.ShadowMode.Value()) | ||||||||||||
assert.Equal(uint64(1), limits[0].Stats.NearLimit.Value()) | ||||||||||||
assert.Equal(uint64(3), limits[0].Stats.WithinLimit.Value()) | ||||||||||||
assert.Equal(uint64(2), limits[0].Stats.WithinLimit.Value()) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This value should be 2. Please refer to the original test code for local cache. ratelimit/test/redis/fixed_cache_impl_test.go Lines 276 to 280 in b3562ca
|
||||||||||||
|
||||||||||||
// Check the local cache stats. | ||||||||||||
testLocalCacheStats(localCacheStats, statsStore, sink, 1, 3, 4, 0, 1) | ||||||||||||
|
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.
This does not follow the Golang naming convention.