Skip to content

Commit 44c700d

Browse files
committed
feat: [#1438] merge UDP tracker core metrics
Extract `request_kind` label. Putting the request type in the metric name does not make sense. The purpose of the refactor to build the new extendable-labeled metrics was to start using labels to group metrics instead of changes in metric's names. From this: ``` http_tracker_core_announce_requests_received_total{server_binding_ip="0.0.0.0",server_binding_port="7070",server_binding_protocol="http"} 1 http_tracker_core_scrape_requests_received_total{server_binding_ip="0.0.0.0",server_binding_port="7070",server_binding_protocol="http"} 1 ``` To this: ``` http_tracker_core_requests_received_total{request_kind="announce",server_binding_ip="0.0.0.0",server_binding_port="7070",server_binding_protocol="http"} 1 http_tracker_core_requests_received_total{request_kind="scrape", server_binding_ip="0.0.0.0",server_binding_port="7070",server_binding_protocol="http"} 1 ```
1 parent 15a34c7 commit 44c700d

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

packages/http-tracker-core/src/statistics/event/handler.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::net::IpAddr;
22

3-
use torrust_tracker_metrics::label::LabelSet;
3+
use torrust_tracker_metrics::label::{LabelName, LabelSet, LabelValue};
44
use torrust_tracker_metrics::metric::MetricName;
55
use torrust_tracker_primitives::DurationSinceUnixEpoch;
66

77
use crate::event::Event;
88
use crate::statistics::repository::Repository;
9+
use crate::statistics::HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL;
910

1011
/// # Panics
1112
///
@@ -27,12 +28,11 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
2728

2829
// Extendable metrics
2930

31+
let mut label_set = LabelSet::from(connection);
32+
label_set.upsert(LabelName::new("request_kind"), LabelValue::new("announce"));
33+
3034
stats_repository
31-
.increase_counter(
32-
&MetricName::new("http_tracker_core_announce_requests_received_total"),
33-
&LabelSet::from(connection),
34-
now,
35-
)
35+
.increase_counter(&MetricName::new(HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL), &label_set, now)
3636
.await;
3737
}
3838
Event::TcpScrape { connection } => {
@@ -49,12 +49,11 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
4949

5050
// Extendable metrics
5151

52+
let mut label_set = LabelSet::from(connection);
53+
label_set.upsert(LabelName::new("request_kind"), LabelValue::new("scrape"));
54+
5255
stats_repository
53-
.increase_counter(
54-
&MetricName::new("http_tracker_core_scrape_requests_received_total"),
55-
&LabelSet::from(connection),
56-
now,
57-
)
56+
.increase_counter(&MetricName::new(HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL), &label_set, now)
5857
.await;
5958
}
6059
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@ use torrust_tracker_metrics::metric::description::MetricDescription;
1010
use torrust_tracker_metrics::metric::MetricName;
1111
use torrust_tracker_metrics::unit::Unit;
1212

13+
const HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL: &str = "http_tracker_core_requests_received_total";
14+
1315
#[must_use]
1416
pub fn describe_metrics() -> Metrics {
1517
let mut metrics = Metrics::default();
1618

1719
metrics.metric_collection.describe_counter(
18-
&MetricName::new("http_tracker_core_announce_requests_received_total"),
19-
Some(Unit::Count),
20-
Some(MetricDescription::new("Total number of HTTP announce requests received")),
21-
);
22-
23-
metrics.metric_collection.describe_counter(
24-
&MetricName::new("http_tracker_core_scrape_requests_received_total"),
20+
&MetricName::new(HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL),
2521
Some(Unit::Count),
26-
Some(MetricDescription::new("Total number of HTTP scrape requests received")),
22+
Some(MetricDescription::new("Total number of HTTP requests received")),
2723
);
2824

2925
metrics

0 commit comments

Comments
 (0)