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

chore(deps) bump worker events and healthchecks #6361

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions kong-2.4.1-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dependencies = {
"lua_pack == 1.0.5",
"lua-resty-dns-client == 6.0.1",
"lua-protobuf == 0.3.2",
"lua-resty-worker-events == 1.0.0",
"lua-resty-healthcheck == 1.4.1",
"lua-resty-worker-events == 2.0.1",
"lua-resty-healthcheck == 2.0.0",
"lua-resty-cookie == 0.1.0",
"lua-resty-mlcache == 2.5.0",
"lua-messagepack == 0.5.2",
Expand Down
4 changes: 2 additions & 2 deletions kong/db/declarative/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ do
ok, err, default_ws = declarative.load_into_cache(entities, meta, hash, SHADOW)
if ok then
ok, err = kong.worker_events.post("declarative", "flip_config", default_ws)
if ok ~= "done" then
if not ok then
ngx.shared.kong:delete(DECLARATIVE_LOCK_KEY)
return nil, "failed to flip declarative config cache pages: " .. (err or ok)
return nil, "failed to flip declarative config cache pages: " .. (err or "unknown error")
end

else
Expand Down
1 change: 1 addition & 0 deletions kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ end


function Kong.status_content()
kong.worker_events.poll()
return serve_content("kong.status")
end

Expand Down
6 changes: 6 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 @@ -112,6 +114,7 @@ for _, consistency in ipairs({"strict", "eventual"}) do

local passive_hc = utils.deep_copy(hc_defaults)
passive_hc.passive.healthy.successes = 1
passive_hc.passive.unhealthy.tcp_failures = 1 -- 1 = required because http failures is 1 as well
passive_hc.passive.unhealthy.http_failures = 1

UPSTREAMS_FIXTURES = {
Expand Down Expand Up @@ -469,6 +472,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 @@ -506,12 +510,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
45 changes: 34 additions & 11 deletions spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local https_server = helpers.https_server


for _, strategy in helpers.each_strategy() do
local bp
local bp, db

local DB_UPDATE_PROPAGATION = strategy == "cassandra" and 0.1 or 0
local DB_UPDATE_FREQUENCY = strategy == "cassandra" and 0.1 or 0.1
Expand All @@ -23,12 +23,15 @@ for _, strategy in helpers.each_strategy() do

describe("Healthcheck #" .. strategy, function()
lazy_setup(function()
bp = bu.get_db_utils_for_dc_and_admin_api(strategy, {
bp, db = bu.get_db_utils_for_dc_and_admin_api(strategy, {
"routes",
"services",
"plugins",
"upstreams",
"targets",
}, {
"worker-events-poll",
"fail-once-auth",
})

local fixtures = {
Expand Down Expand Up @@ -73,6 +76,10 @@ for _, strategy in helpers.each_strategy() do
address = "127.0.0.2",
}

db.plugins:insert({
name = "worker-events-poll",
})

assert(helpers.start_kong({
database = strategy,
dns_resolver = "127.0.0.1",
Expand All @@ -81,6 +88,7 @@ for _, strategy in helpers.each_strategy() do
nginx_conf = "spec/fixtures/custom_nginx.template",
db_update_frequency = DB_UPDATE_FREQUENCY,
db_update_propagation = DB_UPDATE_PROPAGATION,
plugins = "bundled,fail-once-auth,worker-events-poll"
}, nil, nil, fixtures))

end)
Expand Down Expand Up @@ -361,11 +369,14 @@ for _, strategy in helpers.each_strategy() do


lazy_setup(function()
bp = bu.get_db_utils_for_dc_and_admin_api(strategy, {
bp, db = bu.get_db_utils_for_dc_and_admin_api(strategy, {
"services",
"routes",
"upstreams",
"targets",
}, {
"worker-events-poll",
"fail-once-auth",
})

local fixtures = {
Expand All @@ -377,6 +388,10 @@ for _, strategy in helpers.each_strategy() do
address = "127.0.0.1",
}

db.plugins:insert({
name = "worker-events-poll",
})

assert(helpers.start_kong({
database = strategy,
admin_listen = default_admin_listen,
Expand All @@ -387,7 +402,7 @@ for _, strategy in helpers.each_strategy() do
client_ssl_cert_key = "spec/fixtures/kong_spec.key",
db_update_frequency = 0.1,
stream_listen = "off",
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
}, nil, nil, fixtures))
end)

Expand Down Expand Up @@ -469,11 +484,18 @@ for _, strategy in helpers.each_strategy() do
describe("Ring-balancer #" .. strategy, function()

lazy_setup(function()
bp = bu.get_db_utils_for_dc_and_admin_api(strategy, {
bp, db = bu.get_db_utils_for_dc_and_admin_api(strategy, {
"services",
"routes",
"upstreams",
"targets",
}, {
"fail-once-auth",
"worker-events-poll",
})

db.plugins:insert({
name = "worker-events-poll",
})

assert(helpers.start_kong({
Expand All @@ -486,7 +508,7 @@ for _, strategy in helpers.each_strategy() do
stream_listen = "off",
db_update_frequency = DB_UPDATE_FREQUENCY,
db_update_propagation = DB_UPDATE_PROPAGATION,
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
}))
end)

Expand All @@ -512,6 +534,7 @@ for _, strategy in helpers.each_strategy() do
log_level = "debug",
db_update_frequency = DB_UPDATE_FREQUENCY,
db_update_propagation = DB_UPDATE_PROPAGATION,
plugins = "bundled,fail-once-auth,worker-events-poll",
})
end)

Expand Down Expand Up @@ -1053,7 +1076,7 @@ for _, strategy in helpers.each_strategy() do
lua_ssl_trusted_certificate = "spec/fixtures/kong_spec.crt",
db_update_frequency = 0.1,
stream_listen = "off",
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
}, nil, fixtures)
bu.end_testcase_setup(strategy, bp)

Expand Down Expand Up @@ -1481,7 +1504,7 @@ for _, strategy in helpers.each_strategy() do
lua_ssl_trusted_certificate = "spec/fixtures/kong_spec.crt",
db_update_frequency = 0.1,
stream_listen = "off",
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
}, nil, fixtures)
bu.end_testcase_setup(strategy, bp)

Expand Down Expand Up @@ -1590,7 +1613,7 @@ for _, strategy in helpers.each_strategy() do
lua_ssl_trusted_certificate = "spec/fixtures/kong_spec.crt",
db_update_frequency = 0.1,
stream_listen = "off",
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
}, nil, fixtures)
bu.end_testcase_setup(strategy, bp)

Expand Down Expand Up @@ -1813,7 +1836,7 @@ for _, strategy in helpers.each_strategy() do
lua_ssl_trusted_certificate = "spec/fixtures/kong_spec.crt",
db_update_frequency = 0.1,
stream_listen = "off",
plugins = "bundled,fail-once-auth",
plugins = "bundled,fail-once-auth,worker-events-poll",
})
bu.end_testcase_setup(strategy, bp)

