Skip to content

Commit 94acc02

Browse files
authored
feat(acme): add scan_count to redis storage schema (#11532)
SRE has started seeing entries in the Redis slowlog related to retrieving keys for kong_acme:renew_config. lua-resty-acme was recently changed to use Redis scan instead of keys for performance reasons. See the lua-resty-acme PR for more details fffonion/lua-resty-acme#106. This PR exposes a new configuration field for Redis storage that controls how many keys are returned in a scan call and bumps lua-resty-acme to 0.12.0.
1 parent 33ab9a2 commit 94acc02

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

CHANGELOG/unreleased/kong/11532.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
message: "add scan_count to redis storage schema"
2+
type: feature
3+
scope: Plugin
4+
prs:
5+
- 11532

kong-3.5.0-0.rockspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = {
3737
"lua-resty-openssl == 0.8.25",
3838
"lua-resty-counter == 0.2.1",
3939
"lua-resty-ipmatcher == 0.6.1",
40-
"lua-resty-acme == 0.11.0",
40+
"lua-resty-acme == 0.12.0",
4141
"lua-resty-session == 4.0.5",
4242
"lua-resty-timer-ng == 0.2.5",
4343
"lpeg == 1.0.2",

kong/clustering/compat/removed_fields.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ return {
9797
},
9898
},
9999

100+
-- Any dataplane older than 3.5.0
100101
[3005000000] = {
102+
acme = {
103+
"storage_config.redis.scan_count",
104+
},
101105
cors = {
102106
"private_network",
103-
}
104-
}
107+
},
108+
},
105109
}

kong/plugins/acme/schema.lua

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ local REDIS_STORAGE_SCHEMA = {
5252
custom_validator = validate_namespace
5353
}
5454
},
55+
{ scan_count = { type = "number", required = false, default = 10, description = "The number of keys to return in Redis SCAN calls." } },
5556
}
5657

5758
local CONSUL_STORAGE_SCHEMA = {

spec/03-plugins/29-acme/05-redis_storage_spec.lua

+31
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,37 @@ describe("Plugin: acme (storage.redis)", function()
106106
assert.equal(0, #keys)
107107
end)
108108

109+
it("redis namespace list with scan count", function()
110+
local config1 = {
111+
host = helpers.redis_host,
112+
port = helpers.redis_port,
113+
database = 0,
114+
namespace = "namespace1",
115+
scan_count = 20,
116+
}
117+
118+
local storage1, err = redis_storage.new(config1)
119+
assert.is_nil(err)
120+
assert.not_nil(storage1)
121+
122+
for i=1,50 do
123+
local err = storage1:set(string.format("scan-count:%02d", i), i, 10)
124+
assert.is_nil(err)
125+
end
126+
127+
128+
local keys, err = storage1:list("scan-count")
129+
assert.is_nil(err)
130+
assert.is_table(keys)
131+
assert.equal(50, #keys)
132+
133+
table.sort(keys)
134+
135+
for i=1,50 do
136+
assert.equal(string.format("scan-count:%02d", i), keys[i])
137+
end
138+
end)
139+
109140
it("redis namespace isolation", function()
110141
local config0 = {
111142
host = helpers.redis_host,

0 commit comments

Comments
 (0)