fix(store): coalesce NULL avg_latency_ms in HourlyBuckets
ci / lint (pull_request) Successful in 5m45s
ci / image (pull_request) Successful in 6m27s
ci / build (pull_request) Successful in 8m32s
ci / test (pull_request) Successful in 11m55s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-22 20:13:46 +01:00
1 parent 9b26b4150e
commit db37060c70
3 files changed
+17 -2

No files matched your search

+15
View File
@@ -263,6 +263,21 @@ func TestStatusPageGroupsAndDetails(t *testing.T) {
} }
webID := newMonitor("web", up.URL, mgChild["id"]) webID := newMonitor("web", up.URL, mgChild["id"])
apiID := newMonitor("api", down.URL, mgRoot["id"]) apiID := newMonitor("api", down.URL, mgRoot["id"])
// Heartbeat monitors record NULL latency_ms; ensure HourlyBuckets handles them
// cleanly when show_component_details is enabled.
st, hbBody := owner.do("POST", "/api/v1/org/monitors", map[string]any{
"name": "nightly-job",
"type": "heartbeat",
"interval_seconds": 3600,
})
if st != http.StatusCreated {
t.Fatalf("create heartbeat monitor = %d %v, want 201", st, hbBody)
}
hbResp, err := e.srv.Client().Post(e.srv.URL+"/hb/"+hbBody["target"].(string), "text/plain", strings.NewReader(""))
if err != nil {
t.Fatalf("ping heartbeat error = %v", err)
}
_ = hbResp.Body.Close()
slug := uniq("nested-") slug := uniq("nested-")
st, pageBody := owner.do("POST", "/api/v1/org/statuspages", map[string]any{ st, pageBody := owner.do("POST", "/api/v1/org/statuspages", map[string]any{
+1 -1
View File
@@ -200,7 +200,7 @@ func (q *Queries) FirstDataRecent(ctx context.Context, arg FirstDataRecentParams
const hourlyBuckets = `-- name: HourlyBuckets :many const hourlyBuckets = `-- name: HourlyBuckets :many
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count, SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
FROM check_results_1h FROM check_results_1h
WHERE org_id = $1 AND bucket >= $2 WHERE org_id = $1 AND bucket >= $2
GROUP BY monitor_id, bucket GROUP BY monitor_id, bucket
+1 -1
View File
@@ -36,7 +36,7 @@ ORDER BY region, time DESC;
-- name: HourlyBuckets :many -- name: HourlyBuckets :many
-- Per monitor and hour since $2, across all regions. -- Per monitor and hour since $2, across all regions.
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count, SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
FROM check_results_1h FROM check_results_1h
WHERE org_id = $1 AND bucket >= $2 WHERE org_id = $1 AND bucket >= $2
GROUP BY monitor_id, bucket GROUP BY monitor_id, bucket