Skip to content

Commit

Permalink
chore(rpc): add debugging logs
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki committed Oct 31, 2024
1 parent dcfc998 commit 1c4c36e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions kong/clustering/rpc/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion kong/clustering/services/sync/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 1c4c36e

Please sign in to comment.