Repository navigation
Overhaul stats: Scaffolding for metrics in the tracker-core package - #1536
josecelano merged 1 commit into
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1536 +/- ##
===========================================
- Coverage 83.89% 83.52% -0.37%
===========================================
Files 270 273 +3
Lines 19181 19317 +136
Branches 19181 19317 +136
===========================================
+ Hits 16091 16134 +43
- Misses 2817 2909 +92
- Partials 273 274 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tracker-core (total downloads for all torrents)tracker-core package
New metric added:
```
tracker_core_persistent_torrents_downloads_total{} 1
```
However, it's not persisted yet.
TODO:
- Persist into the database when updated.
- Load from database when the tracker starts.
14a1ffa to
2175270
Compare
|
ACK 2175270 |
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of #1536 as it stands at e170b9620 on the default branch.
What still runs from 21752709a: the tracker-core statistics repository and its metrics wrapper (packages/tracker-core/src/statistics/repository.rs, packages/tracker-core/src/statistics/metrics.rs), the container field that holds the repository (packages/tracker-core/src/container.rs:53, built at :105), and the increment of tracker_core_persistent_torrents_downloads_total on every PeerDownloadCompleted event (packages/tracker-core/src/statistics/event/handler.rs:72). Later changes split the listener into an in-memory listener and a persistence listener (6248ff876) and deprecated that counter in favour of explicit in-session and persisted counters (194676344). As merged, the bootstrap started the listener when only tracker_usage_statistics was on, while the handler wrote each completion to the database unconditionally, so the default configuration persisted downloads with persistent_torrent_completed_stat = false. 4febda494 made those writes conditional on that flag, and each of the two listeners now starts on its own flag (src/bootstrap/jobs/tracker_core.rs:24, :45), so that is history. The description mentions only the new counter. The development configuration timeouts the change also edited went unexplained, and they still hold the values it set.
[Minor] share/default/config/tracker.development.sqlite3.toml:36 sets max_peer_timeout = 60 and :13 runs the cleanup every 120 s. The file has no [core.announce_policy], so the default announce interval and minimum interval of 120 s apply (packages/primitives/src/announce.rs:74-79). This file is the binary's fallback configuration (src/bootstrap/config.rs:24) and the README's starting point for a custom one. A peer that announces on schedule passes the 60 s cutoff (packages/tracker-core/src/torrent/manager.rs:104) halfway through each interval. Exactly one cleanup pass falls in every 120 s window, so about half of the compliant peers are removed before each regular announce and re-added by it. With remove_peerless_torrents = true (:38), a one-peer swarm goes with them. The removals also lose completions, which this file's persistent_torrent_completed_stat = true (:37) is there to exercise. Example: a leecher announces at t=0, a cleanup pass at t=70 removes it, and it finishes and announces event=completed at t=90. The swarm then treats it as a new peer (packages/swarm-coordination-registry/src/swarm/coordinator.rs:162-177), so no PeerDownloadCompleted is sent and neither the in-session nor the persisted totals move. The change doubled both values from 30 and 60 without saying why. The timeout-below-interval relation that drops compliant peers predates it and survives it. Smallest fix: set max_peer_timeout above the announce interval in this file, for example 240. If a short timeout is wanted for manual tests, instead add [core.announce_policy] with interval and interval_min below 60, and a comment saying so.
[Nit] packages/tracker-core/src/statistics/metrics.rs:7 documents the type as metrics collected by the torrent repository, and packages/tracker-core/src/statistics/repository.rs:16 calls it a repository for the torrent repository metrics. Both lines were carried over from the swarm package and name the wrong package. That now shows in the public documentation of the tracker-core type. Smallest fix: say tracker-core metrics in both lines.
Checked and found sound:
- The write paths release the lock before logging and return the error they log (
packages/tracker-core/src/statistics/repository.rs:90-108). The handler discards a result only after it has been logged. - The persisted totals are seeded before any listener subscribes (
src/app.rs:268-270). - Persistent statistics without usage statistics are refused at startup (
src/bootstrap/persistence.rs:41, called fromsrc/bootstrap/app.rs:62), so the deprecated counter cannot sit frozen at its seeded value. - The persisted counter advances only after the global database increment succeeds (
packages/tracker-core/src/statistics/event/handler.rs:113-131). - The
expectcalls on the metrics merge (packages/rest-api-runtime-adapter/src/v1/adapters/stats.rs:139-158) and on the initial zero values (packages/tracker-core/src/statistics/mod.rs:65-75) cannot fire with the current package-prefixed names. - The change added no credential, endpoint or new exposure.
Relates to: #1502
It adds a new metric.
The new metric in Prometheus format:
In new PRs, the new metric will be persisted.