Skip to content

Commit fc2d275

Browse files
author
Thomas Luijken
committed
Added timeout for probes in general. Next iteration should be after
deducting elapsed time from timeout
1 parent e7d75c3 commit fc2d275

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

oxybox/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "oxybox"
3-
version = "1.0.4"
3+
version = "1.0.5"
44
authors = ["Thomas Luijken"]
55
categories = ["command-line-utilities"]
66
description = "A drop in replacement for blackbox exporter for Prometheus, with support for TLS and HTTP/3."

oxybox/src/http_probe/probe.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ pub async fn run_probe_loop(
233233
loop {
234234
let mut handles = vec![];
235235

236+
let start_time = Instant::now();
237+
236238
for target in &org_config.targets {
237239
let connector = tls_connector.clone();
238240
let resolver = resolver.clone();
@@ -241,7 +243,9 @@ pub async fn run_probe_loop(
241243
let org_id = org_config.organisation_id.clone();
242244
let mimir_endpoint = mimir_endpoint.clone();
243245

244-
handles.push(tokio::spawn(async move {
246+
let probe_timeout_duration: Duration = Duration::from_secs(org_config.polling_interval_seconds);
247+
248+
handles.push(tokio::spawn(tokio::time::timeout(probe_timeout_duration, async move {
245249
handle_target_probe(
246250
tenant_name,
247251
&org_id,
@@ -252,15 +256,17 @@ pub async fn run_probe_loop(
252256
max_org_width,
253257
)
254258
.await;
255-
}));
259+
})));
256260
}
257261

258262
for handle in handles {
259263
if let Err(join_err) = handle.await {
260264
log::error!("Task panicked: {:?}", join_err);
261265
}
262266
}
263-
sleep(Duration::from_secs(org_config.polling_interval_seconds)).await;
267+
let elapsed = start_time.elapsed();
268+
269+
sleep(Duration::from_secs(org_config.polling_interval_seconds - elapsed.as_secs())).await;
264270
}
265271
}
266272

0 commit comments

Comments
 (0)