Skip to content

[4/6] Report the per-ecosystem breakdown from GET /stats - #391

Merged
andrew merged 3 commits into
git-pkgs:mainfrom
wickedOne:analytics-4-stats-breakdown
Oct 2, 2026
Merged

andrew merged 3 commits into
git-pkgs:mainfrom
wickedOne:analytics-4-stats-breakdown

Conversation

@wickedOne

@wickedOne wickedOne commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

GET /stats reports the per-ecosystem breakdown

Part 4 of six splitting #381 ("analytics dashboard") into reviewable pieces, as the review there asked for. #381 stays open as the umbrella and reference thread until the last of these lands; it is not meant to be merged.

Series: #388 route coverage · #389 ecosystem stats · #390 analytics page · #391 /stats breakdown · #392 Grafana dashboard · #393 source attribution

Needs #389 and #390, and branches off #390, so until those merge the Files changed tab here shows all three. The last commit is this part.

/stats answered from two cheap counters. It now also carries downloaded_bytes, downloads and an ecosystems array, served from the same 60-second snapshot the gauges and the analytics page read, so a polling client does not re-run the aggregation per request.

stats_unavailable

Raised in the review of #381: when the aggregation fails with no retained snapshot, zeros and an empty array are indistinguishable from an idle proxy for anything consuming the JSON. The response now carries stats_unavailable: true in that case.

It is a new field with omitempty rather than pointer totals, so the field set stays stable for existing consumers and a healthy response is byte-identical to one without the flag. A retained snapshot is served on without the flag -- those figures are stale, not absent, and staleness is surfaced to a human on the page rather than to a machine here.

The comment above the call in #381 claimed the breakdown is omitted when there is no snapshot. That held for the array but not for the totals; it now says what the code does.

The endpoint keeps answering with the artifact count and cache size either way: a failing breakdown does not take down an endpoint that worked before it existed.

Tests cover all three states. There were none for the /stats shape before.

@wickedOne wickedOne changed the title Analytics 4 stats breakdown Report the per-ecosystem breakdown from GET /stats Oct 1, 2026
@wickedOne wickedOne changed the title Report the per-ecosystem breakdown from GET /stats [4/6] Report the per-ecosystem breakdown from GET /stats Oct 1, 2026
wickedOne and others added 3 commits October 1, 2026 16:15
- Add GetEcosystemStats, aggregating packages, versions, artifacts,
  cache size, downloads and downloaded bytes per ecosystem
- Publish six proxy_ecosystem_* gauges from it on the existing
  one-minute cache-stats tick
- Set and selectively delete rather than Reset, so no scrape lands on
  a half-populated vector
- Report artifacts with no package row under "unattributed" rather
  than dropping them, so the figures still add up

Part 2 of 6 splitting git-pkgs#381 up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Ring of download size by ecosystem, cache figures, per-ecosystem
  table, vulnerability overview and a Runtime card
- Add metrics.Gather so the page can render counters that were never
  in the database
- Add proxy_response_bytes_total and response-writer byte counting
- Serve a retained snapshot behind a staleness banner when the
  aggregation fails, rather than rendering old figures as current
- Extract the security overview into a shared component

Part 3 of 6 splitting git-pkgs#381 up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Add downloaded_bytes, downloads and an ecosystems array, served from
  the snapshot the gauges and the page already share
- Add stats_unavailable so a failed aggregation is distinguishable
  from an idle proxy
- Regenerate the OpenAPI spec

Part 4 of 6 splitting git-pkgs#381 up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@wickedOne
wickedOne force-pushed the analytics-4-stats-breakdown branch from f169c81 to 4b8c5a8 Compare October 1, 2026 14:19
@andrew
andrew merged commit 7c129f9 into git-pkgs:main Oct 2, 2026
6 checks passed
@wickedOne
wickedOne deleted the analytics-4-stats-breakdown branch October 2, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants