fix: allow null status_code in ingest schema; check HTTP status in post_result

This commit is contained in:
M1 2026-03-18 13:28:42 +04:00
parent 5037222846
commit 6e1d642c77
2 changed files with 9 additions and 3 deletions

View File

@ -97,8 +97,8 @@ export const ingest = new Elysia()
monitor_id: t.String(),
scheduled_at: t.Optional(t.Nullable(t.String())),
jitter_ms: t.Optional(t.Nullable(t.Number())),
status_code: t.Optional(t.Number()),
latency_ms: t.Optional(t.Number()),
status_code: t.Optional(t.Nullable(t.Number())),
latency_ms: t.Optional(t.Nullable(t.Number())),
up: t.Boolean(),
error: t.Optional(t.Nullable(t.String())),
cert_expiry_days: t.Optional(t.Nullable(t.Number())),

View File

@ -342,7 +342,7 @@ async fn post_result(
token: &str,
result: PingResult,
) -> Result<()> {
tokio::time::timeout(
let resp = tokio::time::timeout(
std::time::Duration::from_secs(10),
client
.post(format!("{coordinator_url}/internal/ingest"))
@ -352,5 +352,11 @@ async fn post_result(
).await
.map_err(|_| anyhow::anyhow!("post_result timed out"))?
.map_err(|e| anyhow::anyhow!("{e}"))?;
if !resp.status().is_success() {
let status = resp.status();
let body = resp.text().await.unwrap_or_default();
return Err(anyhow::anyhow!("ingest returned {status}: {body}"));
}
Ok(())
}