Skip to content

[2/6] Per-ecosystem cache and download statistics - #389

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

andrew merged 2 commits into
git-pkgs:mainfrom
wickedOne:analytics-2-ecosystem-stats

Conversation

@wickedOne

@wickedOne wickedOne commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Per-ecosystem cache and download statistics

Part 2 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

Independent of the other five. #390, #391, #392 and #393 all build on it.

/metrics reported cache size and artifact count as single numbers with no breakdown, and the database had the figures to break them down all along: artifacts.hit_count x artifacts.size, summed per ecosystem, is the bytes the proxy has actually handed to clients from cache.

GetEcosystemStats() returns per-ecosystem packages, versions, artifacts, cache size, downloads and downloaded bytes. It is several grouped aggregations merged in Go rather than one join, so ecosystems with nothing cached still appear and the artifacts table stays optional for a database inherited from git-pkgs. Six gauges are published from it on the existing one-minute cache-stats tick, so the added background cost is a multiple of work that already happened rather than something new.

Two details worth a look:

Artifacts whose version or package row has gone missing are reported under unattributed rather than dropped, so the per-ecosystem figures still add up to proxy_cache_size_bytes and proxy_cached_artifacts_total. A non-zero unattributed is a signal about the database, not noise.

The gauges are Set and selectively deleted rather than Reset and repopulated. Reset followed by a repopulating loop leaves a window in which a scrape sees the families empty or half filled, which renders as a gap on any panel built from them. Rows are summed per label first, because normalizing collapses aliases and a database holding both gem and rubygems rows arrives as two rows belonging to one label.

These are gauges rather than counters because eviction clears an artifact's size and drops its past hits out of the total, so the figure can step downwards. The README says so, and says to chart them with max_over_time rather than increase.

New metrics

proxy_ecosystem_downloaded_bytes, proxy_ecosystem_artifact_downloads, proxy_ecosystem_cache_size_bytes, proxy_ecosystem_cached_artifacts, proxy_ecosystem_packages, proxy_ecosystem_versions, all labelled ecosystem.

Two of these were proxy_downloaded_bytes and proxy_artifact_downloads in #381. Renamed to share the prefix with the other four, per the review there -- nothing is published yet, so it costs nothing now and would be a break later.

- 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>
@wickedOne
wickedOne force-pushed the analytics-2-ecosystem-stats branch from 94f3934 to 4ebd805 Compare October 1, 2026 14:19
@andrew
andrew merged commit f40f839 into git-pkgs:main Oct 2, 2026
6 checks passed
@wickedOne
wickedOne deleted the analytics-2-ecosystem-stats 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