Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul core Tracker: refactor statistics module #1229

Prev Previous commit
refactor: [#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.
  • Loading branch information
josecelano committed Jan 31, 2025

Verified

This commit was signed with the committer’s verified signature.
josecelano Jose Celano
commit fd8b57a6792977e823f38f2431ef7ad83794196d
9 changes: 1 addition & 8 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
@@ -26,21 +26,20 @@ use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentT
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use bittorrent_tracker_core::whitelist::setup::initialize_whitelist_manager;
use packages::statistics;
use tokio::sync::RwLock;
use torrust_tracker_clock::static_time;
use torrust_tracker_configuration::validator::Validator;
use torrust_tracker_configuration::Configuration;
use tracing::instrument;

use super::config::initialize_configuration;
use crate::bootstrap;
use crate::container::AppContainer;
use crate::packages::{http_tracker_core, udp_tracker_core};
use crate::servers::udp::server::banning::BanService;
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;
use crate::shared::crypto::ephemeral_instance_keys;
use crate::shared::crypto::keys::{self, Keeper as _};
use crate::{bootstrap, packages};

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

let (stats_event_sender, stats_repository) = statistics::setup::factory(configuration.core.tracker_usage_statistics);
let stats_event_sender = Arc::new(stats_event_sender);
let stats_repository = Arc::new(stats_repository);

// HTTP stats
let (http_stats_event_sender, http_stats_repository) =
http_tracker_core::statistics::setup::factory(configuration.core.tracker_usage_statistics);
@@ -148,10 +143,8 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
authentication_service,
whitelist_authorization,
ban_service,
stats_event_sender,
http_stats_event_sender,
udp_stats_event_sender,
stats_repository,
http_stats_repository,
udp_stats_repository,
whitelist_manager,
10 changes: 1 addition & 9 deletions src/container.rs
Original file line number Diff line number Diff line change
@@ -10,12 +10,10 @@ use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepo
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use bittorrent_tracker_core::whitelist;
use bittorrent_tracker_core::whitelist::manager::WhitelistManager;
use packages::statistics::event::sender::Sender;
use packages::statistics::repository::Repository;
use tokio::sync::RwLock;
use torrust_tracker_configuration::{Core, HttpApi, HttpTracker, UdpTracker};

use crate::packages::{self, http_tracker_core, udp_tracker_core};
use crate::packages::{http_tracker_core, udp_tracker_core};
use crate::servers::udp::server::banning::BanService;

pub struct AppContainer {
@@ -27,10 +25,8 @@ pub struct AppContainer {
pub authentication_service: Arc<AuthenticationService>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub ban_service: Arc<RwLock<BanService>>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
pub udp_stats_event_sender: Arc<Option<Box<dyn udp_tracker_core::statistics::event::sender::Sender>>>,
pub stats_repository: Arc<Repository>,
pub http_stats_repository: Arc<http_tracker_core::statistics::repository::Repository>,
pub udp_stats_repository: Arc<udp_tracker_core::statistics::repository::Repository>,
pub whitelist_manager: Arc<WhitelistManager>,
@@ -45,7 +41,6 @@ pub struct UdpTrackerContainer {
pub announce_handler: Arc<AnnounceHandler>,
pub scrape_handler: Arc<ScrapeHandler>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub udp_stats_event_sender: Arc<Option<Box<dyn udp_tracker_core::statistics::event::sender::Sender>>>,
pub ban_service: Arc<RwLock<BanService>>,
}
@@ -59,7 +54,6 @@ impl UdpTrackerContainer {
announce_handler: app_container.announce_handler.clone(),
scrape_handler: app_container.scrape_handler.clone(),
whitelist_authorization: app_container.whitelist_authorization.clone(),
stats_event_sender: app_container.stats_event_sender.clone(),
udp_stats_event_sender: app_container.udp_stats_event_sender.clone(),
ban_service: app_container.ban_service.clone(),
}
@@ -72,7 +66,6 @@ pub struct HttpTrackerContainer {
pub announce_handler: Arc<AnnounceHandler>,
pub scrape_handler: Arc<ScrapeHandler>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
pub authentication_service: Arc<AuthenticationService>,
}
@@ -86,7 +79,6 @@ impl HttpTrackerContainer {
announce_handler: app_container.announce_handler.clone(),
scrape_handler: app_container.scrape_handler.clone(),
whitelist_authorization: app_container.whitelist_authorization.clone(),
stats_event_sender: app_container.stats_event_sender.clone(),
http_stats_event_sender: app_container.http_stats_event_sender.clone(),
authentication_service: app_container.authentication_service.clone(),
}
10 changes: 6 additions & 4 deletions src/packages/http_tracker_core/statistics/services.rs
Original file line number Diff line number Diff line change
@@ -76,8 +76,8 @@ mod tests {
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
use torrust_tracker_test_helpers::configuration;

use crate::packages::http_tracker_core::statistics;
use crate::packages::http_tracker_core::statistics::services::{get_metrics, TrackerMetrics};
use crate::packages::http_tracker_core::{self, statistics};

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

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

let tracker_metrics = get_metrics(in_memory_torrent_repository.clone(), stats_repository.clone()).await;
let (_http_stats_event_sender, http_stats_repository) =
http_tracker_core::statistics::setup::factory(config.core.tracker_usage_statistics);
let http_stats_repository = Arc::new(http_stats_repository);

let tracker_metrics = get_metrics(in_memory_torrent_repository.clone(), http_stats_repository.clone()).await;

assert_eq!(
tracker_metrics,
1 change: 0 additions & 1 deletion src/packages/mod.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,5 @@
//!
//! It will be moved to the directory `packages`.
pub mod http_tracker_core;
pub mod statistics;
pub mod tracker_api_core;
pub mod udp_tracker_core;
262 changes: 0 additions & 262 deletions src/packages/statistics/event/handler.rs

This file was deleted.

Loading