Skip to content

Commit 397bf0f

Browse files
committed
chore: report find content query elapsed time
1 parent 2310a4d commit 397bf0f

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

trin-history/src/downloader.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,16 @@ impl Downloader {
163163
block_number: u64,
164164
content_type: ContentType,
165165
) -> anyhow::Result<()> {
166-
if CENSUS {
166+
let timer = self.metrics.start_find_content_timer();
167+
let result = if CENSUS {
167168
self.find_content_census(&content_key, block_number, content_type)
168169
.await
169170
} else {
170171
self.recursive_find_content(content_key, block_number, content_type)
171172
.await
172-
}
173+
};
174+
self.metrics.stop_find_content_timer(timer);
175+
result
173176
}
174177

175178
/// Send FindContent queries to the interested peers in the census, includes peers scoring

trin-metrics/src/downloader.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use prometheus_exporter::prometheus::{
2-
opts, register_int_gauge_vec_with_registry, IntGaugeVec, Registry,
2+
histogram_opts, opts, register_histogram_vec_with_registry,
3+
register_int_gauge_vec_with_registry, HistogramTimer, HistogramVec, IntGaugeVec, Registry,
34
};
45

56
use crate::portalnet::PORTALNET_METRICS;
@@ -8,6 +9,7 @@ use crate::portalnet::PORTALNET_METRICS;
89
#[derive(Clone, Debug)]
910
pub struct DownloaderMetrics {
1011
pub current_block: IntGaugeVec,
12+
pub find_content_timer: HistogramVec,
1113
}
1214

1315
impl DownloaderMetrics {
@@ -20,7 +22,18 @@ impl DownloaderMetrics {
2022
&["downloader"],
2123
registry
2224
)?;
23-
Ok(Self { current_block })
25+
let find_content_timer = register_histogram_vec_with_registry!(
26+
histogram_opts!(
27+
"downloader_find_content_timer",
28+
"the time it takes for find content query to complete"
29+
),
30+
&["downloader"],
31+
registry
32+
)?;
33+
Ok(Self {
34+
current_block,
35+
find_content_timer,
36+
})
2437
}
2538
}
2639

@@ -48,4 +61,15 @@ impl DownloaderMetricsReporter {
4861
.with_label_values(&["downloader"])
4962
.set(block_number as i64);
5063
}
64+
65+
pub fn start_find_content_timer(&self) -> HistogramTimer {
66+
self.metrics
67+
.find_content_timer
68+
.with_label_values(&["downloader"])
69+
.start_timer()
70+
}
71+
72+
pub fn stop_find_content_timer(&self, timer: HistogramTimer) {
73+
timer.observe_duration()
74+
}
5175
}

0 commit comments

Comments
 (0)