diff --git a/changelog/unreleased/kong/dynamic-log-level-rpc.yml b/changelog/unreleased/kong/dynamic-log-level-rpc.yml deleted file mode 100644 index 69096eb0afe1..000000000000 --- a/changelog/unreleased/kong/dynamic-log-level-rpc.yml +++ /dev/null @@ -1,6 +0,0 @@ -message: | - Dynamic log level over Hybrid mode RPC which allows setting DP log level - to a different level for specified duration before reverting back - to the `kong.conf` configured value. -type: feature -scope: Clustering diff --git a/kong-3.9.0-0.rockspec b/kong-3.9.0-0.rockspec index 1b5f5f4e95ad..b86e9c85658d 100644 --- a/kong-3.9.0-0.rockspec +++ b/kong-3.9.0-0.rockspec @@ -98,7 +98,6 @@ build = { ["kong.clustering.rpc.utils"] = "kong/clustering/rpc/utils.lua", ["kong.clustering.rpc.concentrator"] = "kong/clustering/rpc/concentrator.lua", - ["kong.clustering.services.debug"] = "kong/clustering/services/debug.lua", ["kong.clustering.services.sync"] = "kong/clustering/services/sync/init.lua", ["kong.clustering.services.sync.rpc"] = "kong/clustering/services/sync/rpc.lua", ["kong.clustering.services.sync.hooks"] = "kong/clustering/services/sync/hooks.lua", diff --git a/kong/clustering/services/debug.lua b/kong/clustering/services/debug.lua deleted file mode 100644 index 387b19e62a1f..000000000000 --- a/kong/clustering/services/debug.lua +++ /dev/null @@ -1,70 +0,0 @@ -local _M = {} - - -local resty_log = require("resty.kong.log") -local constants = require("kong.constants") - - -local tostring = tostring - - -local function rpc_set_log_level(_node_id, new_log_level, timeout) - if not constants.LOG_LEVELS[new_log_level] then - return nil, "unknown log level: " .. tostring(new_log_level) - end - - if type(new_log_level) == "string" then - new_log_level = constants.LOG_LEVELS[new_log_level] - end - - local timeout = math.ceil(timeout or constants.DYN_LOG_LEVEL_DEFAULT_TIMEOUT) - - local _, _, original_level = resty_log.get_log_level() - if new_log_level == original_level then - timeout = 0 - end - - -- this function should not fail, if it throws exception, let RPC framework handle it - resty_log.set_log_level(new_log_level, timeout) - - local data = { - log_level = new_log_level, - timeout = timeout, - } - -- broadcast to all workers in a node - local ok, err = kong.worker_events.post("debug", "log_level", data) - if not ok then - return nil, err - end - - -- store in shm so that newly spawned workers can update their log levels - ok, err = ngx.shared.kong:set(constants.DYN_LOG_LEVEL_KEY, new_log_level, timeout) - if not ok then - return nil, err - end - - ok, err = ngx.shared.kong:set(constants.DYN_LOG_LEVEL_TIMEOUT_AT_KEY, ngx.time() + timeout, timeout) - if not ok then - return nil, err - end - - return true -end - - -local function rpc_get_log_level(_node_id) - local current_level, timeout, original_level = resty_log.get_log_level() - return { current_level = constants.LOG_LEVELS[current_level], - timeout = timeout, - original_level = constants.LOG_LEVELS[original_level], - } -end - - -function _M.init(manager) - manager.callbacks:register("kong.debug.log_level.v1.get_log_level", rpc_get_log_level) - manager.callbacks:register("kong.debug.log_level.v1.set_log_level", rpc_set_log_level) -end - - -return _M diff --git a/kong/init.lua b/kong/init.lua index e76f67e3f9d7..0313e8aa0855 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -699,10 +699,6 @@ function Kong.init() kong.sync = require("kong.clustering.services.sync").new(db, is_control_plane(config)) kong.sync:init(kong.rpc) end - - if is_data_plane(config) then - require("kong.clustering.services.debug").init(kong.rpc) - end end end diff --git a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua index 21eda945c6d7..0acd509fc0a7 100644 --- a/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua @@ -1,7 +1,8 @@ local helpers = require "spec.helpers" local cjson = require("cjson.safe") -for _, inc_sync in ipairs { "on", "off" } do +-- we need incremental sync to verify rpc +for _, inc_sync in ipairs { "on" } do for _, strategy in helpers.each_strategy() do describe("Hybrid Mode RPC #" .. strategy .. " inc_sync=" .. inc_sync, function() @@ -50,12 +51,15 @@ for _, strategy in helpers.each_strategy() do local body = assert.res_status(200, res) local json = cjson.decode(body) + assert(json) + + -- TODO: perhaps need a new test method for _, v in pairs(json.data) do if v.ip == "127.0.0.1" and v.rpc_capabilities and #v.rpc_capabilities ~= 0 then table.sort(v.rpc_capabilities) assert.near(14 * 86400, v.ttl, 3) - -- kong.debug.log_level.v1 should be the first rpc service - assert.same("kong.debug.log_level.v1", v.rpc_capabilities[1]) + -- check the available rpc service + assert.same("kong.sync.v2", v.rpc_capabilities[1]) return true end end diff --git a/spec/02-integration/18-hybrid_rpc/02-log-level_spec.lua b/spec/02-integration/18-hybrid_rpc/02-log-level_spec.lua deleted file mode 100644 index d53fc541dec0..000000000000 --- a/spec/02-integration/18-hybrid_rpc/02-log-level_spec.lua +++ /dev/null @@ -1,185 +0,0 @@ -local helpers = require "spec.helpers" -local cjson = require("cjson.safe") - - -local function obtain_dp_node_id() - local dp_node_id - - helpers.wait_until(function() - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:get("/clustering/data-planes")) - local body = assert.res_status(200, res) - local json = cjson.decode(body) - - for _, v in pairs(json.data) do - if v.ip == "127.0.0.1" and ngx.time() - v.last_seen < 3 then - dp_node_id = v.id - return true - end - end - end, 10) - - return dp_node_id -end - - -for _, inc_sync in ipairs { "on", "off" } do -for _, strategy in helpers.each_strategy() do - describe("Hybrid Mode RPC #" .. strategy .. " inc_sync=" .. inc_sync, function() - - lazy_setup(function() - helpers.get_db_utils(strategy, { - "clustering_data_planes", - }) -- runs migrations - - assert(helpers.start_kong({ - role = "control_plane", - cluster_cert = "spec/fixtures/kong_clustering.crt", - cluster_cert_key = "spec/fixtures/kong_clustering.key", - database = strategy, - cluster_listen = "127.0.0.1:9005", - nginx_conf = "spec/fixtures/custom_nginx.template", - cluster_incremental_sync = inc_sync, -- incremental sync - })) - - assert(helpers.start_kong({ - role = "data_plane", - database = "off", - prefix = "servroot2", - cluster_cert = "spec/fixtures/kong_clustering.crt", - cluster_cert_key = "spec/fixtures/kong_clustering.key", - cluster_control_plane = "127.0.0.1:9005", - proxy_listen = "0.0.0.0:9002", - nginx_conf = "spec/fixtures/custom_nginx.template", - cluster_incremental_sync = inc_sync, -- incremental sync - })) - end) - - lazy_teardown(function() - helpers.stop_kong("servroot2") - helpers.stop_kong() - end) - - describe("Dynamic log level over RPC", function() - it("can get the current log level", function() - local dp_node_id = obtain_dp_node_id() - - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:get("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - local body = assert.res_status(200, res) - local json = cjson.decode(body) - assert.equal(0, json.timeout) - assert.equal("debug", json.current_level) - assert.equal("debug", json.original_level) - end) - - it("can set the current log level", function() - local dp_node_id = obtain_dp_node_id() - - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:put("/clustering/data-planes/" .. dp_node_id .. "/log-level", - { - headers = { - ["Content-Type"] = "application/json", - }, - body = { - current_level = "info", - timeout = 10, - }, - })) - assert.res_status(201, res) - - local res = assert(admin_client:get("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - local body = assert.res_status(200, res) - local json = cjson.decode(body) - assert.near(10, json.timeout, 3) - assert.equal("info", json.current_level) - assert.equal("debug", json.original_level) - end) - - it("set current log level to original_level turns off feature", function() - local dp_node_id = obtain_dp_node_id() - - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:put("/clustering/data-planes/" .. dp_node_id .. "/log-level", - { - headers = { - ["Content-Type"] = "application/json", - }, - body = { - current_level = "info", - timeout = 10, - }, - })) - assert.res_status(201, res) - - local res = assert(admin_client:put("/clustering/data-planes/" .. dp_node_id .. "/log-level", - { - headers = { - ["Content-Type"] = "application/json", - }, - body = { - current_level = "debug", - timeout = 10, - }, - })) - assert.res_status(201, res) - - local res = assert(admin_client:get("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - local body = assert.res_status(200, res) - local json = cjson.decode(body) - assert.equal(0, json.timeout) - assert.equal("debug", json.current_level) - assert.equal("debug", json.original_level) - end) - - it("DELETE turns off feature", function() - local dp_node_id = obtain_dp_node_id() - - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:put("/clustering/data-planes/" .. dp_node_id .. "/log-level", - { - headers = { - ["Content-Type"] = "application/json", - }, - body = { - current_level = "info", - timeout = 10, - }, - })) - assert.res_status(201, res) - - local res = assert(admin_client:delete("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - assert.res_status(204, res) - - local res = assert(admin_client:get("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - local body = assert.res_status(200, res) - local json = cjson.decode(body) - assert.equal(0, json.timeout) - assert.equal("debug", json.current_level) - assert.equal("debug", json.original_level) - end) - end) - end) -end -- for _, strategy -end -- for inc_sync diff --git a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua index 51c7a3b8a1a4..763d7a383474 100644 --- a/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua @@ -2,7 +2,8 @@ local helpers = require "spec.helpers" local cjson = require("cjson.safe") -local function obtain_dp_node_id() +-- keep it for future usage +local function obtain_dp_node_id() -- luacheck: ignore local dp_node_id helpers.wait_until(function() @@ -27,7 +28,8 @@ local function obtain_dp_node_id() end -for _, inc_sync in ipairs { "on", "off" } do +-- we need incremental sync to verify rpc +for _, inc_sync in ipairs { "on" } do for _, strategy in helpers.each_strategy() do describe("Hybrid Mode RPC over DB concentrator #" .. strategy .. " inc_sync=" .. inc_sync, function() @@ -77,35 +79,9 @@ for _, strategy in helpers.each_strategy() do helpers.stop_kong() end) - describe("Dynamic log level over RPC", function() - it("can get the current log level", function() - local dp_node_id = obtain_dp_node_id() - - -- this sleep is *not* needed for the below wait_until to succeed, - -- but it makes the wait_until tried succeed sooner because this - -- extra time gives the concentrator enough time to report the node is - -- online inside the DB. Without it, the first call to "/log-level" - -- will always timeout after 5 seconds - ngx.sleep(1) - - helpers.wait_until(function() - local admin_client = helpers.admin_client() - finally(function() - admin_client:close() - end) - - local res = assert(admin_client:get("/clustering/data-planes/" .. dp_node_id .. "/log-level")) - if res.status == 200 then - local body = assert.res_status(200, res) - local json = cjson.decode(body) - assert.equal(0, json.timeout) - assert.equal("debug", json.current_level) - assert.equal("debug", json.original_level) - return true - end - end, 10) - end) - end) + -- TODO: test with other rpc + --describe("XXX over RPC", function() + --end) end) end -- for _, strategy end -- for inc_sync