Skip to content

Commit d9f4c13

Browse files
committed
refactor: [#1556] extract functions
1 parent 578057b commit d9f4c13

File tree

1 file changed

+14
-5
lines changed
  • packages/udp-tracker-server/src/statistics/event/handler

1 file changed

+14
-5
lines changed

packages/udp-tracker-server/src/statistics/event/handler/error.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ pub async fn handle_event(
1818
ban_service: &Arc<RwLock<BanService>>,
1919
now: DurationSinceUnixEpoch,
2020
) {
21-
// Increase the number of errors
22-
// code-review: should we ban IP due to other errors too?
2321
if let ErrorKind::ConnectionCookie(_msg) = error {
2422
let mut ban_service = ban_service.write().await;
2523
ban_service.increase_counter(&context.client_socket_addr().ip());
2624
}
2725

28-
// Global fixed metrics
26+
update_global_fixed_metrics(&context, stats_repository).await;
27+
28+
update_extendable_metrics(&context, kind, stats_repository, now).await;
29+
}
30+
31+
async fn update_global_fixed_metrics(context: &ConnectionContext, stats_repository: &Repository) {
2932
match context.client_socket_addr().ip() {
3033
std::net::IpAddr::V4(_) => {
3134
stats_repository.increase_udp4_errors().await;
@@ -34,9 +37,15 @@ pub async fn handle_event(
3437
stats_repository.increase_udp6_errors().await;
3538
}
3639
}
40+
}
3741

38-
// Extendable metrics
39-
let mut label_set = LabelSet::from(context);
42+
async fn update_extendable_metrics(
43+
context: &ConnectionContext,
44+
kind: Option<UdpRequestKind>,
45+
stats_repository: &Repository,
46+
now: DurationSinceUnixEpoch,
47+
) {
48+
let mut label_set = LabelSet::from(context.clone());
4049
if let Some(kind) = kind {
4150
label_set.upsert(label_name!("request_kind"), kind.to_string().into());
4251
}

0 commit comments

Comments
 (0)