@@ -8,24 +8,30 @@ use torrust_tracker_primitives::DurationSinceUnixEpoch;
88use crate :: event:: Event ;
99use crate :: statistics:: repository:: Repository ;
1010use crate :: statistics:: {
11- TORRENT_REPOSITORY_PEERS_ADDED_TOTAL , TORRENT_REPOSITORY_PEERS_REMOVED_TOTAL , TORRENT_REPOSITORY_PEERS_UPDATED_TOTAL ,
12- TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL , TORRENT_REPOSITORY_TORRENTS_ADDED_TOTAL ,
13- TORRENT_REPOSITORY_TORRENTS_DOWNLOADS_TOTAL , TORRENT_REPOSITORY_TORRENTS_REMOVED_TOTAL , TORRENT_REPOSITORY_TORRENTS_TOTAL ,
11+ SWARM_COORDINATION_REGISTRY_PEERS_ADDED_TOTAL , SWARM_COORDINATION_REGISTRY_PEERS_REMOVED_TOTAL ,
12+ SWARM_COORDINATION_REGISTRY_PEERS_UPDATED_TOTAL , SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ,
13+ SWARM_COORDINATION_REGISTRY_TORRENTS_ADDED_TOTAL , SWARM_COORDINATION_REGISTRY_TORRENTS_DOWNLOADS_TOTAL ,
14+ SWARM_COORDINATION_REGISTRY_TORRENTS_REMOVED_TOTAL , SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ,
1415} ;
1516
17+ #[ allow( clippy:: too_many_lines) ]
1618pub async fn handle_event ( event : Event , stats_repository : & Arc < Repository > , now : DurationSinceUnixEpoch ) {
1719 match event {
1820 // Torrent events
1921 Event :: TorrentAdded { info_hash, .. } => {
2022 tracing:: debug!( info_hash = ?info_hash, "Torrent added" , ) ;
2123
2224 let _unused = stats_repository
23- . increment_gauge ( & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_TOTAL ) , & LabelSet :: default ( ) , now)
25+ . increment_gauge (
26+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ) ,
27+ & LabelSet :: default ( ) ,
28+ now,
29+ )
2430 . await ;
2531
2632 let _unused = stats_repository
2733 . increment_counter (
28- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_ADDED_TOTAL ) ,
34+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_ADDED_TOTAL ) ,
2935 & LabelSet :: default ( ) ,
3036 now,
3137 )
@@ -35,12 +41,16 @@ pub async fn handle_event(event: Event, stats_repository: &Arc<Repository>, now:
3541 tracing:: debug!( info_hash = ?info_hash, "Torrent removed" , ) ;
3642
3743 let _unused = stats_repository
38- . decrement_gauge ( & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_TOTAL ) , & LabelSet :: default ( ) , now)
44+ . decrement_gauge (
45+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ) ,
46+ & LabelSet :: default ( ) ,
47+ now,
48+ )
3949 . await ;
4050
4151 let _unused = stats_repository
4252 . increment_counter (
43- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_REMOVED_TOTAL ) ,
53+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_REMOVED_TOTAL ) ,
4454 & LabelSet :: default ( ) ,
4555 now,
4656 )
@@ -54,11 +64,15 @@ pub async fn handle_event(event: Event, stats_repository: &Arc<Repository>, now:
5464 let label_set = label_set_for_peer ( & peer) ;
5565
5666 let _unused = stats_repository
57- . increment_gauge ( & metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) , & label_set, now)
67+ . increment_gauge (
68+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ,
69+ & label_set,
70+ now,
71+ )
5872 . await ;
5973
6074 let _unused = stats_repository
61- . increment_counter ( & metric_name ! ( TORRENT_REPOSITORY_PEERS_ADDED_TOTAL ) , & label_set, now)
75+ . increment_counter ( & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_ADDED_TOTAL ) , & label_set, now)
6276 . await ;
6377 }
6478 Event :: PeerRemoved { info_hash, peer } => {
@@ -67,11 +81,19 @@ pub async fn handle_event(event: Event, stats_repository: &Arc<Repository>, now:
6781 let label_set = label_set_for_peer ( & peer) ;
6882
6983 let _unused = stats_repository
70- . decrement_gauge ( & metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) , & label_set, now)
84+ . decrement_gauge (
85+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ,
86+ & label_set,
87+ now,
88+ )
7189 . await ;
7290
7391 let _unused = stats_repository
74- . increment_counter ( & metric_name ! ( TORRENT_REPOSITORY_PEERS_REMOVED_TOTAL ) , & label_set, now)
92+ . increment_counter (
93+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_REMOVED_TOTAL ) ,
94+ & label_set,
95+ now,
96+ )
7597 . await ;
7698 }
7799 Event :: PeerUpdated {
@@ -84,15 +106,15 @@ pub async fn handle_event(event: Event, stats_repository: &Arc<Repository>, now:
84106 if old_peer. role ( ) != new_peer. role ( ) {
85107 let _unused = stats_repository
86108 . increment_gauge (
87- & metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) ,
109+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ,
88110 & label_set_for_peer ( & new_peer) ,
89111 now,
90112 )
91113 . await ;
92114
93115 let _unused = stats_repository
94116 . decrement_gauge (
95- & metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) ,
117+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ,
96118 & label_set_for_peer ( & old_peer) ,
97119 now,
98120 )
@@ -102,15 +124,19 @@ pub async fn handle_event(event: Event, stats_repository: &Arc<Repository>, now:
102124 let label_set = label_set_for_peer ( & new_peer) ;
103125
104126 let _unused = stats_repository
105- . increment_counter ( & metric_name ! ( TORRENT_REPOSITORY_PEERS_UPDATED_TOTAL ) , & label_set, now)
127+ . increment_counter (
128+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_UPDATED_TOTAL ) ,
129+ & label_set,
130+ now,
131+ )
106132 . await ;
107133 }
108134 Event :: PeerDownloadCompleted { info_hash, peer } => {
109135 tracing:: debug!( info_hash = ?info_hash, peer = ?peer, "Peer download completed" , ) ;
110136
111137 let _unused = stats_repository
112138 . increment_counter (
113- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_DOWNLOADS_TOTAL ) ,
139+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_DOWNLOADS_TOTAL ) ,
114140 & label_set_for_peer ( & peer) ,
115141 now,
116142 )
@@ -217,7 +243,8 @@ mod tests {
217243 use crate :: statistics:: event:: handler:: tests:: { expect_counter_metric_to_be, expect_gauge_metric_to_be} ;
218244 use crate :: statistics:: repository:: Repository ;
219245 use crate :: statistics:: {
220- TORRENT_REPOSITORY_TORRENTS_ADDED_TOTAL , TORRENT_REPOSITORY_TORRENTS_REMOVED_TOTAL , TORRENT_REPOSITORY_TORRENTS_TOTAL ,
246+ SWARM_COORDINATION_REGISTRY_TORRENTS_ADDED_TOTAL , SWARM_COORDINATION_REGISTRY_TORRENTS_REMOVED_TOTAL ,
247+ SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ,
221248 } ;
222249 use crate :: tests:: { sample_info_hash, sample_peer} ;
223250 use crate :: CurrentClock ;
@@ -240,7 +267,7 @@ mod tests {
240267
241268 expect_gauge_metric_to_be (
242269 & stats_repository,
243- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_TOTAL ) ,
270+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ) ,
244271 & LabelSet :: default ( ) ,
245272 1.0 ,
246273 )
@@ -252,7 +279,7 @@ mod tests {
252279 clock:: Stopped :: local_set_to_unix_epoch ( ) ;
253280
254281 let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
255- let metric_name = metric_name ! ( TORRENT_REPOSITORY_TORRENTS_TOTAL ) ;
282+ let metric_name = metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_TOTAL ) ;
256283 let label_set = LabelSet :: default ( ) ;
257284
258285 // Increment the gauge first to simulate a torrent being added.
@@ -291,7 +318,7 @@ mod tests {
291318
292319 expect_counter_metric_to_be (
293320 & stats_repository,
294- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_ADDED_TOTAL ) ,
321+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_ADDED_TOTAL ) ,
295322 & LabelSet :: default ( ) ,
296323 1 ,
297324 )
@@ -315,7 +342,7 @@ mod tests {
315342
316343 expect_counter_metric_to_be (
317344 & stats_repository,
318- & metric_name ! ( TORRENT_REPOSITORY_TORRENTS_REMOVED_TOTAL ) ,
345+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_REMOVED_TOTAL ) ,
319346 & LabelSet :: default ( ) ,
320347 1 ,
321348 )
@@ -335,7 +362,8 @@ mod tests {
335362 use crate :: statistics:: event:: handler:: { handle_event, label_set_for_peer} ;
336363 use crate :: statistics:: repository:: Repository ;
337364 use crate :: statistics:: {
338- TORRENT_REPOSITORY_PEERS_ADDED_TOTAL , TORRENT_REPOSITORY_PEERS_REMOVED_TOTAL , TORRENT_REPOSITORY_PEERS_UPDATED_TOTAL ,
365+ SWARM_COORDINATION_REGISTRY_PEERS_ADDED_TOTAL , SWARM_COORDINATION_REGISTRY_PEERS_REMOVED_TOTAL ,
366+ SWARM_COORDINATION_REGISTRY_PEERS_UPDATED_TOTAL ,
339367 } ;
340368 use crate :: tests:: { sample_info_hash, sample_peer} ;
341369 use crate :: CurrentClock ;
@@ -357,7 +385,7 @@ mod tests {
357385 expect_gauge_metric_to_be, get_gauge_metric, make_opposite_role_peer, make_peer,
358386 } ;
359387 use crate :: statistics:: repository:: Repository ;
360- use crate :: statistics:: TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ;
388+ use crate :: statistics:: SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ;
361389 use crate :: tests:: sample_info_hash;
362390 use crate :: CurrentClock ;
363391
@@ -373,7 +401,7 @@ mod tests {
373401 let peer = make_peer ( role) ;
374402
375403 let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
376- let metric_name = metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) ;
404+ let metric_name = metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ;
377405 let label_set = ( label_name ! ( "peer_role" ) , LabelValue :: new ( & role. to_string ( ) ) ) . into ( ) ;
378406
379407 handle_event (
@@ -402,7 +430,7 @@ mod tests {
402430
403431 let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
404432
405- let metric_name = metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) ;
433+ let metric_name = metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ;
406434 let label_set = ( label_name ! ( "peer_role" ) , LabelValue :: new ( & role. to_string ( ) ) ) . into ( ) ;
407435
408436 // Increment the gauge first to simulate a peer being added.
@@ -438,7 +466,7 @@ mod tests {
438466 let old_peer = make_peer ( old_role) ;
439467 let new_peer = make_opposite_role_peer ( & old_peer) ;
440468
441- let metric_name = metric_name ! ( TORRENT_REPOSITORY_PEER_CONNECTIONS_TOTAL ) ;
469+ let metric_name = metric_name ! ( SWARM_COORDINATION_REGISTRY_PEER_CONNECTIONS_TOTAL ) ;
442470 let old_role_label_set = ( label_name ! ( "peer_role" ) , LabelValue :: new ( & old_peer. role ( ) . to_string ( ) ) ) . into ( ) ;
443471 let new_role_label_set = ( label_name ! ( "peer_role" ) , LabelValue :: new ( & new_peer. role ( ) . to_string ( ) ) ) . into ( ) ;
444472
@@ -497,7 +525,7 @@ mod tests {
497525
498526 expect_counter_metric_to_be (
499527 & stats_repository,
500- & metric_name ! ( TORRENT_REPOSITORY_PEERS_ADDED_TOTAL ) ,
528+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_ADDED_TOTAL ) ,
501529 & label_set_for_peer ( & peer) ,
502530 1 ,
503531 )
@@ -524,7 +552,7 @@ mod tests {
524552
525553 expect_counter_metric_to_be (
526554 & stats_repository,
527- & metric_name ! ( TORRENT_REPOSITORY_PEERS_REMOVED_TOTAL ) ,
555+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_REMOVED_TOTAL ) ,
528556 & label_set_for_peer ( & peer) ,
529557 1 ,
530558 )
@@ -552,7 +580,7 @@ mod tests {
552580
553581 expect_counter_metric_to_be (
554582 & stats_repository,
555- & metric_name ! ( TORRENT_REPOSITORY_PEERS_UPDATED_TOTAL ) ,
583+ & metric_name ! ( SWARM_COORDINATION_REGISTRY_PEERS_UPDATED_TOTAL ) ,
556584 & label_set_for_peer ( & new_peer) ,
557585 1 ,
558586 )
@@ -574,7 +602,7 @@ mod tests {
574602 use crate :: statistics:: event:: handler:: handle_event;
575603 use crate :: statistics:: event:: handler:: tests:: { expect_counter_metric_to_be, make_peer} ;
576604 use crate :: statistics:: repository:: Repository ;
577- use crate :: statistics:: TORRENT_REPOSITORY_TORRENTS_DOWNLOADS_TOTAL ;
605+ use crate :: statistics:: SWARM_COORDINATION_REGISTRY_TORRENTS_DOWNLOADS_TOTAL ;
578606 use crate :: tests:: sample_info_hash;
579607 use crate :: CurrentClock ;
580608
@@ -590,7 +618,7 @@ mod tests {
590618 let peer = make_peer ( role) ;
591619
592620 let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
593- let metric_name = metric_name ! ( TORRENT_REPOSITORY_TORRENTS_DOWNLOADS_TOTAL ) ;
621+ let metric_name = metric_name ! ( SWARM_COORDINATION_REGISTRY_TORRENTS_DOWNLOADS_TOTAL ) ;
594622 let label_set = ( label_name ! ( "peer_role" ) , LabelValue :: new ( & role. to_string ( ) ) ) . into ( ) ;
595623
596624 handle_event (
0 commit comments