perf(monitors): a monitor's latest results by a LATERAL probe, not row_number over its history (#5208)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 49s
CI / unit (push) Successful in 1m17s
CI / publish (push) Successful in 1m30s

_last_n_results (Status, the monitors list, host monitors), host_status
(hosts overview, list_hosts) and the report's down-monitor list each
ranked every result a monitor ever recorded to keep the newest few. Each
monitor now gets ORDER BY checked_at DESC LIMIT n in a LATERAL subquery,
which walks ix_monitor_results_monitor_checked backwards and stops.

Also fixes the latest-table test, which read between two begin() blocks
and so autobegan a transaction the second block then refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 23:08:39 -04:00
co-authored by Claude Opus 5.5
parent b8f73270e7
commit 1845ba973c
5 changed files with 77 additions and 50 deletions
+2 -1
View File
@@ -54,7 +54,8 @@ def test_the_newest_sample_wins_and_a_late_backlog_does_not_move_it_back(app):
_sample(host, "cpu_pct", 20.0, now - timedelta(minutes=1)),
_sample(host, "mem_used_pct", 40.0, now - timedelta(minutes=1)),
])
after_first = await _latest(s, host)
async with s.begin():
after_first = await _latest(s, host)
async with s.begin():
# An agent catching up posts older samples after newer ones.
await record_metrics(s, [