Skip to content

Commit b830e5a

Browse files
committed
Add duration histogram for support info requests.
1 parent 867274b commit b830e5a

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;
@@ -188,6 +194,18 @@ async fn fetch_support_data(
188194
.build()
189195
});
190196

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

0 commit comments

Comments
 (0)