Skip to content

Commit fd8b57a

Browse files
committed
refactor: [torrust#1228] remove deprecated unified HTTP and UDP stats
Stats have been split into HTTP and UDP stats. Parallel change, step 4: 1. [x] Start using HTTP Tracker Core Stats 2. [x] Start using UDP Tracker Core Stats 3. [x] Get metrics from HTTP and UDP Tracker Core Stats 4. [x] Remove deprecated unified HTTP and UDP stats.
1 parent 5576938 commit fd8b57a

File tree

27 files changed

+78
-1468
lines changed

27 files changed

+78
-1468
lines changed

src/bootstrap/app.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentT
2626
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
2727
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
2828
use bittorrent_tracker_core::whitelist::setup::initialize_whitelist_manager;
29-
use packages::statistics;
3029
use tokio::sync::RwLock;
3130
use torrust_tracker_clock::static_time;
3231
use torrust_tracker_configuration::validator::Validator;
3332
use torrust_tracker_configuration::Configuration;
3433
use tracing::instrument;
3534

3635
use super::config::initialize_configuration;
36+
use crate::bootstrap;
3737
use crate::container::AppContainer;
3838
use crate::packages::{http_tracker_core, udp_tracker_core};
3939
use crate::servers::udp::server::banning::BanService;
4040
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;
4141
use crate::shared::crypto::ephemeral_instance_keys;
4242
use crate::shared::crypto::keys::{self, Keeper as _};
43-
use crate::{bootstrap, packages};
4443

4544
/// It loads the configuration from the environment and builds app container.
4645
///
@@ -92,10 +91,6 @@ pub fn initialize_global_services(configuration: &Configuration) {
9291
pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
9392
let core_config = Arc::new(configuration.core.clone());
9493

95-
let (stats_event_sender, stats_repository) = statistics::setup::factory(configuration.core.tracker_usage_statistics);
96-
let stats_event_sender = Arc::new(stats_event_sender);
97-
let stats_repository = Arc::new(stats_repository);
98-
9994
// HTTP stats
10095
let (http_stats_event_sender, http_stats_repository) =
10196
http_tracker_core::statistics::setup::factory(configuration.core.tracker_usage_statistics);
@@ -148,10 +143,8 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
148143
authentication_service,
149144
whitelist_authorization,
150145
ban_service,
151-
stats_event_sender,
152146
http_stats_event_sender,
153147
udp_stats_event_sender,
154-
stats_repository,
155148
http_stats_repository,
156149
udp_stats_repository,
157150
whitelist_manager,

src/container.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepo
1010
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
1111
use bittorrent_tracker_core::whitelist;
1212
use bittorrent_tracker_core::whitelist::manager::WhitelistManager;
13-
use packages::statistics::event::sender::Sender;
14-
use packages::statistics::repository::Repository;
1513
use tokio::sync::RwLock;
1614
use torrust_tracker_configuration::{Core, HttpApi, HttpTracker, UdpTracker};
1715

18-
use crate::packages::{self, http_tracker_core, udp_tracker_core};
16+
use crate::packages::{http_tracker_core, udp_tracker_core};
1917
use crate::servers::udp::server::banning::BanService;
2018

2119
pub struct AppContainer {
@@ -27,10 +25,8 @@ pub struct AppContainer {
2725
pub authentication_service: Arc<AuthenticationService>,
2826
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
2927
pub ban_service: Arc<RwLock<BanService>>,
30-
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
3128
pub http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
3229
pub udp_stats_event_sender: Arc<Option<Box<dyn udp_tracker_core::statistics::event::sender::Sender>>>,
33-
pub stats_repository: Arc<Repository>,
3430
pub http_stats_repository: Arc<http_tracker_core::statistics::repository::Repository>,
3531
pub udp_stats_repository: Arc<udp_tracker_core::statistics::repository::Repository>,
3632
pub whitelist_manager: Arc<WhitelistManager>,
@@ -45,7 +41,6 @@ pub struct UdpTrackerContainer {
4541
pub announce_handler: Arc<AnnounceHandler>,
4642
pub scrape_handler: Arc<ScrapeHandler>,
4743
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
48-
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
4944
pub udp_stats_event_sender: Arc<Option<Box<dyn udp_tracker_core::statistics::event::sender::Sender>>>,
5045
pub ban_service: Arc<RwLock<BanService>>,
5146
}
@@ -59,7 +54,6 @@ impl UdpTrackerContainer {
5954
announce_handler: app_container.announce_handler.clone(),
6055
scrape_handler: app_container.scrape_handler.clone(),
6156
whitelist_authorization: app_container.whitelist_authorization.clone(),
62-
stats_event_sender: app_container.stats_event_sender.clone(),
6357
udp_stats_event_sender: app_container.udp_stats_event_sender.clone(),
6458
ban_service: app_container.ban_service.clone(),
6559
}
@@ -72,7 +66,6 @@ pub struct HttpTrackerContainer {
7266
pub announce_handler: Arc<AnnounceHandler>,
7367
pub scrape_handler: Arc<ScrapeHandler>,
7468
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
75-
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
7669
pub http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
7770
pub authentication_service: Arc<AuthenticationService>,
7871
}
@@ -86,7 +79,6 @@ impl HttpTrackerContainer {
8679
announce_handler: app_container.announce_handler.clone(),
8780
scrape_handler: app_container.scrape_handler.clone(),
8881
whitelist_authorization: app_container.whitelist_authorization.clone(),
89-
stats_event_sender: app_container.stats_event_sender.clone(),
9082
http_stats_event_sender: app_container.http_stats_event_sender.clone(),
9183
authentication_service: app_container.authentication_service.clone(),
9284
}

src/packages/http_tracker_core/statistics/services.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ mod tests {
7676
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
7777
use torrust_tracker_test_helpers::configuration;
7878

79-
use crate::packages::http_tracker_core::statistics;
8079
use crate::packages::http_tracker_core::statistics::services::{get_metrics, TrackerMetrics};
80+
use crate::packages::http_tracker_core::{self, statistics};
8181

8282
pub fn tracker_configuration() -> Configuration {
8383
configuration::ephemeral()
@@ -88,10 +88,12 @@ mod tests {
8888
let config = tracker_configuration();
8989

9090
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
91-
let (_stats_event_sender, stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
92-
let stats_repository = Arc::new(stats_repository);
9391

94-
let tracker_metrics = get_metrics(in_memory_torrent_repository.clone(), stats_repository.clone()).await;
92+
let (_http_stats_event_sender, http_stats_repository) =
93+
http_tracker_core::statistics::setup::factory(config.core.tracker_usage_statistics);
94+
let http_stats_repository = Arc::new(http_stats_repository);
95+
96+
let tracker_metrics = get_metrics(in_memory_torrent_repository.clone(), http_stats_repository.clone()).await;
9597

9698
assert_eq!(
9799
tracker_metrics,

src/packages/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
//!
33
//! It will be moved to the directory `packages`.
44
pub mod http_tracker_core;
5-
pub mod statistics;
65
pub mod tracker_api_core;
76
pub mod udp_tracker_core;

src/packages/statistics/event/handler.rs

-262
This file was deleted.

0 commit comments

Comments
 (0)