AlinsRan commented on code in PR #13992: URL: https://github.com/apache/apisix/pull/13992#discussion_r4131420150
########## 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: Valid: a rename or deletion during a long-lived session could label the zone with the name picked in preread and the status and connection count with the one fetched at log time. The resolved pair is now cached on the request context the first time it is computed and reused, so the lookup happens once per session and all four metrics name it the same way. The new TEST 10 in `t/stream-plugin/prometheus-metrics-service.t` renames the service while a session is open and checks the status stays under the first name. Fixed in a20a97fb1. -- 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]
