fix: use monitor-side checked_at timestamp instead of coordinator arrival time

This commit is contained in:
2026-03-18 18:50:16 +04:00
parent 425bfbfc39
commit 42024a9fc3
3 changed files with 11 additions and 1 deletions
+6
View File
@@ -100,6 +100,7 @@ pub async fn fetch_and_run(
Ok(r) => r,
Err(_) => PingResult {
monitor_id: monitor.id.clone(),
checked_at: Some(chrono::Utc::now().to_rfc3339()),
scheduled_at: scheduled_at_iso.clone(),
jitter_ms: None,
status_code: None,
@@ -125,6 +126,9 @@ pub async fn fetch_and_run(
}
async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Option<String>, region: &str, run_id: &str) -> PingResult {
// Record when the check actually started (used as checked_at in the ping)
let checked_at = chrono::Utc::now().to_rfc3339();
// 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()?;
@@ -175,6 +179,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
debug!("{} check error: {e}", monitor.url);
PingResult {
monitor_id: monitor.id.clone(),
checked_at: Some(checked_at.clone()),
scheduled_at,
jitter_ms,
status_code: None,
@@ -236,6 +241,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Op
PingResult {
monitor_id: monitor.id.clone(),
checked_at: Some(checked_at),
scheduled_at,
jitter_ms,
status_code: Some(status),
+1
View File
@@ -33,6 +33,7 @@ pub struct Monitor {
#[derive(Debug, Serialize)]
pub struct PingResult {
pub monitor_id: String,
pub checked_at: Option<String>,
pub scheduled_at: Option<String>,
pub jitter_ms: Option<i64>,
pub status_code: Option<u16>,