Skip to content

Conversation

@josecelano
Copy link
Member

@josecelano josecelano commented May 28, 2025

Subtasks

  • Rename AggregateSwarmMetadata to AggregateActiveSwarmMetadata. Aggregate values are only for active swarms. For example, it does not count downloads for torrents that are not currently active.
  • Little optimisation. Avoid loading the number of downloads for a torrent from the DB if it's not needed.
  • Fix the downloads counter values returned in the API.
  • Remove peerless torrents when it's enabled in the tracker policy. It was not allowed because it affected the global number of downloads exposed via the API. That problem has been solved in the PR.

After merging this PR, the tracker will save memory because peerless torrents will be removed from memory (when that policy is enabled) even when stats is enabled.

…tiveSwarmMetadata

Aggregate values are only for active swarms.

For example, it does not count downloads for torrents that are not
currently active.
@josecelano josecelano requested a review from da2ce7 May 28, 2025 07:17
@josecelano josecelano self-assigned this May 28, 2025
@josecelano josecelano added the - User - Enjoyable to Use our Software label May 28, 2025
We need to load the number of downloads for the torrent before adding
it to the active swarms becuase the scrape response includes the number
of downloads, and that number should included all downloads ever.
@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 96.99248% with 4 lines in your changes missing coverage. Please review.

Project coverage is 83.46%. Comparing base (4b4f310) to head (92242f8).
Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
packages/tracker-core/src/announce_handler.rs 77.77% 0 Missing and 2 partials ⚠️
packages/tracker-core/src/statistics/repository.rs 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1545      +/-   ##
===========================================
+ Coverage    83.34%   83.46%   +0.11%     
===========================================
  Files          274      275       +1     
  Lines        19547    19601      +54     
  Branches     19547    19601      +54     
===========================================
+ Hits         16292    16360      +68     
+ Misses        2965     2948      -17     
- Partials       290      293       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

It now returns the persisted value when available (stats persistence
enabled).
…acker-core

The tracker-core always has the metric alhoutght it can be persisted or
not. When it's not persisted, it contains the number of downloads during
the session.

On the other hand, the `torrent-repository` metri uses labels, so you
have to sum all values for all labels to get the total.

```
torrent_repository_torrents_downloads_total{peer_role="seeder"} 1
tracker_core_persistent_torrents_downloads_total{} 1
```
… tracker policy

There were not being removed when stats was enabled becuase the tracker
was counting downloads only from the active swarms.

Now the API exposed metric (global downldoads) is not taken from the
in-memory data structrure unless stats persistence is disabled. In that
case, the global total would be per session (since the tracker started),
and reset when the tracker restarts.
@josecelano josecelano marked this pull request as ready for review May 28, 2025 11:38
@josecelano
Copy link
Member Author

ACK 92242f8

@josecelano josecelano merged commit 3bade2c into torrust:develop May 28, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- User - Enjoyable to Use our Software

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul stats: Allow removing peerless torrents without affecting global torrent downloads metric

1 participant