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


##########
apisix/plugin.lua:
##########
@@ -356,15 +354,6 @@ function _M.load(config)
             if not ok then
                 core.log.error("failed to load plugins: ", err)
             end
-
-            local enabled = core.table.array_find(http_plugin_names, 
"prometheus") ~= nil
-            local active  = exporter.get_prometheus() ~= nil
-            if not enabled then
-                exporter.destroy()
-            end
-            if enabled and not active then
-                exporter.http_init()
-            end

Review Comment:
   [The original code](https://github.com/apache/apisix/pull/11117) skipped 
[plugin.init()](https://github.com/SkyeYoung/apisix/blob/72c6f229e681b36efa226b51713ebdb23075a575/apisix/plugin.lua#L191-L192)
 and 
[old_plugin.destroy()](https://github.com/SkyeYoung/apisix/blob/72c6f229e681b36efa226b51713ebdb23075a575/apisix/plugin.lua#L121-L122)
 used in 
https://github.com/apache/apisix/blob/6fb9bf94281525c1fca397f681b4890b69440369/apisix/plugin.lua,
 and implemented the overload of the prometheus plugin for some reason that I 
have not yet understood (perhaps because `prometheus.lua` originally did not 
contain two functions init and destroy).
   
   ---
   
   The initial reason was that even after separating the `init_prometheus` part 
and placing it at the end of `init_worker`, directly calling `exporter_timer()` 
would still cause an error. After debugging, another initialization logic was 
found here. This is obviously redundant.
   
   Currently, we provide `init` and `destroy` functions in `prometheus.lua`, 
allowing the initialization and reloading of the prometheus plugin to be 
handled within the plugin's own files, reducing coupling.
   
   



-- 
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