-
Notifications
You must be signed in to change notification settings - Fork 49
Overhaul stats: Emit events from the torrent-repository package and collect metrics
#1513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 26 commits into
torrust:develop
from
josecelano:1358-overhaul-stats-emit-events-from-the-torrent-repository-package-and-collect-metrics
May 16, 2025
Merged
Conversation
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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1513 +/- ##
===========================================
+ Coverage 83.75% 84.35% +0.59%
===========================================
Files 257 265 +8
Lines 18049 18933 +884
Branches 18049 18933 +884
===========================================
+ Hits 15117 15970 +853
- Misses 2654 2682 +28
- Partials 278 281 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
addef82 to
4483e76
Compare
d1c50d5 to
8b6776d
Compare
josecelano
added a commit
that referenced
this pull request
May 13, 2025
243c254 feat: allow incrementing/decrementing gauge metrics (Jose Celano) Pull request description: It allows incrementing/decrementing gauge metrics. This feature was planned to be added, and it's needed in this [PR](#1513). Other [crates](https://docs.rs/metrics/latest/metrics/struct.Gauge.html) also implement it. ACKs for top commit: josecelano: ACK 243c254 Tree-SHA512: 4055825ec04229d65d6ce124ea90c88624ad76ee221b0d6ca5f6edb0b1f4d1e98e81d49b55d7e085cc18f308a2d9f2deb3a2444e2ff30c1b3f00e4cbd83b8a2a
…ry pkg TODO: - Run the event listener for the torrent-repository package when the tracker starts. - Inject enven sender in `Swarms` and `Swarm` type to send events. - Trigger events and process them to update the metrics. - Expose the metrics via the `metrics` API endpoint. - ...
…ker starts This creates independent services that are not used yet in the tracker-core, meaning the `Swarms` object created in the `TorrentRepositoryContainer` will not store any torrent yet. The tracker core is still creating its own fresh instance.
…production code todo: do the same for testing code.
…ST API
These are the new metrics in JSON format:
http://localhost:1212/api/v1/metrics?token=MyAccessToken
```json
{
"metrics": [
{
"kind": "counter",
"name": "torrent_repository_persistent_torrents_downloads_total",
"samples": []
},
{
"kind": "counter",
"name": "torrent_repository_runtime_torrents_downloads_total",
"samples": []
}
]
}
```
It required to use `tokio::sync::Mutex` for the `SwarmHandle` (`Arc<Mutex<Swarm>>`). Otherwise it's not safe to pass the Swarm lock between threads.
… pkg This package dones not have persistence. Persistence is only handle in the `tracker-core` pacakge. The metric will be included there.
Decrease torrent cleanup interval and peer timeout to do manual tests faster.
0cfa4f2 to
d47483f
Compare
There are two concepts: - Unique peers: phisical client with different socket address. - Peer connections: a client (peer) can particiapte in multiple swarms. Current metrics count the second, meaning the peer would be counted doubled if it particiaptes in two swarms.
To fix broken tests. This implementation will kept for now. I think it's only used for testing and I'm planning to remvoe all integration tests becuase now web have unit tests covering the same functionality.
f5c478a to
0e38707
Compare
f04fda5 to
f71211f
Compare
1405ff5 to
31b8715
Compare
31b8715 to
b13797e
Compare
Member
Author
|
ACK d154b2a |
This was referenced May 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
- Admin -
Enjoyable to Install and Setup our Software
- User -
Enjoyable to Use our Software
Enhancement / Feature Request
Something New
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.
Emit events from the
torrent-repository packageand collect metrics. In this PR, I'm only planning to include four metrics. The ones we have in the currentstatsendpoint:{ "torrents": 387044, "seeders": 183887, "completed": 1260584, "leechers": 249136, }However, I will rename them to:
UPDATE: I will not use those long names but "labels". It's only to explain what they represent.
Becuase the current names are too ambiguous. See #1502 (comment).
How to test
Subtasks
torrent-respositorypackage.TorrentRepositoryContainerand run the listener when the tracker starts.Swarmsservice provided by theTorrentRepositoryContainerin theTrackerCoreContainer(otherwise they will be unrelated).Swarmsservice provided by theTorrentRepositoryContainerin theTrackerCoreContainer(otherwise they will be unrelated).metricsAPI endpoint (even if it will have no value yet).SwarmsandSwarmtype to be able to send events from them.Swarmstype.Swarmtype.TorrentAdded-> Increase torrents counter (all instances, all torrents)Torrentremoved-> Decrease torrents counter (all instances, all torrents)PeerAdded-> Increase peers counter (total, seeders, leechers)PeerRemoved-> Decrease peers counter (total, seeders, leechers)PeerUdpated-> Decrease peers counter (total, seeders, leechers)PeerDownloadCompleted-> Increase torrent downloads counter (all instances, all torrents)