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

feat: set minLength of redis_cluster_nodes to 1 for limit-count plugin #10612

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/plugins/limit-count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local limit_count = require("apisix.plugins.limit-count.init")

local plugin_name = "limit-count"
local _M = {
version = 0.4,
version = 0.5,
priority = 1002,
name = plugin_name,
schema = limit_count.schema,
Expand Down
2 changes: 1 addition & 1 deletion apisix/plugins/limit-count/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ local policy_to_additional_properties = {
properties = {
redis_cluster_nodes = {
type = "array",
minItems = 2,
minItems = 1,
items = {
type = "string", minLength = 2, maxLength = 100
},
Expand Down
51 changes: 51 additions & 0 deletions t/plugin/limit-count-redis-cluster3.t
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,54 @@ __DATA__
}
--- response_body
remaining: 1



=== TEST 2: set route, with single node in redis_cluster_nodes and redis_cluster_name
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis-cluster",
"redis_timeout": 1001,
"redis_cluster_nodes": [
"127.0.0.1:5000"
],
"redis_cluster_name": "redis-cluster-1"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 3: up the limit for single node in redis_cluster_nodes
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503]