Skip to content

bug: apisix_upstream_response_time and llm_time_to_first_token have inconsistent time units based on HTTP status code #13698

Description

@RGZingYang

Current Behavior

Image The two metrics use different time units depending on upstream HTTP status: HTTP 200 responses: value in milliseconds Non-200 responses (4xx/5xx): value in seconds This inconsistency breaks monitoring dashboards, latency aggregation and alert rules, as we cannot apply unified conversion logic for latency statistics and SLA calculation.

Expected Behavior

No response

Error Logs

No response

Steps to Reproduce

        -- Upstream responded — mark source before any early returns
        core.response.set_response_source(ctx, "upstream")

        if res.status == 429 or (res.status >= 500 and res.status < 600) then
            if res._t0 then
                apisix_upstream.update_upstream_state({
                    response_time = (ngx_now() - res._t0) * 1000,
                })
            end
            if res._httpc then
                res._httpc:close()
            end
            return res.status
        end

ctx.var.apisix_upstream_response_time and ctx.var.llm_time_to_first_token are not assigned values.

Environment

  • APISIX version (run apisix version): 3.17
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions