-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Add a new parameter
worker_event_max_payload
to kong.conf (
#11214) * With a hard-coded payload size, for some use cases like uploading a big OpenAPI spec in DevPortal or updating a big config entry for plugins, they can not work as expected. With the new parameter, the user can decide the payload size to meet their needs. In this PR, a new parameter, `worker_events_max_payload` is added, which allows to specify the payload size the `worker_events` lib can accept. The default size is 64k, and the max allowed to set is 16M Bytes. The corresponding PR for `worker_events` lib is [#37](Kong/lua-resty-events#37) FTI-4963 * add changelog entry * Update kong.conf.default Co-authored-by: Datong Sun <datong.sun@konghq.com> * add test case and bump lua-resty-events * correct the default value, and add an entry for bumping the version of lua-resty-events * 1. append PR number to the changelog entry of lua-resty-events 2. correct the spec test 3. style * Update CHANGELOG.md --------- Co-authored-by: Datong Sun <datong.sun@konghq.com> Co-authored-by: Chrono <chrono_cpp@me.com>
- Loading branch information
1 parent
9942c71
commit 5665107
Showing
7 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
local worker_events_mock = [[ | ||
server { | ||
server_name example.com; | ||
listen %d; | ||
location = /payload { | ||
content_by_lua_block { | ||
local SOURCE = "foo" | ||
local EVENT = ngx.var.http_payload_type | ||
local worker_events = kong.worker_events | ||
local payload_received | ||
local function wait_until(validator, timeout) | ||
local deadline = ngx.now() + (timeout or 5) | ||
local res | ||
repeat | ||
worker_events.poll() | ||
res = validator() | ||
until res or ngx.now() >= deadline | ||
return res | ||
end | ||
-- subscribe | ||
local ok, err = worker_events.register(function(data) | ||
payload_received = data | ||
end, SOURCE, EVENT) | ||
-- when payload is a string | ||
local PAYLOAD = string.rep("X", %d) | ||
-- when payload is a table | ||
if EVENT == "table" then | ||
PAYLOAD = { | ||
foo = "bar", | ||
data = PAYLOAD, | ||
} | ||
end | ||
local ok, err = worker_events.post(SOURCE, EVENT, PAYLOAD) | ||
if not ok then | ||
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR | ||
ngx.say("post failed, err: " .. err) | ||
return | ||
end | ||
assert(wait_until(function() | ||
if EVENT == "string" then | ||
return PAYLOAD == payload_received | ||
else | ||
return require("pl.tablex").deepcompare(PAYLOAD, payload_received) | ||
end | ||
end, 1)) | ||
ngx.status = ngx.HTTP_OK | ||
ngx.say("ok") | ||
} | ||
} | ||
} | ||
]] | ||
|
||
|
||
local max_payloads = { 60 * 1024, 140 * 1024, } | ||
|
||
|
||
for _, max_payload in ipairs(max_payloads) do | ||
local business_port = 34567 | ||
local payload_size = 70 * 1024 | ||
|
||
local fixtures = { | ||
http_mock = { | ||
worker_events = string.format(worker_events_mock, | ||
business_port, payload_size) | ||
}, | ||
} | ||
|
||
local size_allowed = max_payload > payload_size | ||
local less_or_greater = size_allowed and ">" or "<" | ||
|
||
describe("worker_events [when max_payload " .. less_or_greater .. " payload_size]", function() | ||
local strategy = "off" | ||
local test_cases = {"string", "table", } | ||
|
||
lazy_setup(function() | ||
assert(helpers.start_kong({ | ||
database = strategy, | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
worker_events_max_payload = max_payload, | ||
}, nil, nil, fixtures)) | ||
end) | ||
|
||
lazy_teardown(function () | ||
assert(helpers.stop_kong()) | ||
end) | ||
|
||
for _, payload_type in ipairs(test_cases) do | ||
it("max_payload = " .. max_payload .. ", type = " .. payload_type, function() | ||
|
||
local res = helpers.proxy_client(nil, business_port):get( | ||
"/payload", { | ||
headers = { | ||
host = "example.com", | ||
payload_type = payload_type, | ||
} | ||
}) | ||
|
||
local status_code = 200 | ||
local msg = "ok" | ||
|
||
if not size_allowed then | ||
status_code = 500 | ||
msg = "post failed, err: " .. | ||
"failed to publish event: payload exceeds the limitation (".. max_payload .. ")" | ||
end | ||
|
||
local body = assert.res_status(status_code, res) | ||
assert.equal(body, msg) | ||
end) | ||
end | ||
end) | ||
end |