Skip to content

Commit

Permalink
chore: rename control_plane_reachable to control_plane_connected
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Jan 10, 2025
1 parent 7ef8547 commit ee922f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions kong/clustering/data_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function _M.new(clustering)
end


local function set_control_plane_reachable(reachable)
local ok, err = ngx.shared.kong:safe_set("control_plane_reachable", reachable)
local function set_control_plane_connected(reachable)
local ok, err = ngx.shared.kong:safe_set("control_plane_connected", reachable)
if not ok then
ngx_log(ngx_ERR, _log_prefix, "failed to set controlplane_reachable key in shm to " .. reachable .. " :", err)
end
Expand All @@ -87,7 +87,7 @@ function _M:init_worker(basic_info)

self.plugins_list = basic_info.plugins
self.filters = basic_info.filters
set_control_plane_reachable(false)
set_control_plane_connected(false)

local function start_communicate()
assert(ngx.timer.at(0, function(premature)
Expand Down Expand Up @@ -148,13 +148,13 @@ local function send_ping(c, log_suffix)

local _, err = c:send_ping(hash)
if err then
set_control_plane_reachable(false)
set_control_plane_connected(false)
ngx_log(is_timeout(err) and ngx_NOTICE or ngx_WARN, _log_prefix,
"unable to send ping frame to control plane: ", err, log_suffix)

-- only log a ping if the hash changed
else
set_control_plane_reachable(true)
set_control_plane_connected(true)
if hash ~= prev_hash then
prev_hash = hash
ngx_log(ngx_INFO, _log_prefix, "sent ping frame to control plane with hash: ", hash, log_suffix)
Expand Down Expand Up @@ -210,7 +210,7 @@ function _M:communicate(premature)

local c, uri, err = clustering_utils.connect_cp(self, "/v1/outlet")
if not c then
set_control_plane_reachable(false)
set_control_plane_connected(false)
ngx_log(ngx_WARN, _log_prefix, "connection to control plane ", uri, " broken: ", err,
" (retrying after ", reconnection_delay, " seconds)", log_suffix)

Expand Down Expand Up @@ -243,7 +243,7 @@ function _M:communicate(premature)
filters = self.filters,
labels = labels, }))
if err then
set_control_plane_reachable(false)
set_control_plane_connected(false)
ngx_log(ngx_ERR, _log_prefix, "unable to send basic information to control plane: ", uri,
" err: ", err, " (retrying after ", reconnection_delay, " seconds)", log_suffix)

Expand All @@ -253,7 +253,7 @@ function _M:communicate(premature)
end))
return
end
set_control_plane_reachable(true)
set_control_plane_connected(true)

local config_semaphore = semaphore.new(0)

Expand Down Expand Up @@ -360,19 +360,19 @@ function _M:communicate(premature)
local data, typ, err = c:recv_frame()
if err then
if not is_timeout(err) then
set_control_plane_reachable(false)
set_control_plane_connected(false)
return nil, "error while receiving frame from control plane: " .. err
end

local waited = ngx_time() - last_seen
if waited > PING_WAIT then
set_control_plane_reachable(false)
set_control_plane_connected(false)
return nil, "did not receive pong frame from control plane within " .. PING_WAIT .. " seconds"
end

goto continue
end
set_control_plane_reachable(true)
set_control_plane_connected(true)

if typ == "close" then
ngx_log(ngx_DEBUG, _log_prefix, "received close frame from control plane", log_suffix)
Expand Down
12 changes: 6 additions & 6 deletions kong/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ local function init()
nil,
prometheus.LOCAL_STORAGE)
if role == "data_plane" then
metrics.cp_reachable = prometheus:gauge("control_plane_reachable",
"Control plane reachable from gateway, " ..
"0 is unreachable",
metrics.cp_connected = prometheus:gauge("control_plane_connected",
"Kong connected to controlplane, " ..
"0 is unconnected",
nil,
prometheus.LOCAL_STORAGE)
end
Expand Down Expand Up @@ -460,11 +460,11 @@ local function metric_data(write_fn)
end

if role == "data_plane" then
local cp_reachable = ngx.shared.kong:get("control_plane_reachable")
local cp_reachable = ngx.shared.kong:get("control_plane_connected")
if cp_reachable then
metrics.cp_reachable:set(1)
metrics.cp_connected:set(1)
else
metrics.cp_reachable:set(0)
metrics.cp_connected:set(0)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/03-plugins/26-prometheus/04-status_api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ describe("CP/DP connectivity state #", function ()

it("exposes controlplane connectivity status", function ()
local body = get_metrics()
assert.matches('kong_control_plane_reachable 1', body, nil, true)
assert.matches('kong_control_plane_connected 1', body, nil, true)

helpers.stop_kong("prom_cp")
local body = get_metrics()
assert.matches('kong_control_plane_reachable 0', body, nil, true)
assert.matches('kong_control_plane_connected 0', body, nil, true)
end)
end)

0 comments on commit ee922f2

Please sign in to comment.