From 1c4c36ee57590c7dcd61fa062356fd830bce2e19 Mon Sep 17 00:00:00 2001 From: xumin Date: Thu, 31 Oct 2024 17:30:09 +0800 Subject: [PATCH] chore(rpc): add debugging logs --- kong/clustering/rpc/manager.lua | 13 +++++++++++++ kong/clustering/rpc/socket.lua | 1 + kong/clustering/services/sync/hooks.lua | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/kong/clustering/rpc/manager.lua b/kong/clustering/rpc/manager.lua index 7881b1661ffe..44f3c6d43f1f 100644 --- a/kong/clustering/rpc/manager.lua +++ b/kong/clustering/rpc/manager.lua @@ -18,6 +18,7 @@ local cjson = require("cjson.safe") local ngx_var = ngx.var local ngx_ERR = ngx.ERR +local ngx_DEBUG = ngx.DEBUG local ngx_log = ngx.log local ngx_exit = ngx.exit local ngx_time = ngx.time @@ -172,8 +173,17 @@ function _M:call(node_id, method, ...) local params = {...} + ngx_log(ngx_DEBUG, + "[rpc] calling ", method, + "(node_id: ", node_id, ")", + " via ", res == "local" and "local" or "concentrator" + ) + if res == "local" then res, err = self:_local_call(node_id, method, params) + + ngx_log(ngx_DEBUG, "[rpc] ", method, err and " failed" or " succeeded") + if not res then return nil, err end @@ -188,6 +198,9 @@ function _M:call(node_id, method, ...) assert(fut:start()) local ok, err = fut:wait(5) + + ngx_log(ngx_DEBUG, "[rpc] ", method, err and " failed" or " succeeded") + if err then return nil, err end diff --git a/kong/clustering/rpc/socket.lua b/kong/clustering/rpc/socket.lua index 95ef614df73d..d73620709c41 100644 --- a/kong/clustering/rpc/socket.lua +++ b/kong/clustering/rpc/socket.lua @@ -148,6 +148,7 @@ function _M:start() if payload.method then -- invoke + ngx_log(ngx_DEBUG, "[rpc] got RPC call: ", payload.method, " (id: ", payload.id, ")") local dispatch_cb = self.manager.callbacks.callbacks[payload.method] if not dispatch_cb then local res, err = self.outgoing:push(new_error(payload.id, jsonrpc.METHOD_NOT_FOUND)) diff --git a/kong/clustering/services/sync/hooks.lua b/kong/clustering/services/sync/hooks.lua index ae7bbbe90620..8ae44ca062b7 100644 --- a/kong/clustering/services/sync/hooks.lua +++ b/kong/clustering/services/sync/hooks.lua @@ -59,6 +59,8 @@ function _M:notify_all_nodes() return end + ngx_log(ngx_DEBUG, "[rpc:sync] notifying all nodes of new version: ", latest_version) + local msg = { default = { new_version = latest_version, }, } for _, node in ipairs(get_all_nodes_with_sync_cap()) do @@ -112,6 +114,7 @@ end -- only control plane has these delta operations function _M:register_dao_hooks() local function is_db_export(name) + ngx_log(ngx_DEBUG, "[rpc:sync] name: ", name, " db_export: ", kong.db[name].schema.db_export) local db_export = kong.db[name].schema.db_export return db_export == nil or db_export == true end @@ -131,6 +134,7 @@ function _M:register_dao_hooks() return end + ngx_log(ngx_DEBUG, "[rpc:sync] failed. Canceling ", name) local res, err = self.strategy:cancel_txn() if not res then ngx_log(ngx_ERR, "unable to cancel cancel_txn: ", tostring(err)) @@ -142,6 +146,7 @@ function _M:register_dao_hooks() return entity end + ngx_log(ngx_DEBUG, "[rpc:sync] new delta due to writing ", name) return self:entity_delta_writer(entity, name, options, ws_id) end @@ -150,7 +155,8 @@ function _M:register_dao_hooks() return entity end - -- set lmdb value to ngx_null then return entity + ngx_log(ngx_DEBUG, "[rpc:sync] new delta due to deleting ", name) + -- set lmdb value to ngx_null then return row return self:entity_delta_writer(entity, name, options, ws_id, true) end