AlinsRan commented on code in PR #13878:
URL: https://github.com/apache/apisix/pull/13878#discussion_r3870053902


##########
apisix/plugins/prometheus.lua:
##########
@@ -109,8 +109,16 @@ end
 
 function _M.init()
     local local_conf = core.config.local_conf()
-    local enabled_in_stream = core.table.array_find(local_conf.stream_plugins, 
"prometheus")
-    exporter.http_init(enabled_in_stream)
+    -- Not `stream_plugins` from config.yaml: that list is only the boot-time
+    -- default, and /apisix/plugins in etcd can turn the stream prometheus
+    -- plugin on later. This runs whenever the plugin is loaded, so building
+    -- `metrics` without the L4 gauges here would leave
+    -- collect_stream_zone_metrics() stopped at its first guard for the rest of
+    -- the process's life. Whether the stream subsystem runs at all is the
+    -- thing that does not change under APISIX.
+    local proxy_mode = local_conf.apisix.proxy_mode
+    local stream_enabled = proxy_mode == "stream" or proxy_mode == 
"http&stream"
+    exporter.http_init(stream_enabled)

Review Comment:
   **Removing the gate alone wouldn't help.** With prometheus in neither local 
list, `http_init()` returns at the phase guard (`exporter.lua:454`), 
`prometheus` stays nil, and the timer returns at `if not prometheus` (`:1169`) 
on every tick.
   
   Making that path work means removing the phase guard, i.e. the `-- todo: 
support hot reload` right above it. Separate issue.
   
   **It's also a narrow config:** Admin API off (`plugin.lua:932`) plus 
prometheus deleted from the local `plugins` by hand. "After startup" isn't part 
of it. The first `/plugins` sync runs in a timer (`config_etcd.lua:1112`), so a 
pre-seeded etcd hits the same guard.
   
   **The default list is the case here, not a mask.** Stock `config.yaml` has 
prometheus in `plugins` and not in `stream_plugins`, which is why the L4 half 
broke and the HTTP half didn't.
   
   The fix is in `_M.init()`. `plugin.load()` builds the exporter in 
init_worker off that list, previously without the L4 gauges. The later etcd 
reload keeps them, since `destroy()` leaves `metrics` intact (`:1370`). The 
added case fails on master.
   



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