Repository navigation
feat: report per-connection usage - #310
Merged
Merged
Conversation
Add an opt-in per-connection usage handle. With Relay::with_connection_usage(observer), the relay hands the embedder a ConnectionUsage for every accepted connection once its scope is resolved and its interface classified. It carries the QUIC connection ID, interface, transport, reported scope, and totals since the connection was accepted: UDP bytes, MoQT objects and MoQT groups in each direction. The embedder reads it on its own schedule; the relay keeps no timer, registry or lock shared between connections. When the connection ends, the totals are frozen and the connection is released. moq-transport counts objects and groups as they cross a session, on subgroup streams, as datagrams and as FETCH records, including FETCH responses relayed by FetchRequested::proxy, and exposes them through Session::traffic(). A group counts once, when its first object crosses, even when it is split across several subgroup streams. Consecutive datagrams of one group skip the per-session lookup. The reported scope comes only from the new Coordinator::metrics_scope_id(), which defaults to None; ScopeInfo::scope_id is never reported because its format is coordinator-defined and may carry credentials. It is set only after authorization succeeds, so a refused session is never reported under a tenant. A connection refused at scope resolution is not reported. moq-native-ietf gains Server::accept_with_stats and re-exports rustls; moq-relay-ietf re-exports moq_native_ietf. Their types appear in the public APIs.
Report a connection refused at scope resolution. The connection tagger needs only the peer address, TLS SNI and path, so it now runs before scope resolution and the usage handle is created then; a refused connection is reported without a tenant, as one refused at authorization already was. Count a group whose first object arrives after a newer group's. Each track now remembers which of the 64 groups below its newest it has seen, so a late group inside that window counts once. A group first seen further behind is not counted, rather than risk counting twice one whose mark has left the window. Forget the least recently used track at the 4,096-track cap instead of every track, so groups in flight on active tracks are not counted twice.
…its tenant Only the call order kept a session refused at authorization from being reported under its tenant: reported_scope took an authorized flag that the relay always passed as true, so its test covered a branch the relay never took. Drop the flag and test the rule through the relay instead, with a coordinator that names a tenant and then denies the session. Reporting the tenant before authorization now fails that test. Create the usage guard before handing the usage to the observer, so an observer that panics still closes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in, per-connection usage reporting to the relay. An embedder registers a
ConnectionUsageObserverwithRelay::with_connection_usage, and the relay hands it aConnectionUsagehandle for every accepted connection. The handle exposes running totals that the embedder can read at any time, plus the connection's identity and tenant. When no observer is registered, nothing is read and the counting hooks are the only cost.This targets draft-18 (
main). A draft-16 backport will follow separately.What is reported
publicorinternal(SessionInterface)webtransportorraw_quicCoordinator::metrics_scope_id, or none (see below)Totals run from when the connection was accepted. When the connection ends, its totals are frozen, so a final read after close still gets everything.
How counting works
moq-transportgains aTrafficCounterper session half, exposed throughSession::traffic()asSessionTraffic/TrafficSnapshot. Counting happens where objects actually cross the wire:recv_subgroup, datagram receive, andFetch::next_record.serve_datagrams,FetchWriter::write_record, andFetchRequested::proxy_body, so FETCH responses the relay proxies from upstream are counted at every hop.A group can be split across several subgroup streams, and a late subgroup can arrive after newer groups. So each track keeps a 64-group bitmap behind its newest group, and a group counts only the first time it is seen inside that window. A connection tracks at most 4,096 tracks per direction and evicts the least recently used beyond that, which bounds memory for a client that touches many tracks.
Consecutive datagrams of one group skip the counter's lock. The receive loop remembers the last group it counted, so a burst of datagrams takes the lock once.
Tenant attribution
The reported scope comes only from the new
Coordinator::metrics_scope_id. It defaults toNone, so existing coordinators report nothing.ScopeInfo::scope_idis never reported directly, because its format is coordinator-defined and can contain credentials. The relay asks formetrics_scope_idonly after the session is authorized.The usage handle is created once MoQT setup completes, before scope resolution and authorization. A connection refused at either step is still reported, but without a scope, so a refused session's traffic is never attributed to a tenant.
AGENTS.mdrecords this rule.API changes
moq-transport:Session::traffic(),SessionTraffic,TrafficSnapshot.moq-native-ietf:Server::accept_with_stats,ConnectionStatistics,ConnectionStatisticsSnapshot; re-exportsrustls, whose types appear in its public API.moq-relay-ietf:Relay::with_connection_usage,ConnectionUsage,ConnectionUsageObserver,UsageSnapshot,Coordinator::metrics_scope_id(default method, so not breaking); re-exportsmoq_native_ietf, whose types appear inRelayConfigandCoordinator::lookup.Known gaps
Testing
metrics_scope_iddoes not expose the routing scope.