Commit cb9196e
committed
Merge torrust#1513: Overhaul stats: Emit events from the
d154b2a refactor: [torrust#1358] clean Swarm type (Jose Celano)
b3b0b71 refactor: [torrust#1358] Swarm, cleaning upsert_peer method (Jose Celano)
47d1eab refactor: [torrust#1358] Swarm tests to use new mock helpers (Jose Celano)
b13797e test: [torrust#1358] add tests for events in torrent-repository pkg (Jose Celano)
f71211f test: [torrust#1358] add tests to torrust_tracker_torrent_repository::swarms::Swarms (Jose Celano)
3d7e6ff test: [torrust#1358] add tests to torrust_tracker_torrent_repository::swarm::Swarm (Jose Celano)
0e38707 fix: [torrust#1358] revert Hash impl for Swarm (Jose Celano)
c9a893c refactor: [torrust#1358] rename metrics for clarity (Jose Celano)
8ee258e refactor: [torrust#1358] use the new field info-hash as ID for the Swarm (Hash,PartialEq) (Jose Celano)
dfba00c feat: [torrust#1358] allow disabling the event sender in the torrent-repository pkg (Jose Celano)
60c00e8 feat: [torrust#1358] add info-hash to all torrent-repository events (Jose Celano)
c706a1b refactor: [torrust#1358] move logs (Jose Celano)
daba8a0 feat: [torrust#1358] new metric in torrent-repository: total number of downloads (Jose Celano)
01a9970 feat: [torrust#1358] new metric in torrent-repository: total number of peers (Jose Celano)
269d273 refactor: [torrust#1358] rename metric (Jose Celano)
ba2033b fix: [torrust#1358] trigger PeerRemoved event when peer is removed due to inactivity (Jose Celano)
d47483f feat: [torrust#1358] new metric in torrent-repository: total number of torrents (Jose Celano)
29a2dfd dev: change default config (Jose Celano)
1eb545c feat: [torrust#1358] remove persistent metric from torrent-repository pkg (Jose Celano)
6d95d1a refactor: [torrust#1358] inject event sender in Swarm type (Jose Celano)
2c479a1 refactor: [torrust#1358] inject event sender in Swarms type (Jose Celano)
68b930d feat: [torrust#1495] expose new torrent-repositoru metrics via the REST API (Jose Celano)
41f4022 feat: [torrust#1358] inject Swarms into InMemoryTorrentRepository in testing code (Jose Celano)
95766bb feat: [torrust#1358] inject Swarms into InMemoryTorrentRepository in production code (Jose Celano)
f986bda feat: [torrust#1358] add the and run the event listener when the tracker starts (Jose Celano)
2522ad4 feat: [torrust#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 torrust#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] torrust#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: d4946847dae38b51bc6027b4de25d7e2ad5b1042294913008f503c590c81e586ed083ab980613d647a0f867601f7bd482f4c004628c01cdfffc9d8b810bb670etorrent-repository package and collect metricsFile tree
68 files changed
+2576
-709
lines changed- packages
- axum-http-tracker-server
- src
- v1/handlers
- tests/server/v1
- axum-rest-tracker-api-server
- src
- v1/context
- stats
- torrent
- tests/server/v1/contract/context
- events/src
- http-tracker-core
- benches/helpers
- src
- services
- statistics
- event
- metrics/src
- primitives/src
- rest-tracker-api-core
- src
- statistics
- torrent-repository
- src
- statistics
- event
- tests
- swarms
- swarm
- tracker-core/src
- torrent
- repository
- udp-tracker-core
- benches/helpers
- src
- services
- statistics
- udp-tracker-server
- src
- handlers
- statistics
- src
- bootstrap/jobs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
68 files changed
+2576
-709
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
263 | 264 | | |
264 | 265 | | |
265 | 266 | | |
| |||
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
282 | | - | |
| 283 | + | |
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
292 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
293 | 301 | | |
294 | 302 | | |
295 | 303 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
Lines changed: 27 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
| 477 | + | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
| 530 | + | |
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
| |||
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
628 | | - | |
| 628 | + | |
629 | 629 | | |
630 | 630 | | |
631 | 631 | | |
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
| 669 | + | |
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
| |||
787 | 787 | | |
788 | 788 | | |
789 | 789 | | |
790 | | - | |
| 790 | + | |
| 791 | + | |
791 | 792 | | |
792 | 793 | | |
793 | 794 | | |
| |||
829 | 830 | | |
830 | 831 | | |
831 | 832 | | |
832 | | - | |
| 833 | + | |
| 834 | + | |
833 | 835 | | |
834 | 836 | | |
835 | 837 | | |
| |||
878 | 880 | | |
879 | 881 | | |
880 | 882 | | |
881 | | - | |
| 883 | + | |
| 884 | + | |
882 | 885 | | |
883 | 886 | | |
884 | 887 | | |
| |||
925 | 928 | | |
926 | 929 | | |
927 | 930 | | |
928 | | - | |
| 931 | + | |
| 932 | + | |
929 | 933 | | |
930 | 934 | | |
931 | 935 | | |
| |||
1010 | 1014 | | |
1011 | 1015 | | |
1012 | 1016 | | |
1013 | | - | |
| 1017 | + | |
| 1018 | + | |
1014 | 1019 | | |
1015 | 1020 | | |
1016 | 1021 | | |
| |||
1050 | 1055 | | |
1051 | 1056 | | |
1052 | 1057 | | |
1053 | | - | |
| 1058 | + | |
| 1059 | + | |
1054 | 1060 | | |
1055 | 1061 | | |
1056 | 1062 | | |
| |||
1282 | 1288 | | |
1283 | 1289 | | |
1284 | 1290 | | |
1285 | | - | |
| 1291 | + | |
| 1292 | + | |
1286 | 1293 | | |
1287 | 1294 | | |
1288 | 1295 | | |
| |||
1318 | 1325 | | |
1319 | 1326 | | |
1320 | 1327 | | |
1321 | | - | |
| 1328 | + | |
| 1329 | + | |
1322 | 1330 | | |
1323 | 1331 | | |
1324 | 1332 | | |
| |||
1494 | 1502 | | |
1495 | 1503 | | |
1496 | 1504 | | |
1497 | | - | |
| 1505 | + | |
| 1506 | + | |
1498 | 1507 | | |
1499 | 1508 | | |
1500 | 1509 | | |
| |||
1525 | 1534 | | |
1526 | 1535 | | |
1527 | 1536 | | |
1528 | | - | |
| 1537 | + | |
| 1538 | + | |
1529 | 1539 | | |
1530 | 1540 | | |
1531 | 1541 | | |
| |||
1576 | 1586 | | |
1577 | 1587 | | |
1578 | 1588 | | |
1579 | | - | |
| 1589 | + | |
| 1590 | + | |
1580 | 1591 | | |
1581 | 1592 | | |
1582 | 1593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
175 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
176 | 185 | | |
177 | 186 | | |
| 187 | + | |
178 | 188 | | |
179 | 189 | | |
| 190 | + | |
180 | 191 | | |
181 | 192 | | |
182 | 193 | | |
| 194 | + | |
183 | 195 | | |
184 | 196 | | |
185 | 197 | | |
| |||
0 commit comments