Copilot commented on code in PR #13992:
URL: https://github.com/apache/apisix/pull/13992#discussion_r4131165786


##########
apisix/plugins/prometheus/exporter.lua:
##########
@@ -317,6 +321,40 @@ local STREAM_PUBLISHED_PREFIX = "stream_bytes_published:"
 local STREAM_PUBLISH_LOCK = "stream_bytes_publishing"
 local STREAM_PUBLISH_LOCK_TTL = 10
 
+
+-- the same rule as the http metrics: the id, or the name with prefer_name
+local function stream_service_labels(conf, ctx)
+    local service_id = ctx.service_id
+    local name = ctx.service_name
+    if not service_id then
+        -- a route with an upstream_id keeps its service_id without the service
+        -- being merged in, and the http metrics still label it with it
+        service_id = ctx.matched_route.value.service_id
+        if not service_id then
+            return "", ""
+        end
+
+        local service = conf.prefer_name == true and service_fetch(service_id)
+        name = service and service.value.name

Review Comment:
   For a Route that has both `upstream_id` and `service_id`, this fetch runs 
independently in preread and log. If a long-lived session spans a Service 
rename or deletion, the zone keeps the label selected in preread while 
`stream_status` and `stream_connection_total` resolve a different label at log 
time. Cache the resolved pair in `ctx` on first use and reuse it so all four 
metrics identify the session consistently.
   
   This issue also appears on line 342 of the same file.



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