-
Notifications
You must be signed in to change notification settings - Fork 49
Labels
Code Cleanup / RefactoringTidying and Making NeatTidying and Making Neat
Description
Depends on: #1445
The API exposes the "old" metrics (/stats) and the new ones (/metrics)
Internally, we use only one repository to store both:
For example, in packages/http-tracker-core/src/statistics/metrics.rs:
pub struct Metrics {
/// Total number of TCP (HTTP tracker) `announce` requests from IPv4 peers.
pub tcp4_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv4 peers.
pub tcp4_scrapes_handled: u64,
/// Total number of TCP (HTTP tracker) `announce` requests from IPv6 peers.
pub tcp6_announces_handled: u64,
/// Total number of TCP (HTTP tracker) `scrape` requests from IPv6 peers.
pub tcp6_scrapes_handled: u64,
/// A collection of metrics.
pub metric_collection: MetricCollection,
}
impl Metrics {
pub fn increase_counter(&mut self, metric_name: &MetricName, labels: &LabelSet, now: DurationSinceUnixEpoch) {
self.metric_collection.increase_counter(metric_name, labels, now);
}
pub fn set_gauge(&mut self, metric_name: &MetricName, labels: &LabelSet, value: f64, now: DurationSinceUnixEpoch) {
self.metric_collection.set_gauge(metric_name, labels, value, now);
}
}
I kept global and new metrics because I didn't want to make breaking changes in the API. However, we can remove the old ones internally and calculate them from the new ones only when the API replies to a /stats request.
That would have these benefits:
- Simplify the
bittorrent_http_tracker_core::statistics::event::handler - Improve performance; the tracker does not have to maintain both metrics.
The cons are:
- The old
/statsendpoint will be slower - We must implement new methods in the
MetricColelctiontype to calculate aggregate data. These methods could be helpful for other tasks in the future.
Metadata
Metadata
Assignees
Labels
Code Cleanup / RefactoringTidying and Making NeatTidying and Making Neat