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

fix(clustering): ensure data plane config hash is never nil #11917

Merged
merged 2 commits into from
Nov 7, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Fix a bug causing data-plane status updates to fail when an empty PING frame is received from a data-plane
type: bugfix
scope: Clustering
8 changes: 7 additions & 1 deletion kong/clustering/control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ function _M:handle_cp_websocket()
local ok
ok, err = kong.db.clustering_data_planes:upsert({ id = dp_id, }, {
last_seen = last_seen,
config_hash = config_hash ~= "" and config_hash or nil,
config_hash = config_hash ~= ""
and config_hash
or DECLARATIVE_EMPTY_CONFIG_HASH,
hostname = dp_hostname,
ip = dp_ip,
version = dp_version,
Expand Down Expand Up @@ -341,6 +343,10 @@ function _M:handle_cp_websocket()

if not data then
return nil, "did not receive ping frame from data plane"

elseif #data ~= 32 then
return nil, "received a ping frame from the data plane with an invalid"
.. " hash: '" .. tostring(data) .. "'"
end

-- dps only send pings
Expand Down
2 changes: 1 addition & 1 deletion kong/clustering/data_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ local function send_ping(c, log_suffix)

local hash = declarative.get_current_hash()

if hash == true then
if hash == "" or type(hash) ~= "string" then
hash = DECLARATIVE_EMPTY_CONFIG_HASH
end

Expand Down
35 changes: 19 additions & 16 deletions spec/02-integration/20-wasm/06-clustering_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@ local FILTER_SRC = "spec/fixtures/proxy_wasm_filters/build/response_transformer.
local json = cjson.encode
local file = helpers.file

local function get_node_id(prefix)
local data = helpers.wait_for_file_contents(prefix .. "/kong.id")
data = data:gsub("%s*(.-)%s*", "%1")
assert(utils.is_valid_uuid(data), "invalid kong node ID found in " .. prefix)
return data
end


local function expect_status(prefix, exp)
local id = get_node_id(prefix)
local msg = "waiting for clustering sync status to equal"
.. " '" .. exp .. "' for data plane"

local function expect_status(id, exp)
assert
.eventually(function()
local cp_client = helpers.admin_client()
Expand Down Expand Up @@ -69,7 +58,8 @@ local function expect_status(prefix, exp)

return true
end)
.is_truthy(msg)
.is_truthy("waiting for clustering sync status to equal "
.. "'filter_set_incompatible' for data plane")
end

local function new_wasm_filter_directory()
Expand All @@ -89,6 +79,9 @@ describe("#wasm - hybrid mode #postgres", function()
local dp_prefix = "dp"

lazy_setup(function()
helpers.clean_prefix(cp_prefix)
helpers.clean_prefix(dp_prefix)

local _, db = helpers.get_db_utils("postgres", {
"services",
"routes",
Expand Down Expand Up @@ -129,9 +122,11 @@ describe("#wasm - hybrid mode #postgres", function()
describe("[happy path]", function()
local client
local dp_filter_path
local node_id

lazy_setup(function()
dp_filter_path = new_wasm_filter_directory()
node_id = utils.uuid()

assert(helpers.start_kong({
role = "data_plane",
Expand All @@ -144,6 +139,7 @@ describe("#wasm - hybrid mode #postgres", function()
nginx_conf = "spec/fixtures/custom_nginx.template",
wasm = true,
wasm_filters_path = dp_filter_path,
node_id = node_id,
}))

client = helpers.proxy_client()
Expand Down Expand Up @@ -271,13 +267,16 @@ describe("#wasm - hybrid mode #postgres", function()
end)
.is_truthy("wasm filter has been removed from the data plane")

expect_status(dp_prefix, STATUS.NORMAL)
expect_status(node_id, STATUS.NORMAL)
end)
end)

describe("data planes with wasm disabled", function()
local node_id

lazy_setup(function()
helpers.clean_logfile(cp_errlog)
node_id = utils.uuid()

assert(helpers.start_kong({
role = "data_plane",
Expand All @@ -289,6 +288,7 @@ describe("#wasm - hybrid mode #postgres", function()
admin_listen = "off",
nginx_conf = "spec/fixtures/custom_nginx.template",
wasm = "off",
node_id = node_id,
}))
end)

Expand All @@ -302,16 +302,18 @@ describe("#wasm - hybrid mode #postgres", function()
[[unable to send updated configuration to data plane: data plane is missing one or more wasm filters]],
true, 5)

expect_status(dp_prefix, STATUS.FILTER_SET_INCOMPATIBLE)
expect_status(node_id, STATUS.FILTER_SET_INCOMPATIBLE)
end)
end)

describe("data planes missing one or more wasm filter", function()
local tmp_dir
local node_id

lazy_setup(function()
helpers.clean_logfile(cp_errlog)
tmp_dir = helpers.make_temp_dir()
node_id = utils.uuid()

assert(helpers.start_kong({
role = "data_plane",
Expand All @@ -324,6 +326,7 @@ describe("#wasm - hybrid mode #postgres", function()
nginx_conf = "spec/fixtures/custom_nginx.template",
wasm = true,
wasm_filters_path = tmp_dir,
node_id = node_id,
}))
end)

Expand All @@ -338,7 +341,7 @@ describe("#wasm - hybrid mode #postgres", function()
[[unable to send updated configuration to data plane: data plane is missing one or more wasm filters]],
true, 5)

expect_status(dp_prefix, STATUS.FILTER_SET_INCOMPATIBLE)
expect_status(node_id, STATUS.FILTER_SET_INCOMPATIBLE)
end)
end)
end)