Files
llmgw/internal/store/migrations/sqlite/0012_usage_diagnostics.sql
Ilker ManapandClaude Opus 5.5 f8572fb5ee Follow one request from its id to the replica that served it
"Why was this request slow?" had no answer. Nothing tied a request to the
replica that served it, the time admission held it went out in a response
header and was never kept, and the only per-request log lines were for
disconnects, early stream ends and upstream retries.

Every request now has an id: the client's X-Request-Id when it is a plain
string of reasonable length, otherwise one the gateway makes. It is set on
the response before anything else, so a request refused as malformed can be
named too, and forwarded to the engine. One access log line per request
carries it with the model asked for and served, the replica, status, time in
the queue, time to the first token, total time, tokens, and the key,
project and user.

Usage records gain the id, the replica, queue time and time to first token,
tried against a restored copy of the live store before being shipped: 591
rows kept, columns and index in place. `llmgw ctl request ID` reads one back
through the admin API.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 02:36:45 +02:00

14 lines
819 B
SQL

-- What a request went through, beside what it cost: which replica answered,
-- how long it queued in admission, and how long the first token took. Without
-- them "why was my request slow" had no answer — the queue time went out in a
-- response header and nowhere else.
--
-- request_id is the id the client sent or the gateway made, echoed in the
-- X-Request-Id header and the access log, so one request can be followed from
-- the client's error to the replica that served it.
ALTER TABLE usage ADD COLUMN request_id TEXT NOT NULL DEFAULT '';
ALTER TABLE usage ADD COLUMN replica TEXT NOT NULL DEFAULT '';
ALTER TABLE usage ADD COLUMN queue_ms INTEGER NOT NULL DEFAULT 0;
ALTER TABLE usage ADD COLUMN ttft_ms INTEGER NOT NULL DEFAULT 0;
CREATE INDEX usage_by_request ON usage(request_id) WHERE request_id <> '';