Skip to content

Commit 81d7214

Browse files
committed
Add duration histogram for support info requests.
1 parent 2356daf commit 81d7214

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

nts-pool-ke/src/servers.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77
};
88

99
use notify::{RecursiveMode, Watcher};
10-
use opentelemetry::{KeyValue, metrics::Counter};
10+
use opentelemetry::{
11+
KeyValue,
12+
metrics::{Counter, Histogram},
13+
};
1114
use pool_nts::{
1215
AlgorithmDescription, AlgorithmId, BufferBorrowingReader, MAX_MESSAGE_SIZE, ProtocolId,
1316
ServerInformationRequest, ServerInformationResponse,
@@ -21,7 +24,10 @@ use tokio::{
2124
};
2225
use tokio_rustls::{TlsConnector, client::TlsStream};
2326

24-
use crate::{config::BackendConfig, error::PoolError, util::load_certificates};
27+
use crate::{
28+
config::BackendConfig, error::PoolError, telemetry::TIMING_HISTOGRAM_BUCKET_BOUNDARIES,
29+
util::load_certificates,
30+
};
2531

2632
mod geo;
2733
pub use geo::GeographicServerManager;
@@ -187,6 +193,18 @@ async fn fetch_support_data(
187193
.build()
188194
});
189195

196+
static SUPPORT_REQUEST_DURATION: OnceLock<Histogram<f64>> = OnceLock::new();
197+
198+
let support_request_duration = SUPPORT_REQUEST_DURATION.get_or_init(|| {
199+
opentelemetry::global::meter("PoolKe")
200+
.f64_histogram("support_request_duration")
201+
.with_description("Duration of support information requests to a server")
202+
.with_unit("s")
203+
.with_boundaries(TIMING_HISTOGRAM_BUCKET_BOUNDARIES.to_vec())
204+
.build()
205+
});
206+
207+
let start = std::time::Instant::now();
190208
match tokio::time::timeout(timeout, async {
191209
ServerInformationRequest {
192210
key: key.into(),
@@ -221,6 +239,19 @@ async fn fetch_support_data(
221239
.await
222240
{
223241
Ok(v) => {
242+
support_request_duration.record(
243+
start.elapsed().as_secs_f64(),
244+
&[
245+
KeyValue::new("uuid", uuid.clone()),
246+
KeyValue::new(
247+
"outcome",
248+
match v {
249+
Ok(_) => "success",
250+
Err(_) => "error",
251+
},
252+
),
253+
],
254+
);
224255
support_request_counter.add(
225256
1,
226257
&[
@@ -237,6 +268,13 @@ async fn fetch_support_data(
237268
v
238269
}
239270
Err(_) => {
271+
support_request_duration.record(
272+
start.elapsed().as_secs_f64(),
273+
&[
274+
KeyValue::new("uuid", uuid.clone()),
275+
KeyValue::new("outcome", "timeout"),
276+
],
277+
);
240278
support_request_counter.add(
241279
1,
242280
&[

0 commit comments

Comments
 (0)