From 6a2cf8d0551f831513c7fb7f59ab2394482e9347 Mon Sep 17 00:00:00 2001 From: Steve Zesch Date: Wed, 6 Sep 2023 23:03:13 -0400 Subject: [PATCH] feat(acme): add scan_count to redis storage schema * bump lua-resty-acme plugin to 0.12.0 * expose scan_count in redis storage schema to configure the number of keys returned in redis scan calls --- CHANGELOG/unreleased/kong/11532.yaml | 5 +++ kong-3.5.0-0.rockspec | 2 +- kong/clustering/compat/removed_fields.lua | 8 +++-- kong/plugins/acme/schema.lua | 1 + .../29-acme/05-redis_storage_spec.lua | 31 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG/unreleased/kong/11532.yaml diff --git a/CHANGELOG/unreleased/kong/11532.yaml b/CHANGELOG/unreleased/kong/11532.yaml new file mode 100644 index 000000000000..e27eba43b650 --- /dev/null +++ b/CHANGELOG/unreleased/kong/11532.yaml @@ -0,0 +1,5 @@ +message: "add scan_count to redis storage schema" +type: feature +scope: Plugin +prs: + - 11532 \ No newline at end of file diff --git a/kong-3.5.0-0.rockspec b/kong-3.5.0-0.rockspec index 8c59cf2906b6..f50954943f9c 100644 --- a/kong-3.5.0-0.rockspec +++ b/kong-3.5.0-0.rockspec @@ -37,7 +37,7 @@ dependencies = { "lua-resty-openssl == 0.8.25", "lua-resty-counter == 0.2.1", "lua-resty-ipmatcher == 0.6.1", - "lua-resty-acme == 0.11.0", + "lua-resty-acme == 0.12.0", "lua-resty-session == 4.0.5", "lua-resty-timer-ng == 0.2.5", "lpeg == 1.0.2", diff --git a/kong/clustering/compat/removed_fields.lua b/kong/clustering/compat/removed_fields.lua index 81022d0e26a6..940a6ef614da 100644 --- a/kong/clustering/compat/removed_fields.lua +++ b/kong/clustering/compat/removed_fields.lua @@ -97,9 +97,13 @@ return { }, }, + -- Any dataplane older than 3.5.0 [3005000000] = { + acme = { + "storage_config.redis.scan_count", + }, cors = { "private_network", - } - } + }, + }, } diff --git a/kong/plugins/acme/schema.lua b/kong/plugins/acme/schema.lua index ee21116847ee..df50fc743d1c 100644 --- a/kong/plugins/acme/schema.lua +++ b/kong/plugins/acme/schema.lua @@ -52,6 +52,7 @@ local REDIS_STORAGE_SCHEMA = { custom_validator = validate_namespace } }, + { scan_count = { type = "number", required = false, default = 10, description = "The number of keys to return in Redis SCAN calls." } }, } local CONSUL_STORAGE_SCHEMA = { diff --git a/spec/03-plugins/29-acme/05-redis_storage_spec.lua b/spec/03-plugins/29-acme/05-redis_storage_spec.lua index da4744f5f238..861e7609c9a0 100644 --- a/spec/03-plugins/29-acme/05-redis_storage_spec.lua +++ b/spec/03-plugins/29-acme/05-redis_storage_spec.lua @@ -106,6 +106,37 @@ describe("Plugin: acme (storage.redis)", function() assert.equal(0, #keys) end) + it("redis namespace list with scan count", function() + local config1 = { + host = helpers.redis_host, + port = helpers.redis_port, + database = 0, + namespace = "namespace1", + scan_count = 20, + } + + local storage1, err = redis_storage.new(config1) + assert.is_nil(err) + assert.not_nil(storage1) + + for i=1,50 do + local err = storage1:set(string.format("scan-count:%02d", i), i, 10) + assert.is_nil(err) + end + + + local keys, err = storage1:list("scan-count") + assert.is_nil(err) + assert.is_table(keys) + assert.equal(50, #keys) + + table.sort(keys) + + for i=1,50 do + assert.equal(string.format("scan-count:%02d", i), keys[i]) + end + end) + it("redis namespace isolation", function() local config0 = { host = helpers.redis_host,