Repository navigation
feat(apiv2): report each playback session's viewer egress on the admin sessions list - #5385
Conversation
…n sessions list Silo counts the bytes it serves each playback session across every API server and proxy node, but only the per-minute dashboard total reached an API, so a monitor couldn't split Silo's streaming traffic by local or remote, account, or device. GET /api/v2/admin/sessions?include_egress=true now adds an egress object to each row: the session's cumulative viewer bytes (hops between Silo's own nodes excluded), the publishers' capture time as measured_at, and a series token that changes when the set of servers counting the session changes. A client diffs observations within one series, ignores one that isn't newer than its baseline, and groups by stream_location, user_id and device_id. Egress is omitted, never zero, when the count is unknown: telemetry off, the merged view not built, its last refresh failed, the session's routes capped, no record, or a proxy node served the session while telemetry isn't shared through Redis. A stale or departed publisher changes the series of the sessions it served instead of blanking the list. session.* events never carry egress. The read uses the existing telemetry view cache. The rebuild now runs on its own context with its own timeout, so one reader's deadline or disconnect never fails it for others; the egress read waits at most 2 s, the projection is built once per refresh, and after a failed refresh the egress read serves the last view for one TTL. GET /api/v2/admin/sessions/capabilities gains egress, true when stream telemetry is enabled. Both routes stay readable with admin:monitor:read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 10 minutes. View limit details
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gpt-6.2-sol, reviewed 754c381)
I found two issues in failure handling. I traced the published counters and the Redis read path at this commit, and replayed the polling recipe with synthetic observations.
AI disclosure: Codex harness in T3 Code, gpt-6.2-sol, independent source review and synthetic polling replay.
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (claude-opus-5-5, reviewed 754c381)
Scope: the full diff against the base, checked against AGENTS.md, docs/architecture/api-contract.md, the stream telemetry merge and ingest paths (global.go, node_report.go, nodecontrol/server.go), the parity reader of ViewCache.View, the existing per-minute egress helper in internal/dashmetrics, and how a monitor that paginates /admin/sessions every few seconds would consume the result.
No correctness defect found. Points I checked and found sound: the series hash is computed over publisher contributions sorted by refLess, so it is the same on every replica; measured_at comes from CapturedAt stored in Redis, not from the replica's build time; node reports carry the node boot as epoch, so a node restart changes the series; local-only telemetry stores no node snapshots (NodeSnapshotStore is nil without a Redis store), so omitting proxy-served rows there is right; the new GlobalSessionView fields do not reach the parity endpoint's JSON; and the projection map is shared read-only.
One nit, inline.
…g Redis client The view cache's rebuild bounds its Redis reads with a timeout, and the admin sessions list now waits on that rebuild, but the API passed telemetry the shared client whose socket reads ignore context deadlines and wait out the URL's read timeout, which may be unlimited. A stalled Redis could then hold the rebuild, and the list kept serving the last view. Telemetry now gets its own client that honors deadlines, as the other callers that bound Redis waits already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gemini-4-neon, reviewed 754c381)
Checked the implementation, contract schemas, docs, and callers against the repository source. The core egress projection, series token, detached rebuild cache, local-only proxy omission, and capability gating match the codebase and work as described. One factual inaccuracy in the measured_at field description and docs is flagged inline.
…der view The reader that started a rebuild and hit its own deadline got nothing, while a reader arriving moments later during the same rebuild got the older view marked stale. A monitor polling about once per TTL starts most rebuilds, so a slow Redis left its egress chart with gaps. A reader that gives up now takes the older view, stale, when there is one, and nothing only before the first view exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e time The egress field description and docs said a proxy node's measured_at is when the API server received the node's report. Proxy nodes publish their own snapshots through Redis with their own capture time; only transcode nodes report through the API, and their relay hops don't set measured_at. The text now says it is the counting server's capture time on its own clock, and puts the short-interval jitter down to the roughly once-a-second reports and small clock differences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a8db40c665
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # internal/apiv2/fixtures_test.go
Quick104
left a comment
There was a problem hiding this comment.
Maintainer review of d3dae4b (main merged in). 🤖 Claude Code in T3 Code (claude-opus-5-5)
The approach holds: the counts come from telemetry Silo already collects, nothing new is stored, and the field is opt-in behind a capability. These findings are about whether the client recipe stays correct, and I'm fixing all of them in a commit on this branch, so there's no need to change anything yourself.
Medium. One API server's view can mix a newer count from one publisher with an older count from another, with no Redis write lost. RedisStore.LoadAll (internal/streamtelemetry/store_redis.go, outside this diff) reads every publisher's hash in a plain pipeline. Each publish is a transaction, but another publish can land between those reads. With two API servers behind a load balancer, server 1 can read A=200, B=100 (measured_at from A) while server 2 reads A=100 before A's publish and B=120 after B's (measured_at from B, newer). The recipe accepts server 2's newer observation, sees bytes fall from 300 to 220 and rebaselines. The next poll then counts A's 100 bytes a second time. This is the ordering the Codex thread on global.go raised. The earlier answer there ("can't happen without Redis losing a write") assumed each view is one consistent read of Redis, and it isn't. Repair: read the publisher hashes in one MULTI/EXEC, so every view is a single cut of Redis and per-publisher counts only move forward between views.
Docs fixes in docs/admin-api.md, also in the commit:
- Low. Rolling upgrade behind a load balancer. "Read the capabilities again and drop the parameter" can loop: the capabilities come from an upgraded server, the list from an old one, and every retry repeats the 422. The text now says to leave the parameter off for a few minutes after a 422.
- Low. A proxy with stream telemetry turned off. Its sessions still carry
egress, but that only counts what an API server sent them (playlists, subtitles). Nothing maps a row'srouting_egress_node_idto a telemetry publisher, so the server can't detect this case. Thebytesdescription now says so. - Low. A restart within one series. A session idle past telemetry retention (five minutes by default) is forgotten and recounted from zero under the same publisher and epoch, so the series doesn't change. A client that never sees the lower count undercounts that interval. The recipe now names the limit.
Review fixes for the egress the admin sessions list reports. - LoadAll reads every publisher's snapshot in one transaction. Publishes could land between a plain pipeline's reads, so two API servers could build views that were each newer for one publisher and older for another; a client polling both saw bytes fall at a newer measured_at, rebaselined, and counted one publisher's bytes twice. - A session whose counting publisher captured further ahead of the view's clock than Freshness omits egress. Its measured_at came from that fast clock, and a client that took it as a baseline discarded every later observation until the other servers caught up. - The series description now gives the recipe in the docs' order: ignore an older measured_at first, whatever the series. Checking the series first let a replica with a view from before a series change rebaseline the client backward and count bytes twice. - The view cache clones and projects the view inside build, under its panic recovery, and installs BuildTook with the view. - The docs cover a rolling upgrade behind a load balancer, a proxy with telemetry off, and a restart a slow poller can miss. - The egress fixture case runs last again, after the case main added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Review Completed, but its comments could not be posted
|
| Options | Enabled |
|---|---|
| Bug | ✅ |
| Performance | ✅ |
| Security | ✅ |
| Business Logic | ❌ |
Maintainer review summaryReviewed head: 437c568 (main merged in at d3dae4b, then the review fixes). 🤖 Claude Code in T3 Code (claude-opus-5-5) Fit: 7/10 · Readiness: 9/10 — conditional Fit: the change reuses telemetry Silo already collects, stores nothing new, and stays opt-in behind a capability, so clients that don't ask pay nothing. It holds at 7 because it's new permanent Addressed (437c568)
Left for the maintainers
Checks
Evidence: https://evidence.siloserver.org/r/silo-server/egress-attribution/ |
Problem
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
Monitoring tools can't split Silo's own streaming traffic the way they split Plex's. Plex reports its bandwidth as LAN and WAN with per-account and per-device detail. Silo counts the bytes it serves each playback session across every API server and proxy node, but the only API that exposes them is the per-minute dashboard total, so a tool like Tracearr can chart Silo's total egress but not who or where it went to.
This adds an opt-in
egressobject to each row ofGET /api/v2/admin/sessions?include_egress=true: the session's cumulative viewer bytes, when they were measured, and a series token. A client subtracts two polls per session and groups the result by the row'sstream_location,user_idanddevice_id.Approach
The counts come from the merged stream-telemetry view Silo already builds for its parity diagnostics. It sums every publisher's viewer-egress routes for a session, so a transcode node's hop to a proxy or the API isn't counted twice. Nothing new is stored: no table, migration or job. The read is live, which matches how monitors chart bandwidth (Tracearr's Plex chart is a two-minute window).
bytes: viewer bytes for the session so far, across every API server and proxy node.measured_at: the newest capture time among the servers that counted it. It comes from the publishers, so every API replica reports the same instant for the same counts.series: an opaque token over those servers. It changes when one joins, leaves or restarts, which is whenbytescan jump or fall by a whole server's count.The docs give clients one rule set: ignore an observation whose
measured_atisn't newer than the baseline's, whatever its series, so a poll that lands on a replica with an older cached view can't make a later poll count bytes twice; otherwise start a new baseline when the series changes orbytesfalls, and diff only within one series. For that to hold across replicas, the Redis store now reads every publisher's snapshot in one transaction, so each view is a single cut of Redis and each publisher's count only moves forward from one view to the next.egressis omitted, never zero, when the count is unknown: telemetry off, the view not built, its last refresh failed, the session's routes over the telemetry route cap, a counting server whose clock runs ahead of this one's by more than the telemetry freshness window, no record of the session, or a proxy-served session while telemetry isn't shared through Redis (then the view holds only this server's counts). A stale or departed server drops out of the sessions it served and changes their series rather than blanking every row.session.*events never carryegress.The view cache's rebuild now runs on its own context with its own timeout and reads Redis through a client that honors that deadline, so one reader's deadline or disconnect, or a stalled Redis, can't hold it for everyone else; the egress read waits at most 2 s, takes the older view (stale) if it gives up, and builds its projection once per refresh.
GET /api/v2/admin/sessions/capabilitiesgainsegress, true when stream telemetry is enabled; both routes are already readable withadmin:monitor:read. An older server rejectsinclude_egresswith a 422, so clients send it only when the capability says so.Bytes follow the session's
stream_location, which is decided when playback starts. History (who used the bandwidth last month) and download attribution are out of scope.Validation
egressandinclude_egress=trueis rejected (422). On the branch, with one local direct play and one remote transcode running at once and the list polled withinclude_egress=true: the local row'sbytesmoved in exact steps equal to what the client pulled each cycle; the remote row tracked what the viewer pulled from the proxy, without the transcode node's relay hop;stream_location,user_idanddevice_idwere right on both;measured_atadvanced andseriesstayed constant.go testfor streamtelemetry (also with-race), apiv2, api and middleware; the apiv2 OpenAPI, fixture, contract and web-type checks;make lint-changed; web lint, format check and build.bytesequal to what the client had pulled at each count, a constantseries, andegressomitted before the proxy's first report. The parity endpoint still serves a complete view. The handler case for a counting server whose clock runs ahead fails on d3dae4b and passes now; the single-transaction read was checked against a real Redis 7.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/egress-attribution/
Risks
The view cache's rebuild moved onto its own goroutine with a 10 s timeout; the parity endpoint's
Viewstill retries on every read with no cooldown, but a reader that waited on someone else's failed rebuild now gets that failure instead of starting another rebuild at once. While Redis is unreachable and no view exists yet, eachinclude_egresslist request waits up to 2 s before answering withoutegress. Reading egress costs one merged-view rebuild per TTL per API replica while someone polls withinclude_egress, the same cost the parity endpoint already pays.Checklist
Council review
Rounds: 2, last reviewed a8db40c
No visual review: nothing a user sees changes.
Maintainer review of d3dae4b (main merged in), with one more round from Sol (7/10), Opus (8.5/10) and Gemini (8.5/10): fixed in 437c568 were a cross-publisher read that wasn't one cut of Redis, a counting server whose clock runs ahead, the
seriesdescription giving the recipe in a different order from the docs, and the view cache's build timing and panic recovery. The docs also cover a rolling upgrade behind a load balancer, a proxy with telemetry off, and a restart a slow poller can miss.Fixed: telemetry now reads Redis through a client that honors deadlines, so a stalled Redis can't hold the view rebuild; a request that gives up on a rebuild gets the older view, stale, instead of nothing; the
measured_atdescription now says it's the counting server's own capture time. Answered: a newermeasured_atcan't hide an older count from another server within one series unless Redis loses a write. Two telemetry publishing defects that predate this change are fixed in their own follow-up PRs: the publish loop has no per-publish deadline, and a delta publish after a Redis failover that lost a write can leave a stale count for up to a full-resync interval.AI Disclosure
egressomitted rather than null when unknown. Code review at high (three finders and a validation check) found that the client recipe could double-count behind a load balancer, that one reader's timeout or disconnect could fail the shared rebuild, that one stale node blanked every row, and that local-only telemetry would undercount proxy-served sessions; all fixed, plus cleanups. A simplify pass ran before each commit. Background review: two rounds, see Council review.🤖 Generated with Claude Code