Skip to content

Commit

Permalink
rework goto statements
Browse files Browse the repository at this point in the history
  • Loading branch information
omegabytes committed Dec 10, 2022
1 parent 393daa9 commit 739a308
Showing 1 changed file with 38 additions and 45 deletions.
83 changes: 38 additions & 45 deletions lua-tree/share/lua/5.1/kong/pdk/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,57 +169,50 @@ local function new(self)
-- get workers Lua VM allocated memory

do
if not shared.kong then
goto lua_shared_dicts
end

local keys, err = shared.kong:get_keys()
if not keys then
res.workers_lua_vms.err = "could not get kong shm keys: " .. err
goto lua_shared_dicts
end

if #keys == 1024 then
-- Preventive warning log for future Kong developers, in case 'kong'
-- shm becomes mis-used or over-used.
ngx.log(ngx.WARN, "ngx.shared.kong:get_keys() returned 1024 keys, ",
"but it may have more")
end

for i = 1, #keys do
local pid = match(keys[i], "kong:mem:(%d+)")
if not pid then
goto continue
end

local w = self.table.new(0, 2)
w.pid = tonumber(pid)

local count, err = shared.kong:get("kong:mem:" .. pid)
if err then
w.err = "could not get worker's HTTP Lua VM memory (pid: " ..
pid .. "): " .. err

elseif type(count) ~= "number" then
w.err = "could not get worker's HTTP Lua VM memory (pid: " ..
pid .. "): reported value is corrupted"

if shared.kong then

local keys, err = shared.kong:get_keys()
if keys then

if #keys == 1024 then
-- Preventive warning log for future Kong developers, in case 'kong'
-- shm becomes mis-used or over-used.
ngx.log(ngx.WARN, "ngx.shared.kong:get_keys() returned 1024 keys, ",
"but it may have more")
end

for i = 1, #keys do
local pid = match(keys[i], "kong:mem:(%d+)")
if pid then
local w = self.table.new(0, 2)
w.pid = tonumber(pid)

local count, err = shared.kong:get("kong:mem:" .. pid)
if err then
w.err = "could not get worker's HTTP Lua VM memory (pid: " ..
pid .. "): " .. err

elseif type(count) ~= "number" then
w.err = "could not get worker's HTTP Lua VM memory (pid: " ..
pid .. "): reported value is corrupted"

else
count = count * 1024 -- reported value is in kb
w.http_allocated_gc = convert_bytes(count, unit, scale)
end

insert(res.workers_lua_vms, w)
end
end

sort(res.workers_lua_vms, sort_pid_asc)
else
count = count * 1024 -- reported value is in kb
w.http_allocated_gc = convert_bytes(count, unit, scale)
res.workers_lua_vms.err = "could not get kong shm keys: " .. err
end

insert(res.workers_lua_vms, w)

::continue::
end

sort(res.workers_lua_vms, sort_pid_asc)
end

-- get lua_shared_dicts allocated slabs
::lua_shared_dicts::

for _, shm in ipairs(shms) do
local allocated = shm.capacity - shm.zone:free_space()

Expand Down

0 comments on commit 739a308

Please sign in to comment.