@@ -341,8 +341,6 @@ function _M.load(config)
341
341
return local_plugins
342
342
end
343
343
344
- local exporter = require (" apisix.plugins.prometheus.exporter" )
345
-
346
344
if ngx .config .subsystem == " http" then
347
345
if not http_plugin_names then
348
346
core .log .error (" failed to read plugin list from local file" )
@@ -356,15 +354,6 @@ function _M.load(config)
356
354
if not ok then
357
355
core .log .error (" failed to load plugins: " , err )
358
356
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
368
357
end
369
358
end
370
359
808
797
end
809
798
810
799
811
- function _M .init_worker ()
800
+ function _M .init_prometheus ()
812
801
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" )
813
804
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 ()
821
810
end
811
+ end
822
812
813
+
814
+ function _M .init_worker ()
823
815
-- someone's plugin needs to be initialized after prometheus
824
816
-- see https://github.com/apache/apisix/issues/3286
825
817
_M .load ()
0 commit comments