nic-6443 opened a new pull request, #13317: URL: https://github.com/apache/apisix/pull/13317
### Description When the ai-proxy plugin sends requests via cosocket (`resty.http`), nginx's upstream module is bypassed entirely, leaving `$upstream_status`, `$upstream_addr`, `$upstream_response_time`, `$upstream_header_time`, `$upstream_connect_time`, `$upstream_response_length`, `$upstream_host`, `$upstream_scheme`, and `$upstream_uri` empty or defaulted in access logs. This uses the FFI functions from apisix-nginx-module 1.19.4 (`push_upstream_state` / `update_upstream_state`) to populate these variables from Lua after cosocket requests complete. ### Changes **Transport layer (`ai-transport/http.lua`)** - Capture timing info (connect_time, header_time, total time) during the HTTP lifecycle - Attach upstream metadata (addr, host, scheme, uri, timings) to the response object - Close cosocket on all error paths (connect failure, encode failure, request failure) **Plugin layer (`ai-proxy/base.lua`)** - Call `push_upstream_state()` after getting a response (or on transport errors) to populate addr, status, connect_time, header_time - Call `update_upstream_state()` after body is fully consumed to populate response_time and response_length - Set `upstream_uri`, `upstream_host`, and `upstream_scheme` to reflect the actual LLM provider endpoint - Close cosocket on early return paths (429/5xx, missing body_reader) - Works for both `ai-proxy` and `ai-proxy-multi` **Runtime** - Bump apisix-runtime to 1.3.5 (includes apisix-nginx-module 1.19.4) **Docs** - Document the newly populated upstream variables in the ai-proxy access log section - Update the example access log entry to show populated values ### Tests - `t/plugin/ai-proxy-upstream-vars.t`: New test validating upstream variable population (addr, status, response_time, uri, host) for streaming and non-streaming - Updated `t/plugin/ai-proxy3.t`: Adjusted access_log regex patterns to match populated upstream variables -- 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]
