yurkovoznyak commented on code in PR #12383:
URL: https://github.com/apache/apisix/pull/12383#discussion_r2454332090


##########
apisix/plugin.lua:
##########
@@ -808,18 +797,21 @@ do
 end
 
 
-function _M.init_worker()
+function _M.init_prometheus()
     local _, http_plugin_names, stream_plugin_names = get_plugin_names()
+    local enabled_in_http = core.table.array_find(http_plugin_names, 
"prometheus")
+    local enabled_in_stream = core.table.array_find(stream_plugin_names, 
"prometheus")
 
-    -- some plugins need to be initialized in init* phases
-    if is_http and core.table.array_find(http_plugin_names, "prometheus") then
-        local prometheus_enabled_in_stream =
-            core.table.array_find(stream_plugin_names, "prometheus")
-        
require("apisix.plugins.prometheus.exporter").http_init(prometheus_enabled_in_stream)
-    elseif not is_http and core.table.array_find(stream_plugin_names, 
"prometheus") then
-        require("apisix.plugins.prometheus.exporter").stream_init()
+    -- For stream-only mode, there are separate calls in ngx_tpl.lua.
+    -- And for other modes, whether in stream or http plugins,
+    -- the prometheus exporter needs to be initialized.
+    if is_http and (enabled_in_http or enabled_in_stream) then
+        require("apisix.plugins.prometheus.exporter").init_exporter_timer()
     end
+end
 
+
+function _M.init_worker()
     -- someone's plugin needs to be initialized after prometheus

Review Comment:
   Hi @SkyeYoung, I'm using Prometheus metrics in my custom plugin, and with 
this change, there is no guarantee that the prometheus plugin is loaded before 
mine. What is the correct approach for defining custom metrics now?
   
   Sorry for commenting on a closed PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to