This is an automated email from the ASF dual-hosted git repository.
shreemaanabhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new a33a41a10 fix: avoid initialising stream plugins in http subsystem
(#13064)
a33a41a10 is described below
commit a33a41a10ef75c61dc93722aef6d2de215eb95bc
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Thu Mar 5 17:10:27 2026 +0545
fix: avoid initialising stream plugins in http subsystem (#13064)
---
apisix/plugin.lua | 12 ++++++++++++
apisix/plugins/prometheus/exporter.lua | 18 ------------------
t/plugin/prometheus4.t | 27 +++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 6e80877b9..8b4177ae0 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -121,6 +121,11 @@ local function unload_plugin(name, plugin_type)
return
end
+ -- Don't unload stream plugins in the HTTP subsystem.
+ if plugin_type == PLUGIN_TYPE_STREAM and is_http then
+ return
+ end
+
local pkg_name = "apisix.plugins." .. name
if plugin_type == PLUGIN_TYPE_STREAM then
pkg_name = "apisix.stream.plugins." .. name
@@ -197,6 +202,13 @@ local function load_plugin(name, plugins_list, plugin_type)
plugin.attr = plugin_attr(name)
core.table.insert(plugins_list, plugin)
+ -- Don't initialize stream plugins in the HTTP subsystem.
+ -- The modules are loaded for schema validation (admin API),
+ -- but init/workflow_handler functions must only run in the stream
subsystem.
+ if plugin_type == PLUGIN_TYPE_STREAM and is_http then
+ return
+ end
+
if plugin.init then
plugin.init()
end
diff --git a/apisix/plugins/prometheus/exporter.lua
b/apisix/plugins/prometheus/exporter.lua
index cfa56bfa1..49073be6c 100644
--- a/apisix/plugins/prometheus/exporter.lua
+++ b/apisix/plugins/prometheus/exporter.lua
@@ -120,15 +120,6 @@ end
function _M.http_init(prometheus_enabled_in_stream)
- -- FIXME:
- -- Now the HTTP subsystem loads the stream plugin unintentionally, which
shouldn't happen.
- -- But this part did not show any issues during testing,
- -- it's just to prevent the same problem from happening again.
- if ngx.config.subsystem ~= "http" then
- core.log.warn("prometheus plugin http_init should not be called in
stream subsystem")
- return
- end
-
-- todo: support hot reload, we may need to update the lua-prometheus
-- library
if ngx.get_phase() ~= "init" and ngx.get_phase() ~= "init_worker" then
@@ -275,15 +266,6 @@ end
function _M.stream_init()
- -- FIXME:
- -- Now the HTTP subsystem loads the stream plugin unintentionally, which
shouldn't happen.
- -- It breaks the initialization logic of the plugin,
- -- here it is temporarily fixed using a workaround.
- if ngx.config.subsystem ~= "stream" then
- core.log.warn("prometheus plugin stream_init should not be called in
http subsystem")
- return
- end
-
if ngx.get_phase() ~= "init" and ngx.get_phase() ~= "init_worker" then
return
end
diff --git a/t/plugin/prometheus4.t b/t/plugin/prometheus4.t
index 160a13d5b..d30946a7b 100644
--- a/t/plugin/prometheus4.t
+++ b/t/plugin/prometheus4.t
@@ -334,3 +334,30 @@ GET /apisix/prometheus/metrics
--- error_code: 200
--- response_body_like eval
qr/apisix_node_info\{hostname="[^"]+",version="\d+\.\d+\.\d+"\} \d+/
+
+
+
+=== TEST 15: verify no errors when prometheus is enabled in both http and
stream subsystems
+--- yaml_config
+deployment:
+ admin:
+ admin_key: null
+apisix:
+ node_listen: 1984
+ proxy_mode: http&stream
+ stream_proxy:
+ tcp:
+ - addr: 9100
+ udp:
+ - 9200
+plugins:
+ - prometheus
+ - public-api
+stream_plugins:
+ - prometheus
+plugin_attr:
+ prometheus:
+ refresh_interval: 0.1
+--- request
+GET /apisix/prometheus/metrics
+--- error_code: 200