Skip to content

Commit

Permalink
fix(prometheus): delayed require of WasmX module
Browse files Browse the repository at this point in the history
Co-authored-by: Caio Ramos Casimiro <caiorcasimiro@gmail.com>
  • Loading branch information
hishamhm and casimiro committed Oct 31, 2024
1 parent 7fc9b1c commit 3f444c0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion kong/plugins/prometheus/wasmx.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local buffer = require "string.buffer"
local wasm = require "kong.runloop.wasm"
local wasmx_shm = require "resty.wasmx.shm"
local wasmx_shm


local str_sub = string.sub
Expand Down Expand Up @@ -179,6 +179,19 @@ _M.metric_data = function()

metrics_data_buf:reset()

-- delayed require of the WasmX module, to ensure it is loaded
-- after ngx_wasm_module.so is loaded.
if not wasmx_shm then
local ok, _wasmx_shm = pcall(require, "resty.wasmx.shm")
if ok then
wasmx_shm = _wasmx_shm
end
end

if not wasmx_shm then
return
end

wasmx_shm.metrics:lock()

for key in wasmx_shm.metrics:iterate_keys() do
Expand Down

0 comments on commit 3f444c0

Please sign in to comment.