Skip to content

Commit

Permalink
chore(deps) bump resty.worker-events from 1.0.0 to 2.0.0
Browse files Browse the repository at this point in the history
### Summary

#### 2.0.0, 16-September-2020

- BREAKING: the `post` function does not call `poll` anymore, making all events
  asynchronous. When an immediate treatment to an event is needed an explicit
  call to `poll` must be done.
- BREAKING: the `post_local` function does not immediately execute the
  event anymore, making all local events asynchronous. When an immediate
  treatment to an event is needed an explicit call to `poll` must be done.
- fix: prevent spinning at 100% CPU when during a reload the event-shm is
  cleared
- fix: improved logging in case of failure to write to shm (add payload size
  for troubleshooting purposes)
- fix: do not log the payload anymore, since it might expose sensitive data
  through the logs
- change: updated `shm_retries` default to 999
- change: changed timer loop to a sleep-loop (performance)
- fix: when re-configuring make sure callbacks table is initialized
  • Loading branch information
bungle committed Sep 17, 2020
1 parent a7da8bc commit 082edf8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kong-2.1.3-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = {
"luasyslog == 1.0.0",
"lua_pack == 1.0.5",
"lua-resty-dns-client == 5.0.1",
"lua-resty-worker-events == 1.0.0",
"lua-resty-worker-events == 2.0.0",
"lua-resty-mediador == 0.1.2",
"lua-resty-healthcheck == 1.3.0",
"lua-resty-cookie == 0.1.0",
Expand Down
22 changes: 22 additions & 0 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,18 @@ local function serve_content(module, options)
end


local function poll_worker_events(premature)
if premature then
return
end

kong.worker_events.poll()
end


function Kong.admin_content(options)
kong.worker_events.poll()

local ctx = ngx.ctx
if not ctx.workspace then
ctx.workspace = kong.default_workspace
Expand Down Expand Up @@ -1333,6 +1344,16 @@ function Kong.admin_header_filter()
header[constants.HEADERS.ADMIN_LATENCY] = ctx.KONG_ADMIN_LATENCY
end

local method = ngx.req.get_method()

if method == "POST"
or method == "PUT"
or method == "DELETE"
or method == "PATCH"
then
ngx.timer.at(0, poll_worker_events)
end

-- this is not used for now, but perhaps we need it later?
--ctx.KONG_ADMIN_HEADER_FILTER_ENDED_AT = get_now_ms()
--ctx.KONG_ADMIN_HEADER_FILTER_TIME = ctx.KONG_ADMIN_HEADER_FILTER_ENDED_AT - ctx.KONG_ADMIN_HEADER_FILTER_START
Expand Down Expand Up @@ -1362,6 +1383,7 @@ do

function Kong.stream_config_listener()
local sock, err = ngx.req.socket()

if not sock then
kong.log.crit("unable to obtain request socket: ", err)
return
Expand Down
5 changes: 5 additions & 0 deletions spec/01-unit/09-balancer_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local utils = require "kong.tools.utils"
local mocker = require "spec.fixtures.mocker"
local we = require "resty.worker.events"


local ws_id = utils.uuid()

Expand Down Expand Up @@ -548,6 +550,7 @@ for _, consistency in ipairs({"strict", "eventual"}) do
}
for _, t in ipairs(tests) do
assert(balancer.post_health(upstream_ph, t.host, nil, t.port, t.health))
we.poll()
local health_info = assert(balancer.get_upstream_health("ph"))
local response = t.health and "HEALTHY" or "UNHEALTHY"
assert.same(response,
Expand Down Expand Up @@ -585,12 +588,14 @@ for _, consistency in ipairs({"strict", "eventual"}) do
port = 1111,
host = {hostname = "localhost"},
}}, 429)
we.poll()
my_balancer.report_http_status({
address = {
ip = "127.0.0.1",
port = 1111,
host = {hostname = "localhost"},
}}, 200)
we.poll()
balancer.unsubscribe_from_healthcheck_events(cb)
my_balancer.report_http_status({
address = {
Expand Down
6 changes: 6 additions & 0 deletions spec/02-integration/03-db/11-postgres-ro_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ for _, strategy in helpers.each_strategy() do
body = assert.res_status(201, res)
json = cjson.decode(body)

ngx.sleep(1)

route_id = json.id

res = assert(proxy_client:send({
Expand All @@ -70,6 +72,8 @@ for _, strategy in helpers.each_strategy() do
}))
assert.res_status(204, res)

ngx.sleep(1)

res = assert(proxy_client:send({
method = "GET",
path = "/",
Expand Down Expand Up @@ -124,6 +128,8 @@ for _, strategy in helpers.each_strategy() do
}))
assert.res_status(201, res)

ngx.sleep(1)

res = assert(proxy_client:send({
method = "GET",
path = "/",
Expand Down
6 changes: 6 additions & 0 deletions spec/02-integration/04-admin_api/08-targets_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ describe("Admin API #" .. strategy, function()
end)

it("checks every combination of valid and invalid upstream and target", function()
ngx.sleep(1)
for i, u in ipairs({ utils.uuid(), "invalid", upstream.name, upstream.id }) do
for j, t in ipairs({ utils.uuid(), "invalid:1234", wrong_target.id, target.target, target.id }) do
for _, e in ipairs({ "healthy", "unhealthy" }) do
Expand All @@ -701,6 +702,7 @@ describe("Admin API #" .. strategy, function()
path = target_path .. "/unhealthy"
})
assert.same(204, status, body)
ngx.sleep(1)
status, body = assert(client_send {
method = "GET",
path = "/upstreams/" .. upstream.id .. "/health"
Expand All @@ -714,6 +716,7 @@ describe("Admin API #" .. strategy, function()
path = target_path .. "/healthy"
})
assert.same(204, status)
ngx.sleep(1)
status, body = assert(client_send {
method = "GET",
path = "/upstreams/" .. upstream.id .. "/health"
Expand All @@ -725,12 +728,14 @@ describe("Admin API #" .. strategy, function()
end)

it("flips the target status from HEALTHY to UNHEALTHY", function()
ngx.sleep(1)
local status, body, json
status = assert(client_send {
method = "POST",
path = target_path .. "/healthy"
})
assert.same(204, status)
ngx.sleep(1)
status, body = assert(client_send {
method = "GET",
path = "/upstreams/" .. upstream.id .. "/health"
Expand All @@ -744,6 +749,7 @@ describe("Admin API #" .. strategy, function()
path = target_path .. "/unhealthy"
})
assert.same(204, status)
ngx.sleep(1)
status, body = assert(client_send {
method = "GET",
path = "/upstreams/" .. upstream.id .. "/health"
Expand Down
2 changes: 2 additions & 0 deletions spec/02-integration/05-proxy/04-plugins_triggering_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,8 @@ for _, strategy in helpers.each_strategy() do

assert.res_status(201, res)

ngx.sleep(1)

local res = assert(proxy_client:get("/status/400", {
headers = {
["Host"] = "runs-init-worker.org",
Expand Down

0 comments on commit 082edf8

Please sign in to comment.