Skip to content

Commit 3ee074f

Browse files
committed
Merge #1387: Overhaul stats: Use only UDP server stats in the REST API
e729a5f refactor: [#1386] remove dependency on UDP core metrics from API (Jose Celano) Pull request description: Overhaul stats: Use only UDP server stats in the REST API. ACKs for top commit: josecelano: ACK e729a5f Tree-SHA512: 74eeb0021637d1c1fab42032dcb3905bef688b233eb9230db402b130388656fbd823ae2895ede827a00510ae43b780bb093a7f3cdef8525a0ce5385213da9507
2 parents 7451712 + e729a5f commit 3ee074f

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

packages/axum-rest-tracker-api-server/src/v1/context/stats/handlers.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,11 @@ pub async fn get_stats_handler(
4343
Arc<InMemoryTorrentRepository>,
4444
Arc<RwLock<BanService>>,
4545
Arc<bittorrent_http_tracker_core::statistics::repository::Repository>,
46-
Arc<bittorrent_udp_tracker_core::statistics::repository::Repository>,
4746
Arc<torrust_udp_tracker_server::statistics::repository::Repository>,
4847
)>,
4948
params: Query<QueryParams>,
5049
) -> Response {
51-
let metrics = get_metrics(
52-
state.0.clone(),
53-
state.1.clone(),
54-
state.2.clone(),
55-
state.3.clone(),
56-
state.4.clone(),
57-
)
58-
.await;
50+
let metrics = get_metrics(state.0.clone(), state.1.clone(), state.2.clone(), state.3.clone()).await;
5951

6052
match params.0.format {
6153
Some(format) => match format {

packages/axum-rest-tracker-api-server/src/v1/context/stats/routes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn add(prefix: &str, router: Router, http_api_container: &Arc<TrackerHttpApi
1919
http_api_container.in_memory_torrent_repository.clone(),
2020
http_api_container.ban_service.clone(),
2121
http_api_container.http_stats_repository.clone(),
22-
http_api_container.udp_core_stats_repository.clone(),
2322
http_api_container.udp_server_stats_repository.clone(),
2423
)),
2524
)

packages/rest-tracker-api-core/src/statistics/services.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
44
use bittorrent_udp_tracker_core::services::banning::BanService;
5-
use bittorrent_udp_tracker_core::{self, statistics as udp_core_statistics};
5+
use bittorrent_udp_tracker_core::{self};
66
use tokio::sync::RwLock;
77
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
88
use torrust_udp_tracker_server::statistics as udp_server_statistics;
@@ -29,13 +29,11 @@ pub async fn get_metrics(
2929
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
3030
ban_service: Arc<RwLock<BanService>>,
3131
http_stats_repository: Arc<bittorrent_http_tracker_core::statistics::repository::Repository>,
32-
udp_core_stats_repository: Arc<udp_core_statistics::repository::Repository>,
3332
udp_server_stats_repository: Arc<udp_server_statistics::repository::Repository>,
3433
) -> TrackerMetrics {
3534
let torrents_metrics = in_memory_torrent_repository.get_torrents_metrics();
3635
let udp_banned_ips_total = ban_service.read().await.get_banned_ips_total();
3736
let http_stats = http_stats_repository.get_stats().await;
38-
let udp_core_stats = udp_core_stats_repository.get_stats().await;
3937
let udp_server_stats = udp_server_stats_repository.get_stats().await;
4038

4139
// For backward compatibility we keep the `tcp4_connections_handled` and
@@ -63,16 +61,16 @@ pub async fn get_metrics(
6361
udp_avg_scrape_processing_time_ns: udp_server_stats.udp_avg_scrape_processing_time_ns,
6462
// UDPv4
6563
udp4_requests: udp_server_stats.udp4_requests,
66-
udp4_connections_handled: udp_core_stats.udp4_connections_handled,
67-
udp4_announces_handled: udp_core_stats.udp4_announces_handled,
68-
udp4_scrapes_handled: udp_core_stats.udp4_scrapes_handled,
64+
udp4_connections_handled: udp_server_stats.udp4_connections_handled,
65+
udp4_announces_handled: udp_server_stats.udp4_announces_handled,
66+
udp4_scrapes_handled: udp_server_stats.udp4_scrapes_handled,
6967
udp4_responses: udp_server_stats.udp4_responses,
7068
udp4_errors_handled: udp_server_stats.udp4_errors_handled,
7169
// UDPv6
7270
udp6_requests: udp_server_stats.udp6_requests,
73-
udp6_connections_handled: udp_core_stats.udp6_connections_handled,
74-
udp6_announces_handled: udp_core_stats.udp6_announces_handled,
75-
udp6_scrapes_handled: udp_core_stats.udp6_scrapes_handled,
71+
udp6_connections_handled: udp_server_stats.udp6_connections_handled,
72+
udp6_announces_handled: udp_server_stats.udp6_announces_handled,
73+
udp6_scrapes_handled: udp_server_stats.udp6_scrapes_handled,
7674
udp6_responses: udp_server_stats.udp6_responses,
7775
udp6_errors_handled: udp_server_stats.udp6_errors_handled,
7876
},
@@ -112,9 +110,8 @@ mod tests {
112110
let http_stats_repository = Arc::new(http_stats_repository);
113111

114112
// UDP core stats
115-
let (_udp_stats_event_sender, udp_stats_repository) =
113+
let (_udp_stats_event_sender, _udp_stats_repository) =
116114
bittorrent_udp_tracker_core::statistics::setup::factory(config.core.tracker_usage_statistics);
117-
let udp_stats_repository = Arc::new(udp_stats_repository);
118115

119116
// UDP server stats
120117
let (_udp_server_stats_event_sender, udp_server_stats_repository) =
@@ -125,7 +122,6 @@ mod tests {
125122
in_memory_torrent_repository.clone(),
126123
ban_service.clone(),
127124
http_stats_repository.clone(),
128-
udp_stats_repository.clone(),
129125
udp_server_stats_repository.clone(),
130126
)
131127
.await;

0 commit comments

Comments
 (0)