feat: jitter_ms tracking — scheduled_at stamped at dispatch, jitter computed on ingest

This commit is contained in:
M1
2026-03-17 10:44:35 +04:00
parent 5c91cbc522
commit f71388a51a
5 changed files with 32 additions and 14 deletions
+4 -2
View File
@@ -44,7 +44,7 @@ pub async fn fetch_and_run(
let token = token.to_string();
let in_flight = in_flight.clone();
tokio::spawn(async move {
let result = run_check(&client, &monitor).await;
let result = run_check(&client, &monitor, monitor.scheduled_at.clone()).await;
// Remove from in-flight before posting so a fast next cycle can pick it up
in_flight.lock().await.remove(&monitor.id);
if let Err(e) = post_result(&client, &coordinator_url, &token, result).await {
@@ -56,7 +56,7 @@ pub async fn fetch_and_run(
Ok(spawned)
}
async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> PingResult {
async fn run_check(client: &reqwest::Client, monitor: &Monitor, scheduled_at: Option<String>) -> PingResult {
let start = Instant::now();
// Check cert expiry for HTTPS URLs
@@ -96,6 +96,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> PingResult {
match result {
Err(e) => PingResult {
monitor_id: monitor.id.clone(),
scheduled_at,
status_code: None,
latency_ms: Some(latency_ms),
up: false,
@@ -142,6 +143,7 @@ async fn run_check(client: &reqwest::Client, monitor: &Monitor) -> PingResult {
PingResult {
monitor_id: monitor.id.clone(),
scheduled_at,
status_code: Some(status),
latency_ms: Some(latency_ms),
up,
+2
View File
@@ -12,11 +12,13 @@ pub struct Monitor {
pub timeout_ms: Option<u64>,
pub interval_s: i64,
pub query: Option<Value>,
pub scheduled_at: Option<String>,
}
#[derive(Debug, Serialize)]
pub struct PingResult {
pub monitor_id: String,
pub scheduled_at: Option<String>,
pub status_code: Option<u16>,
pub latency_ms: Option<u64>,
pub up: bool,