Group stats by source kind and add rolling event counts per station - #17
Merged
Conversation
Every API publisher, UDP sender and HTTP feeder rolls up into one source kind (v1, udp, http, mmsi) in /v1/stats; upstreams keep their name. Event rings, vessel counts and last-event age are per kind. Each /v1/stations row reports events over the last 24 hours and 7 days from the same hourly ring, which replaces the 24-hour ring behind the earned feeder tier. Station rings persist in the usage file and re-attach when the station reports again after a restart.
There was a problem hiding this comment.
Pull request overview
This PR updates AISCast’s usage and station statistics so /v1/stats and /v1/stations present more actionable aggregates: sources are rolled up by “source kind” (e.g., v1, udp, http, mmsi, plus upstream names), and stations now expose rolling event-window counts derived from the same 7‑day hourly ring used for stats and persisted across restarts.
Changes:
- Roll up
/v1/stats.sourcesby source kind, unioning vessel sets and summing event windows per kind. - Replace per-station 24h buckets with the shared 7‑day hourly ring and expose
events: {last_24h, last_7d}on/v1/stations(persisted in the usage file and restored on restart). - Update viewer and API docs/tests to match the new
eventsshape.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| viewer/index.html | Updates station panel to display events.last_24h. |
| server/stats.go | Persists/restores station rings; groups stats sources by kind; adjusts stats payload shapes. |
| server/stats_test.go | Updates per-kind expectations and adds restart/restore test for station rings. |
| server/stations.go | Introduces 7‑day hourRing for station events, adds ring persistence/restore, and groups vessel counts by source kind. |
| server/pipeline.go | Records usage events per source kind (via sourceKind). |
| server/hub_test.go | Updates station stats assertions to new events map shape. |
| docs/API.md | Updates examples and endpoint documentation for the new events and per-kind sources shapes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
/v1/statslisted every API client, UDP sender and HTTP feeder as its own source, so our own feeds showed up as a dozenv1:ed25519:…andudp:…entries next to each upstream. They now roll up into one entry per kind:v1,udp,http,mmsi, with the upstreams keeping their names. Event windows are summed per kind,vesselsandvessels_exclusiveare unioned per kind, andlast_age_sis the youngest member.Each row in
/v1/stationsnow carrieseventsas{"last_24h", "last_7d"}from the same 7-day hourly ring that backs/v1/stats. That ring replaces the 24-hour one the earned feeder tier used, so the tier reads the same numbers. Station rings are saved in the usage file and re-attached when a station reports again after a restart, so a deploy neither zeroes a feeder's counts nor lists stations that haven't reported since.duplicatesandpositionsremain since first heard.The viewer's station panel shows the 24-hour count;
docs/API.mddescribes both shapes. Tests cover the per-kind grouping, a source that only ever duplicates, and the station-ring restore.