From 5d995c595f832ae1a731555acf97bb0206db62c7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 30 Sep 2024 14:19:53 -0400 Subject: [PATCH] fix(prometheus): delayed require of WasmX module Co-authored-by: Caio Ramos Casimiro --- kong/plugins/prometheus/wasmx.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kong/plugins/prometheus/wasmx.lua b/kong/plugins/prometheus/wasmx.lua index 7843155e62a7..23b6487d0043 100644 --- a/kong/plugins/prometheus/wasmx.lua +++ b/kong/plugins/prometheus/wasmx.lua @@ -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 fmt = string.format @@ -161,6 +161,19 @@ _M.metric_data = function() local parsed = {} local buf = buf_new() + -- 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