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

Fix shadow mode metric is not collected when local cache hit #424

Merged
merged 1 commit into from
May 30, 2023

Conversation

upgle
Copy link
Contributor

@upgle upgle commented May 18, 2023

Description

This PR fixes #423 issue where statistics were not collected correctly when hitting the local cache.

If the local cache is hit, the rate limit service does not perform the INCR command, but the GetResponseDescriptorStatus method does not handle it properly.

Invalid metric

shadow mode stats are not collected for the actual number of requests.

image

Expected

shadow mode stat should be the same value as over limit .

image

@mattklein123 mattklein123 self-assigned this May 18, 2023
Signed-off-by: Seonghyun Oh <seonghyunoh@gmail.com>
@upgle upgle force-pushed the fix-shadowmode-stats branch from fc22497 to f9c6402 Compare May 18, 2023 16:56
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())
Copy link
Contributor Author

@upgle upgle May 18, 2023

Choose a reason for hiding this comment

The 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.
(Even if shadow mode is enabled, this value should not be changed.)

assert.Equal(uint64(4), limits[0].Stats.TotalHits.Value())
assert.Equal(uint64(2), limits[0].Stats.OverLimit.Value())
assert.Equal(uint64(1), limits[0].Stats.OverLimitWithLocalCache.Value())
assert.Equal(uint64(1), limits[0].Stats.NearLimit.Value())
assert.Equal(uint64(2), limits[0].Stats.WithinLimit.Value())

}

isOverLimitWithLocalCache[i] = true
Copy link
Contributor Author

@upgle upgle May 18, 2023

Choose a reason for hiding this comment

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

  • Shadow mode and local cache should be irrelevant.
  • If the local cache is hit, the continue statement does not perform the INCR command, but the GetResponseDescriptorStatus method does not handle it properly.

@@ -80,9 +80,9 @@ func (this *BaseRateLimiter) GetResponseDescriptorStatus(key string, limitInfo *
nil, 0)
}
var responseDescriptorStatus *pb.RateLimitResponse_DescriptorStatus
over_limit := false
Copy link
Contributor Author

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.

@upgle upgle changed the title Increment shadow metric regardless of local cache Fix shadow mode metric is not collected when local cache hit May 18, 2023
@mattklein123
Copy link
Member

Can you check CI? Not sure if it's a flake or not.

@upgle
Copy link
Contributor Author

upgle commented May 19, 2023

@mattklein123
All tests passed in my environment. Could you please re-run the PR build again?
The error log shows that the redis connection was refused.

@mattklein123 mattklein123 merged commit ce3d747 into envoyproxy:main May 30, 2023
barroca pushed a commit to barroca/ratelimit that referenced this pull request Sep 1, 2023
Signed-off-by: Seonghyun Oh <seonghyunoh@gmail.com>
timcovar pushed a commit to goatapp/ratelimit that referenced this pull request Jan 16, 2024
Signed-off-by: Seonghyun Oh <seonghyunoh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Invalid shadow metric when local cache hit
2 participants