feat(store): record agent instances and query results by checker

Refs #82

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 12:54:56 +01:00
1 parent db8bdb3a62
commit 53ff2a628d
7 files changed
+289 -2

No files matched your search

+16 -1
View File
@@ -13,7 +13,7 @@ WHERE org_id = $1 AND time > now() - interval '1 day'
ORDER BY monitor_id, region, time DESC;
-- name: RecentResults :many
SELECT time, region, ok, latency_ms, status_code, error
SELECT time, region, ok, latency_ms, status_code, error, checker_id
FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > $3
ORDER BY time DESC
@@ -128,3 +128,18 @@ SELECT monitor_id, region, min(time)::timestamptz AS first
FROM check_results
WHERE org_id = $1 AND time >= $2
GROUP BY 1, 2;
-- name: ResultsByChecker :many
-- The organization's latest results run by one checker instance.
SELECT r.time, r.monitor_id, r.region, r.ok, r.latency_ms, r.status_code, r.error
FROM check_results r
WHERE r.org_id = $1 AND r.checker_id = sqlc.arg(checker_id) AND r.time > now() - interval '1 day'
ORDER BY r.time DESC
LIMIT 50;
-- name: CheckerStats :one
-- How much one instance checked for the organization in the last hour.
SELECT count(*)::bigint AS total, count(*) FILTER (WHERE NOT ok)::bigint AS failed,
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
FROM check_results
WHERE org_id = $1 AND checker_id = sqlc.arg(checker_id) AND time > now() - interval '1 hour';