feat(libmoq, moq-ffi): expose connection stats#1783
Conversation
Surface a point-in-time snapshot of the underlying QUIC/WebTransport connection (RTT, send/receive bandwidth estimates, byte/packet counters) through both FFI layers. The transport already exposed these via web_transport_trait::Stats; moq-net just wasn't surfacing them. - moq-net: new public ConnectionStats struct (non_exhaustive, all fields Option) and Session::stats(), reading the transport counters plus the MoQ PROBE recv-bandwidth estimate. - moq-native: ConnectionStatsReader + Reconnect::stats() so the live session inside the reconnect loop can be polled; returns None while reconnecting. - libmoq: moq_session_stats(session, &dst) filling a moq_connection_stats struct. Each metric carries a *_valid flag since availability is backend-dependent (a false flag is not a zero value). - moq-ffi: MoqSession.stats() returning a MoqConnectionStats record with Option<u64> fields, surfaced automatically by the py/swift/kt/go wrappers. - docs: connection-stats section in the C doc, stats() snippets in the Swift/Kotlin quickstarts. Additive (non-breaking) API changes. Per-track stats and the js/net browser mirror are left as follow-ups. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThis pull request introduces connection statistics reporting across the full library stack. A new 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rs/libmoq/src/api.rs`:
- Around line 95-127: Add documentation comments using `///` for all the boolean
`*_valid` fields in the struct that are currently undocumented. These fields
include send_rate_valid, recv_rate_valid, bytes_sent_valid,
bytes_received_valid, bytes_lost_valid, packets_sent_valid,
packets_received_valid, and packets_lost_valid. Each `*_valid` field should have
a doc comment explaining that it indicates whether the corresponding measurement
field is valid, to ensure complete API documentation for C consumers.
In `@rs/moq-ffi/src/session.rs`:
- Line 181: The rtt_us field assignment uses a lossy cast from u128 to u64 via
the as operator, which can silently truncate large duration values. Replace the
direct as u64 cast in the map closure with a checked conversion using try_into()
method, which will return a Result that can be properly handled to prevent
overflow instead of wrapping.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4f4c83f5-6022-41cc-b316-65d839cde832
📒 Files selected for processing (8)
doc/lib/c/index.mddoc/lib/kt/index.mddoc/lib/swift/index.mdrs/libmoq/src/api.rsrs/libmoq/src/session.rsrs/moq-ffi/src/session.rsrs/moq-native/src/reconnect.rsrs/moq-net/src/session.rs
Address review feedback: - Document every `*_valid` flag in `moq_connection_stats` so the generated C header is fully documented. - Convert `Duration::as_micros()` (u128) to u64 via checked `try_from` instead of a lossy `as` cast, in both the libmoq and moq-ffi mappings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Very welcome stats for gsteamer moqsink. |
Summary
Adds a point-in-time snapshot of the underlying QUIC/WebTransport connection (RTT, send/receive bandwidth estimates, byte/packet counters) to both FFI layers.
libmoqitself previously exported no stats/version API, so callers had no way to read MoQ-level connection health.The transport already exposed these metrics via
web_transport_trait::Stats;moq-netjust wasn't surfacing them. This plumbs a snapshot through three layers and out through both FFI surfaces.What changed
rs/moq-net: new publicConnectionStatsstruct (#[non_exhaustive], every fieldOptionsince availability is backend/state-dependent) andSession::stats(). Reads the transport's QUIC counters and fillsestimated_recv_ratefrom the existing MoQ PROBE bandwidth consumer.rs/moq-native: a cloneableConnectionStatsReader(Reconnect::stats()). The live session lives inside the reconnect loop, so the reader snapshots the current connection and returnsNonewhile reconnecting.rs/libmoq: new C APImoq_session_stats(session, &dst)filling amoq_connection_statsstruct. Each metric has a*_validflag, because afalseflag is not the same as a zero value. The reconnect loop is now built up front inconnect()so a stats reader can be grabbed before it moves into the spawned task.rs/moq-ffi:MoqSession.stats()returning aMoqConnectionStatsuniffi record withOption<u64>fields (→ native optionals in Python/Swift/Kotlin/Go). The py/swift/kt/go wrappers expose the uniffiMoqSessiondirectly, so it surfaces automatically with no wrapper code.stats()snippets in the Swift/Kotlin quickstarts.Stats exposed
RTT, estimated send rate (congestion-controller bandwidth), estimated recv rate (MoQ PROBE), and bytes/packets sent/received/lost.
Notes for reviewers
moq_net::ConnectionStats+Session::stats();moq_native::ConnectionStatsReader+Reconnect::stats();moq_connection_stats+moq_session_stats()in libmoq (regeneratedmoq.h);MoqConnectionStats+MoqSession::stats()in moq-ffi. Hence targetingmain.js/netbrowser mirror.Test plan
cargo check/buildacross moq-net, moq-native, libmoq, moq-fficargo clippy --all-targetsclean (via nix)cargo testpasses for all four cratescargo fmt --checkcleanmoq.hregenerates withmoq_connection_stats+moq_session_stats(Written by Claude)