Skip to content

Commit

Permalink
Merge pull request #1113 from eloycoto/RateLimitIssue
Browse files Browse the repository at this point in the history
Policy: Rate-limit fix window exception
  • Loading branch information
eloycoto authored Sep 12, 2019
2 parents 29bd8a7 + dbe4917 commit d818e1a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fix issues when OPENTRACING_FORWARD_HEADER was set [PR #1109](https://github.com/3scale/APIcast/pull/1109), [THREESCALE-1660](https://issues.jboss.org/browse/THREESCALE-1660)
- New TLS termination policy [PR #1108](https://github.com/3scale/APIcast/pull/1108), [THREESCALE-2898](https://issues.jboss.org/browse/THREESCALE-2898)
- Fix exception on rate limit policy when window was set as 0. [PR #1113](https://github.com/3scale/APIcast/pull/1108), [THREESCALE-3382](https://issues.jboss.org/browse/THREESCALE-3382)



## [3.6.0-rc1] - 2019-07-04
Expand Down
4 changes: 3 additions & 1 deletion gateway/src/apicast/policy/rate_limit/apicast-policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"type": "array",
"items": {
"type": "object",
"required": ["key", "count", "window"],
"properties": {
"key": {
"$ref": "#/definitions/key"
Expand All @@ -196,7 +197,8 @@
"window": {
"type": "integer",
"description": "The time window in seconds before the request count is reset",
"exclusiveMinimum": 0
"exclusiveMinimum": 0,
"default": 1
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/apicast/policy/rate_limit/rate_limit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ local traffic_limiters = {
return resty_limit_req.new(shdict_key, config.rate, config.burst)
end,
fixed_window = function(config)
if not config.window or config.window <= 0 then
config.window = 1
end
return resty_limit_count.new(shdict_key, config.count, config.window)
end
}
Expand Down
45 changes: 45 additions & 0 deletions t/apicast-policy-rate-limit.t
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,48 @@ limit. The limit is set to 2. Only the third one should fail.
[200, 200, 429]
--- no_error_log
[error]
=== TEST 22: Window is set to 0 and default is 1.
Return 429 code.
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require "resty.core"
ngx.shared.limiter:flush_all()
require('apicast.configuration_loader').mock({
services = {
{
id = 42,
proxy = {
policy_chain = {
{
name = "apicast.policy.rate_limit",
configuration = {
fixed_window_limiters = {
{
key = {name = "test9", scope = "global"},
count = 1,
window = 0
}
},
limits_exceeded_error = { status_code = 429 }
}
}
}
}
}
}
})
}
lua_shared_dict limiter 1m;
--- config
include $TEST_NGINX_APICAST_CONFIG;
--- pipelined_requests eval
["GET /","GET /"]
--- error_code eval
[200, 429]

0 comments on commit d818e1a

Please sign in to comment.