Expand Down Expand Up @@ -1999,7 +2022,7 @@ for _, strategy in helpers.each_strategy() do

end)

it("perform passive health checks -- connection #timeouts", function()
it("#flaky perform passive health checks -- connection #timeouts", function()

-- configure healthchecks
bu.begin_testcase_setup(strategy, bp)
Expand Down
32 changes: 27 additions & 5 deletions spec/03-plugins/25-oauth2/04-invalidations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ for _, strategy in helpers.each_strategy() do
local token = cjson.decode(assert.res_status(200, res))
assert.is_table(token)

-- Check that cache is not populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)
local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
headers = {}
})
assert.res_status(404, res)

-- The token should work
local res = assert(proxy_ssl_client:send {
method = "GET",
Expand All @@ -327,7 +336,6 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(200, res)

-- Check that cache is populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)
local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
Expand Down Expand Up @@ -376,6 +384,15 @@ for _, strategy in helpers.each_strategy() do
local token = cjson.decode(assert.res_status(200, res))
assert.is_table(token)

-- Check that cache is not populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)
local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
headers = {}
})
assert.res_status(404, res)

-- The token should work
local res = assert(proxy_ssl_client:send {
method = "GET",
Expand All @@ -387,8 +404,6 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(200, res)

-- Check that cache is populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)

local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
Expand Down Expand Up @@ -454,6 +469,15 @@ for _, strategy in helpers.each_strategy() do
local token = cjson.decode(assert.res_status(200, res))
assert.is_table(token)

-- Check that cache is not populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)
local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
headers = {}
})
assert.res_status(404, res)

-- The token should work
local res = assert(proxy_ssl_client:send {
method = "GET",
Expand All @@ -465,8 +489,6 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(200, res)

-- Check that cache is populated
local cache_key = db.oauth2_tokens:cache_key(token.access_token)

local res = assert(admin_client:send {
method = "GET",
path = "/cache/" .. cache_key,
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/balancer_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ local function end_testcase_setup(strategy, bp, consistency)
end


local function get_db_utils_for_dc_and_admin_api(strategy, tables)
local bp = assert(helpers.get_db_utils(strategy, tables))
local function get_db_utils_for_dc_and_admin_api(strategy, tables, plugins)
local bp, db = assert(helpers.get_db_utils(strategy, tables, plugins))
if strategy ~= "off" then
bp = require("spec.fixtures.admin_api")
end
return bp
return bp, db
end


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local kong = kong
local math = math


local WorkerEventsPoll = {
PRIORITY = math.huge
}


function WorkerEventsPoll:preread()
kong.worker_events.poll()
end


function WorkerEventsPoll:rewrite()
kong.worker_events.poll()
end


return WorkerEventsPoll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local typedefs = require "kong.db.schema.typedefs"

return {
name = "worker-events-poll",
fields = {
{
protocols = typedefs.protocols { default = { "http", "https", "tcp", "tls", "grpc", "grpcs" } },
},
{
config = {
type = "record",
fields = {
},
},
},
},
}