janiussyafiq commented on code in PR #13659:
URL: https://github.com/apache/apisix/pull/13659#discussion_r3526327510


##########
apisix/plugins/prometheus/exporter.lua:
##########
@@ -974,6 +1019,80 @@ function _M.dec_llm_active_connections(ctx)
     inc_llm_active_connections(ctx, -1)
 end
 
+
+local AI_CACHE_STATUS_METRICS = {
+    HIT    = "ai_cache_hits_total",
+    MISS   = "ai_cache_misses_total",
+    BYPASS = "ai_cache_bypasses_total",
+}
+
+
+function _M.inc_ai_cache_status(ctx, status, layer)
+    local name = AI_CACHE_STATUS_METRICS[status]
+    if not name or not metrics or not metrics[name] then
+        return
+    end
+
+    local vars = ctx.var
+
+    local route_id = ""
+    local balancer_ip = ctx.balancer_ip or ""
+    local service_id = ""
+    local consumer_name = ctx.consumer_name or ""
+
+    local matched_route = ctx.matched_route and ctx.matched_route.value
+    if matched_route then
+        route_id = matched_route.id
+        service_id = matched_route.service_id or ""
+    end
+
+    local disabled_label_metric_map = get_disabled_label_metric_map()
+
+    if status == "HIT" then
+        metrics[name]:inc(1,
+            get_enabled_label_values_for_metric(name, 
disabled_label_metric_map,
+                layer or "exact", route_id, service_id, consumer_name, 
balancer_ip,
+                vars.request_type, vars.request_llm_model, vars.llm_model,

Review Comment:
   fixed



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