fix: jitter_ms now measured in Rust at check start, excludes latency and return trip

This commit is contained in:
M1
2026-03-17 10:52:08 +04:00
parent e7ec457d0e
commit 27be1fa8bf
4 changed files with 13 additions and 1 deletions
+1
View File
@@ -18,3 +18,4 @@ rustls-native-certs = "0.8"
webpki-roots = "0.26"
x509-parser = "0.16"
tokio-rustls = "0.26"
chrono = { version = "0.4", features = ["serde"] }
+9
View File
@@ -57,6 +57,13 @@ pub async fn fetch_and_run(
}
async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Option<String>) -> PingResult {
// Compute jitter: how late we actually started vs when we were scheduled
let jitter_ms: Option<i64> = scheduled_at.as_deref().and_then(|s| {
let scheduled = chrono::DateTime::parse_from_rfc3339(s).ok()?;
let now = chrono::Utc::now();
Some((now - scheduled.with_timezone(&chrono::Utc)).num_milliseconds())
});
let start = Instant::now();
// Check cert expiry for HTTPS URLs
@@ -97,6 +104,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
Err(e) => PingResult {
monitor_id: monitor.id.clone(),
scheduled_at,
jitter_ms,
status_code: None,
latency_ms: Some(latency_ms),
up: false,
@@ -144,6 +152,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
PingResult {
monitor_id: monitor.id.clone(),
scheduled_at,
jitter_ms,
status_code: Some(status),
latency_ms: Some(latency_ms),
up,
+1
View File
@@ -19,6 +19,7 @@ pub struct Monitor {
pub struct PingResult {
pub monitor_id: String,
pub scheduled_at: Option<String>,
pub jitter_ms: Option<i64>,
pub status_code: Option<u16>,
pub latency_ms: Option<u64>,
pub up: bool,