@@ -341,8 +341,6 @@ function _M.load(config)
341341 return local_plugins
342342 end
343343
344- local exporter = require (" apisix.plugins.prometheus.exporter" )
345-
346344 if ngx .config .subsystem == " http" then
347345 if not http_plugin_names then
348346 core .log .error (" failed to read plugin list from local file" )
@@ -356,15 +354,6 @@ function _M.load(config)
356354 if not ok then
357355 core .log .error (" failed to load plugins: " , err )
358356 end
359-
360- local enabled = core .table .array_find (http_plugin_names , " prometheus" ) ~= nil
361- local active = exporter .get_prometheus () ~= nil
362- if not enabled then
363- exporter .destroy ()
364- end
365- if enabled and not active then
366- exporter .http_init ()
367- end
368357 end
369358 end
370359
808797end
809798
810799
811- function _M .init_worker ()
800+ function _M .init_prometheus ()
812801 local _ , http_plugin_names , stream_plugin_names = get_plugin_names ()
802+ local enabled_in_http = core .table .array_find (http_plugin_names , " prometheus" )
803+ local enabled_in_stream = core .table .array_find (stream_plugin_names , " prometheus" )
813804
814- -- some plugins need to be initialized in init* phases
815- if is_http and core .table .array_find (http_plugin_names , " prometheus" ) then
816- local prometheus_enabled_in_stream =
817- core .table .array_find (stream_plugin_names , " prometheus" )
818- require (" apisix.plugins.prometheus.exporter" ).http_init (prometheus_enabled_in_stream )
819- elseif not is_http and core .table .array_find (stream_plugin_names , " prometheus" ) then
820- require (" apisix.plugins.prometheus.exporter" ).stream_init ()
805+ -- For stream-only mode, there are separate calls in ngx_tpl.lua.
806+ -- And for other modes, whether in stream or http plugins,
807+ -- the prometheus exporter needs to be initialized.
808+ if is_http and (enabled_in_http or enabled_in_stream ) then
809+ require (" apisix.plugins.prometheus.exporter" ).init_exporter_timer ()
821810 end
811+ end
822812
813+
814+ function _M .init_worker ()
823815 -- someone's plugin needs to be initialized after prometheus
824816 -- see https://github.com/apache/apisix/issues/3286
825817 _M .load ()
0 commit comments