Skip to content

Commit e474d86

Browse files
committed
Added counter for support requests to servers.
1 parent 20b7e36 commit e474d86

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

nts-pool-ke/src/servers.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use std::{
22
borrow::Cow,
33
collections::{HashMap, HashSet},
44
net::SocketAddr,
5-
sync::{Arc, RwLock},
5+
sync::{Arc, OnceLock, RwLock},
66
time::Duration,
77
};
88

99
use notify::{RecursiveMode, Watcher};
10+
use opentelemetry::{KeyValue, metrics::Counter};
1011
use pool_nts::{
1112
AlgorithmDescription, AlgorithmId, BufferBorrowingReader, MAX_MESSAGE_SIZE, ProtocolId,
1213
ServerInformationRequest, ServerInformationResponse,
@@ -166,6 +167,7 @@ fn calculate_auth_key(
166167

167168
async fn fetch_support_data(
168169
mut connection: impl ServerConnection,
170+
uuid: Arc<str>,
169171
key: String,
170172
allowed_protocols: &HashSet<ProtocolId>,
171173
timeout: Duration,
@@ -176,6 +178,15 @@ async fn fetch_support_data(
176178
),
177179
PoolError,
178180
> {
181+
static SUPPORT_REQUEST_COUNTER: OnceLock<Counter<u64>> = OnceLock::new();
182+
183+
let support_request_counter = SUPPORT_REQUEST_COUNTER.get_or_init(|| {
184+
opentelemetry::global::meter("PoolKe")
185+
.u64_counter("support_info_requests")
186+
.with_description("Number of requests to server about what is supported")
187+
.build()
188+
});
189+
179190
match tokio::time::timeout(timeout, async {
180191
ServerInformationRequest {
181192
key: key.into(),
@@ -209,8 +220,32 @@ async fn fetch_support_data(
209220
})
210221
.await
211222
{
212-
Ok(v) => v,
213-
Err(_) => Err(PoolError::Timeout),
223+
Ok(v) => {
224+
support_request_counter.add(
225+
1,
226+
&[
227+
KeyValue::new("uuid", uuid),
228+
KeyValue::new(
229+
"outcome",
230+
match v {
231+
Ok(_) => "success",
232+
Err(_) => "error",
233+
},
234+
),
235+
],
236+
);
237+
v
238+
}
239+
Err(_) => {
240+
support_request_counter.add(
241+
1,
242+
&[
243+
KeyValue::new("uuid", uuid),
244+
KeyValue::new("outcome", "timeout"),
245+
],
246+
);
247+
Err(PoolError::Timeout)
248+
}
214249
}
215250
}
216251

@@ -385,6 +420,7 @@ mod tests {
385420

386421
let (protocols, algorithms) = fetch_support_data(
387422
connection,
423+
"uuid".into(),
388424
"abcd".into(),
389425
&HashSet::from([0, 1]),
390426
Duration::from_secs(1),
@@ -431,6 +467,7 @@ mod tests {
431467

432468
let (protocols, algorithms) = fetch_support_data(
433469
connection,
470+
"uuid".into(),
434471
"abcd".into(),
435472
&HashSet::from([0, 1]),
436473
Duration::from_secs(1),

nts-pool-ke/src/servers/geo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ impl Server for GeographicServer {
553553
_ => {
554554
let data = fetch_support_data(
555555
self.connect(connection_type).await?,
556+
self.uuid().clone(),
556557
self.auth_key(),
557558
&self.config.allowed_protocols,
558559
self.config.timesource_timeout,

nts-pool-ke/src/servers/roundrobin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl Server for RoundRobinServer<'_> {
137137
> {
138138
fetch_support_data(
139139
self.connect(connection_type).await?,
140+
self.uuid().clone(),
140141
self.auth_key(),
141142
&self.owner.allowed_protocols,
142143
self.owner.timeout,

0 commit comments

Comments
 (0)