Allow incrementing/decrementing gauge metrics.#1516
Merged
josecelano merged 1 commit intotorrust:developfrom May 13, 2025
Merged
Allow incrementing/decrementing gauge metrics.#1516josecelano merged 1 commit intotorrust:developfrom
josecelano merged 1 commit intotorrust:developfrom
Conversation
24ea27b to
243c254
Compare
Member
Author
|
ACK 24ea27b |
19 tasks
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1516 +/- ##
===========================================
- Coverage 83.86% 83.76% -0.11%
===========================================
Files 257 257
Lines 17945 18049 +104
Branches 17945 18049 +104
===========================================
+ Hits 15049 15118 +69
- Misses 2620 2654 +34
- Partials 276 277 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
ACK 243c254 |
josecelano
added a commit
that referenced
this pull request
May 16, 2025
…` 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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
It allows incrementing/decrementing gauge metrics.
This feature was planned to be added, and it's needed in this PR.
Other crates also implement it.