Expand description
Process-wide usage event sink (enterprise#17).
usage_meter::record is the single choke-point every measured turn flows
through (streaming and non-streaming alike). This module lets a run-mode
(the self-hosted gateway) subscribe to that stream without the proxy knowing
anything about Postgres: the gateway installs an mpsc sender at startup,
and push forwards each finalized RealUsage.
Fail-open by construction (enterprise#12): push never blocks and never
errors the request path — when no sink is installed it is a no-op, and when
the writer falls behind the event is dropped (counted, visible in logs)
rather than back-pressuring live LLM traffic.
Functions§
- dropped_
count - Events dropped because the sink was full/closed (observability, #34).
- install
- Installs the process-wide sink. First caller wins (one gateway run-mode per
process); later calls return
falseand change nothing. - installed
- True once a sink is installed (the gateway run-mode is active).
- pending_
count - Events currently queued (sent but not yet consumed by the writer). Used by the gateway’s graceful shutdown to drain metering before exit (#51).
- push
- Forwards one finalized usage record to the sink, if any. Never blocks: on a full or closed channel the event is dropped and counted.