You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #1513: Overhaul stats: Emit events from the torrent-repository package and collect metrics
d154b2a refactor: [#1358] clean Swarm type (Jose Celano)
b3b0b71 refactor: [#1358] Swarm, cleaning upsert_peer method (Jose Celano)
47d1eab refactor: [#1358] Swarm tests to use new mock helpers (Jose Celano)
b13797e test: [#1358] add tests for events in torrent-repository pkg (Jose Celano)
f71211f test: [#1358] add tests to torrust_tracker_torrent_repository::swarms::Swarms (Jose Celano)
3d7e6ff test: [#1358] add tests to torrust_tracker_torrent_repository::swarm::Swarm (Jose Celano)
0e38707 fix: [#1358] revert Hash impl for Swarm (Jose Celano)
c9a893c refactor: [#1358] rename metrics for clarity (Jose Celano)
8ee258e refactor: [#1358] use the new field info-hash as ID for the Swarm (Hash,PartialEq) (Jose Celano)
dfba00c feat: [#1358] allow disabling the event sender in the torrent-repository pkg (Jose Celano)
60c00e8 feat: [#1358] add info-hash to all torrent-repository events (Jose Celano)
c706a1b refactor: [#1358] move logs (Jose Celano)
daba8a0 feat: [#1358] new metric in torrent-repository: total number of downloads (Jose Celano)
01a9970 feat: [#1358] new metric in torrent-repository: total number of peers (Jose Celano)
269d273 refactor: [#1358] rename metric (Jose Celano)
ba2033b fix: [#1358] trigger PeerRemoved event when peer is removed due to inactivity (Jose Celano)
d47483f feat: [#1358] new metric in torrent-repository: total number of torrents (Jose Celano)
29a2dfd dev: change default config (Jose Celano)
1eb545c feat: [#1358] remove persistent metric from torrent-repository pkg (Jose Celano)
6d95d1a refactor: [#1358] inject event sender in Swarm type (Jose Celano)
2c479a1 refactor: [#1358] inject event sender in Swarms type (Jose Celano)
68b930d feat: [#1495] expose new torrent-repositoru metrics via the REST API (Jose Celano)
41f4022 feat: [#1358] inject Swarms into InMemoryTorrentRepository in testing code (Jose Celano)
95766bb feat: [#1358] inject Swarms into InMemoryTorrentRepository in production code (Jose Celano)
f986bda feat: [#1358] add the and run the event listener when the tracker starts (Jose Celano)
2522ad4 feat: [#1358] basic scaffolding for events in torrent-repository pkg (Jose Celano)
Pull request description:
Emit events from the `torrent-repository package` and collect metrics. In this PR, I'm only planning to include four metrics. The ones we have in the current `stats` endpoint:
```json
{
"torrents": 387044,
"seeders": 183887,
"completed": 1260584,
"leechers": 249136,
}
```
However, I will rename them to:
```
{
"torrent_repository_per_session_all_instances_all_torrents_total": 387044,
"torrent_repository_per_session_all_instances_all_seeders_total": 183887,
"torrent_repository_per_session_all_instances_all_torrents_downloads_total": 1260584,
"torrent_repository_per_session_all_instances_all_leechers_total": 249136,
}
```
**UPDATE:** I will not use those long names but "labels". It's only to explain what they represent.
- per session: since the main tracker process started.
- all instances: all tracker servers (UDP or HTTP) running on different ports.
- all torrents: all swarms.
Becuase the current names are too ambiguous. See #1502 (comment).
### How to test
1. Run the tracker.
2. Use the tracker client to make an announce request.
```
cargo run -p torrust-tracker-client --bin udp_tracker_client announce udp://127.0.0.1:6969 443c7602b4fde83d1154d6d9da48808418b181b6 | jq
```
3. Use the REST API to get the metric value.
```
curl -s "http://localhost:1212/api/v1/metrics?token=MyAccessToken&format=prometheus" | grep torrent_repository_peers_total
```
### Subtasks
- [x] Add basic event scaffolding in the `torrent-respository` package.
- [x] Run the event listener for the torrent-repository package when the tracker starts.
- [x] Add the `TorrentRepositoryContainer` and run the listener when the tracker starts.
- [x] In production code: use the `Swarms` service provided by the `TorrentRepositoryContainer` in the `TrackerCoreContainer` (otherwise they will be unrelated).
- [x] In testing code: use the `Swarms` service provided by the `TorrentRepositoryContainer` in the `TrackerCoreContainer` (otherwise they will be unrelated).
- [x] Expose the new metrics via the `metrics` API endpoint (even if it will have no value yet).
- [x] Inject the event sender in `Swarms` and `Swarm` type to be able to send events from them.
- [x] In `Swarms` type.
- [x] In `Swarm` type.
- [x] #1516
- [x] Star triggering events and process them to update the metrics in the metrics collection. One event and the corresponding affected metrics at the time.
- [x] `TorrentAdded` -> Increase torrents counter (all instances, all torrents)
- [x] `Torrentremoved` -> Decrease torrents counter (all instances, all torrents)
- [x] `PeerAdded` -> Increase peers counter (total, seeders, leechers)
- [x] `PeerRemoved` -> Decrease peers counter (total, seeders, leechers)
- [x] `PeerUdpated` -> Decrease peers counter (total, seeders, leechers)
- [x] `PeerDownloadCompleted` -> Increase torrent downloads counter (all instances, all torrents)
- [x] Add tests to check that events have been sent.
- [x] Add tests to check that metrics are updated after receiving the event.
ACKs for top commit:
josecelano:
ACK d154b2a
Tree-SHA512: d4946847dae38b51bc6027b4de25d7e2ad5b1042294913008f503c590c81e586ed083ab980613d647a0f867601f7bd482f4c004628c01cdfffc9d8b810bb670e
0 commit comments