-
Notifications
You must be signed in to change notification settings - Fork 170
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
Policy: rate_limit_headers fix cache issues. #1197
Conversation
8f34ddf
to
b82f3ff
Compare
When testing rate_limit_headers the number of APICast workers are always set to 1. When the number of workers increased, the lru_cache is not longer effective due to multiple threads. Because we only have information about usage statistics on Authrep, and this is using ngx.shared info, this policy also need to use shared information to be able to reply without doing the authrep in all sessions. Fix THREESCALE-3795 Signed-off-by: Eloy Coto <[email protected]>
b82f3ff
to
b489e35
Compare
@@ -41,4 +42,25 @@ function _M:reset(max, remaining, reset) | |||
self.reset = countdown_counter.new(reset, now()) | |||
end | |||
|
|||
function _M:export() |
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.
Nitpick: should this be called tostring
or similar for clarity?
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.
I do not think so, export/import is more declarative when you read the code. tostring was my first idea 😅
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.
👍
return _M.Init_empty(usage) | ||
end | ||
|
||
local data = stringx.split(exported_data, "#") |
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.
Nitpick: the "#" could be extracted to a constant that could be used in this method and in export()
.
local data = cache_entry.import(usage, entry:export()) | ||
assert.same(data.limit:__tostring(), "1") | ||
assert.same(data.remaining:__tostring(), "10") | ||
end) |
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 forgot one assert for reset
(3).
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.
Same for the tests below.
usage:add("foo", 1) | ||
end) | ||
|
||
it('if Auth cache is disabled, report the usage', function() |
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.
Not too important, but in cases like this, I like to put the condition outside the it
clause, so the it
clause reads like natural English. Something like this:
describe('when the auth cache is disabled', function()
it('reports the usage', function()
...
)
)
b1f73c6
to
1c0896d
Compare
Signed-off-by: Eloy Coto <[email protected]>
1c0896d
to
ea9133e
Compare
When testing rate_limit_headers the number of APICast workers are always set to
due to multiple threads.
Because we only have information about usage statistics on Authrep, and this is
using ngx.shared info, this policy also need to use shared information to be
able to reply without doing the authrep in all sessions.
Fix THREESCALE-3795
Signed-off-by: Eloy Coto [email protected]