Skip to content

Commit 3d6fc65

Browse files
committed
refactor: [torrust#1543] rename AggregateSwarmMetadata to AggregateActiveSwarmMetadata
Aggregate values are only for active swarms. For example, it does not count downloads for torrents that are not currently active.
1 parent 4b4f310 commit 3d6fc65

File tree

19 files changed

+70
-71
lines changed

19 files changed

+70
-71
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl From<TrackerLabeledMetrics> for LabeledStats {
136136
mod tests {
137137
use torrust_rest_tracker_api_core::statistics::metrics::Metrics;
138138
use torrust_rest_tracker_api_core::statistics::services::TrackerMetrics;
139-
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
139+
use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata;
140140

141141
use super::Stats;
142142

@@ -145,7 +145,7 @@ mod tests {
145145
fn stats_resource_should_be_converted_from_tracker_metrics() {
146146
assert_eq!(
147147
Stats::from(TrackerMetrics {
148-
torrents_metrics: AggregateSwarmMetadata {
148+
torrents_metrics: AggregateActiveSwarmMetadata {
149149
total_complete: 1,
150150
total_downloaded: 2,
151151
total_incomplete: 3,

packages/http-tracker-core/src/statistics/services.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use std::sync::Arc;
2424

2525
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
26-
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
26+
use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata;
2727

2828
use crate::statistics::metrics::Metrics;
2929
use crate::statistics::repository::Repository;
@@ -34,7 +34,7 @@ pub struct TrackerMetrics {
3434
/// Domain level metrics.
3535
///
3636
/// General metrics for all torrents (number of seeders, leechers, etcetera)
37-
pub torrents_metrics: AggregateSwarmMetadata,
37+
pub torrents_metrics: AggregateActiveSwarmMetadata,
3838

3939
/// Application level metrics. Usage statistics/metrics.
4040
///
@@ -72,7 +72,7 @@ mod tests {
7272
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
7373
use bittorrent_tracker_core::{self};
7474
use torrust_tracker_configuration::Configuration;
75-
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
75+
use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata;
7676
use torrust_tracker_test_helpers::configuration;
7777

7878
use crate::event::bus::EventBus;
@@ -109,7 +109,7 @@ mod tests {
109109
assert_eq!(
110110
tracker_metrics,
111111
TrackerMetrics {
112-
torrents_metrics: AggregateSwarmMetadata::default(),
112+
torrents_metrics: AggregateActiveSwarmMetadata::default(),
113113
protocol_metrics: describe_metrics(),
114114
}
115115
);

packages/primitives/src/swarm_metadata.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,23 @@ impl SwarmMetadata {
4646

4747
/// Structure that holds aggregate swarm metadata.
4848
///
49-
/// Metrics are aggregate values for all torrents.
49+
/// Metrics are aggregate values for all active torrents/swarms.
5050
#[derive(Copy, Clone, Debug, PartialEq, Default)]
51-
pub struct AggregateSwarmMetadata {
52-
/// Total number of peers that have ever completed downloading for all
53-
/// torrents.
51+
pub struct AggregateActiveSwarmMetadata {
52+
/// Total number of peers that have ever completed downloading.
5453
pub total_downloaded: u64,
5554

56-
/// Total number of seeders for all torrents.
55+
/// Total number of seeders.
5756
pub total_complete: u64,
5857

59-
/// Total number of leechers for all torrents.
58+
/// Total number of leechers.
6059
pub total_incomplete: u64,
6160

6261
/// Total number of torrents.
6362
pub total_torrents: u64,
6463
}
6564

66-
impl AddAssign for AggregateSwarmMetadata {
65+
impl AddAssign for AggregateActiveSwarmMetadata {
6766
fn add_assign(&mut self, rhs: Self) {
6867
self.total_complete += rhs.total_complete;
6968
self.total_downloaded += rhs.total_downloaded;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bittorrent_udp_tracker_core::services::banning::BanService;
55
use bittorrent_udp_tracker_core::{self};
66
use tokio::sync::RwLock;
77
use torrust_tracker_metrics::metric_collection::MetricCollection;
8-
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
8+
use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata;
99
use torrust_udp_tracker_server::statistics as udp_server_statistics;
1010

1111
use crate::statistics::metrics::Metrics;
@@ -16,7 +16,7 @@ pub struct TrackerMetrics {
1616
/// Domain level metrics.
1717
///
1818
/// General metrics for all torrents (number of seeders, leechers, etcetera)
19-
pub torrents_metrics: AggregateSwarmMetadata,
19+
pub torrents_metrics: AggregateActiveSwarmMetadata,
2020

2121
/// Application level metrics. Usage statistics/metrics.
2222
///
@@ -144,7 +144,7 @@ mod tests {
144144
use bittorrent_udp_tracker_core::MAX_CONNECTION_ID_ERRORS_PER_IP;
145145
use tokio::sync::RwLock;
146146
use torrust_tracker_configuration::Configuration;
147-
use torrust_tracker_primitives::swarm_metadata::AggregateSwarmMetadata;
147+
use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata;
148148
use torrust_tracker_test_helpers::configuration;
149149

150150
use crate::statistics::metrics::Metrics;
@@ -187,7 +187,7 @@ mod tests {
187187
assert_eq!(
188188
tracker_metrics,
189189
TrackerMetrics {
190-
torrents_metrics: AggregateSwarmMetadata::default(),
190+
torrents_metrics: AggregateActiveSwarmMetadata::default(),
191191
protocol_metrics: Metrics::default(),
192192
}
193193
);

packages/torrent-repository-benchmarking/src/repository/dash_map_mutex_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bittorrent_primitives::info_hash::InfoHash;
44
use dashmap::DashMap;
55
use torrust_tracker_configuration::TrackerPolicy;
66
use torrust_tracker_primitives::pagination::Pagination;
7-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
7+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
88
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
99

1010
use super::Repository;
@@ -46,8 +46,8 @@ where
4646
maybe_entry.map(|entry| entry.clone())
4747
}
4848

49-
fn get_metrics(&self) -> AggregateSwarmMetadata {
50-
let mut metrics = AggregateSwarmMetadata::default();
49+
fn get_metrics(&self) -> AggregateActiveSwarmMetadata {
50+
let mut metrics = AggregateActiveSwarmMetadata::default();
5151

5252
for entry in &self.torrents {
5353
let stats = entry.value().lock().expect("it should get a lock").get_swarm_metadata();

packages/torrent-repository-benchmarking/src/repository/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bittorrent_primitives::info_hash::InfoHash;
22
use torrust_tracker_configuration::TrackerPolicy;
33
use torrust_tracker_primitives::pagination::Pagination;
4-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
4+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
55
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
66

77
pub mod dash_map_mutex_std;
@@ -17,7 +17,7 @@ use std::fmt::Debug;
1717

1818
pub trait Repository<T>: Debug + Default + Sized + 'static {
1919
fn get(&self, key: &InfoHash) -> Option<T>;
20-
fn get_metrics(&self) -> AggregateSwarmMetadata;
20+
fn get_metrics(&self) -> AggregateActiveSwarmMetadata;
2121
fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, T)>;
2222
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap);
2323
fn remove(&self, key: &InfoHash) -> Option<T>;
@@ -30,7 +30,7 @@ pub trait Repository<T>: Debug + Default + Sized + 'static {
3030
#[allow(clippy::module_name_repetitions)]
3131
pub trait RepositoryAsync<T>: Debug + Default + Sized + 'static {
3232
fn get(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;
33-
fn get_metrics(&self) -> impl std::future::Future<Output = AggregateSwarmMetadata> + Send;
33+
fn get_metrics(&self) -> impl std::future::Future<Output = AggregateActiveSwarmMetadata> + Send;
3434
fn get_paginated(&self, pagination: Option<&Pagination>) -> impl std::future::Future<Output = Vec<(InfoHash, T)>> + Send;
3535
fn import_persistent(&self, persistent_torrents: &NumberOfDownloadsBTreeMap) -> impl std::future::Future<Output = ()> + Send;
3636
fn remove(&self, key: &InfoHash) -> impl std::future::Future<Output = Option<T>> + Send;

packages/torrent-repository-benchmarking/src/repository/rw_lock_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bittorrent_primitives::info_hash::InfoHash;
22
use torrust_tracker_configuration::TrackerPolicy;
33
use torrust_tracker_primitives::pagination::Pagination;
4-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
4+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
55
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
66

77
use super::Repository;
@@ -64,8 +64,8 @@ where
6464
db.get(key).cloned()
6565
}
6666

67-
fn get_metrics(&self) -> AggregateSwarmMetadata {
68-
let mut metrics = AggregateSwarmMetadata::default();
67+
fn get_metrics(&self) -> AggregateActiveSwarmMetadata {
68+
let mut metrics = AggregateActiveSwarmMetadata::default();
6969

7070
for entry in self.get_torrents().values() {
7171
let stats = entry.get_swarm_metadata();

packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use bittorrent_primitives::info_hash::InfoHash;
44
use torrust_tracker_configuration::TrackerPolicy;
55
use torrust_tracker_primitives::pagination::Pagination;
6-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
6+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
77
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
88

99
use super::Repository;
@@ -59,8 +59,8 @@ where
5959
db.get(key).cloned()
6060
}
6161

62-
fn get_metrics(&self) -> AggregateSwarmMetadata {
63-
let mut metrics = AggregateSwarmMetadata::default();
62+
fn get_metrics(&self) -> AggregateActiveSwarmMetadata {
63+
let mut metrics = AggregateActiveSwarmMetadata::default();
6464

6565
for entry in self.get_torrents().values() {
6666
let stats = entry.lock().expect("it should get a lock").get_swarm_metadata();

packages/torrent-repository-benchmarking/src/repository/rw_lock_std_mutex_tokio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use futures::future::join_all;
77
use futures::{Future, FutureExt};
88
use torrust_tracker_configuration::TrackerPolicy;
99
use torrust_tracker_primitives::pagination::Pagination;
10-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
10+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
1111
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
1212

1313
use super::RepositoryAsync;
@@ -85,8 +85,8 @@ where
8585
}
8686
}
8787

88-
async fn get_metrics(&self) -> AggregateSwarmMetadata {
89-
let mut metrics = AggregateSwarmMetadata::default();
88+
async fn get_metrics(&self) -> AggregateActiveSwarmMetadata {
89+
let mut metrics = AggregateActiveSwarmMetadata::default();
9090

9191
let entries: Vec<_> = self.get_torrents().values().cloned().collect();
9292

packages/torrent-repository-benchmarking/src/repository/rw_lock_tokio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bittorrent_primitives::info_hash::InfoHash;
22
use torrust_tracker_configuration::TrackerPolicy;
33
use torrust_tracker_primitives::pagination::Pagination;
4-
use torrust_tracker_primitives::swarm_metadata::{AggregateSwarmMetadata, SwarmMetadata};
4+
use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata};
55
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap};
66

77
use super::RepositoryAsync;
@@ -84,8 +84,8 @@ where
8484
}
8585
}
8686

87-
async fn get_metrics(&self) -> AggregateSwarmMetadata {
88-
let mut metrics = AggregateSwarmMetadata::default();
87+
async fn get_metrics(&self) -> AggregateActiveSwarmMetadata {
88+
let mut metrics = AggregateActiveSwarmMetadata::default();
8989

9090
for entry in self.get_torrents().await.values() {
9191
let stats = entry.get_swarm_metadata();

0 commit comments

Comments
 (0)