Skip to content

Commit

Permalink
save dp ipaddr in rpc manager
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 24, 2024
1 parent 0255e06 commit d81b020
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function _M.new(conf, node_id)
-- clients[node_id]: { socket1 => true, socket2 => true, ... }
clients = {},
client_capabilities = {},
client_ips = {}, -- store DP node's ip addr
node_id = node_id,
conf = conf,
cluster_cert = assert(clustering_tls.get_cluster_cert(conf)),
Expand Down Expand Up @@ -75,16 +76,18 @@ end


function _M:_remove_socket(socket)
local sockets = assert(self.clients[socket.node_id])
local node_id = socket.node_id
local sockets = assert(self.clients[node_id])

assert(sockets[socket])

sockets[socket] = nil

if table_isempty(sockets) then
self.clients[socket.node_id] = nil
self.client_capabilities[socket.node_id] = nil
assert(self.concentrator:_enqueue_unsubscribe(socket.node_id))
self.clients[node_id] = nil
self.client_ips[node_id] = nil
self.client_capabilities[node_id] = nil
assert(self.concentrator:_enqueue_unsubscribe(node_id))
end
end

Expand Down Expand Up @@ -255,6 +258,9 @@ function _M:handle_websocket()
local s = socket.new(self, wb, node_id)
self:_add_socket(s, rpc_capabilities)

-- store DP's ip addr
self.client_ips[node_id] = ngx_var.remote_addr

s:start()
local res, err = s:join()
self:_remove_socket(s)
Expand Down
2 changes: 1 addition & 1 deletion kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function _M:init_cp(manager)
local ok, err = kong.db.clustering_data_planes:upsert({ id = node_id }, {
last_seen = ngx.time(),
hostname = node_id,
ip = "127.0.7.1", -- XXX how to get the corret ip?
ip = kong.rpc.client_ips[node_id], -- try to get the corret ip
version = "3.8.0.0",
sync_status = CLUSTERING_SYNC_STATUS.NORMAL,
config_hash = string.format("%032d", default_namespace.version),
Expand Down
2 changes: 1 addition & 1 deletion spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for _, strategy in helpers.each_strategy() do
local json = cjson.decode(body)

for _, v in pairs(json.data) do
if v.rpc_capabilities and #v.rpc_capabilities ~= 0 then
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)
--assert.same({ "kong.debug.log_level.v1", }, v.rpc_capabilities)
Expand Down

0 comments on commit d81b020

Please sign in to comment.