Interval change keeps unreported samples for the reporter (closes #124)
check / check (push) Successful in 2m9s

The interval menu cleared every host's history, and the reporter builds
each report from that history, so the samples recorded since the last
delivered report were never sent. The menu now calls
HostState.clearHistory, which moves the history's entries to
clearedHistory, keeping the last maxHistoryPoints as the history does;
buildReport reads both. The per-host marks are unchanged, so a sample a
delivered report had is not sent again, and the page's history still
starts over. Reporter is exported for the new unit test.

Model: opus-5-5
This commit is contained in:
2026-10-14 09:08:33 +00:00
parent b1eefe0c29
commit c6f325cff5
4 changed files with 90 additions and 10 deletions
+21 -7
View File
@@ -265,6 +265,9 @@ export class HostState {
// error }, or a round skipped while paused, { timestamp,
// latency: null, paused: true }.
this.history = [];
// The entries the history held before the interval menu last
// cleared it, which the reporter may not have sent yet.
this.clearedHistory = [];
this.lastLatency = null;
this.status = "pending"; // 'online' | 'offline' | 'error' | 'pending'
this.pinned = pinned;
@@ -293,6 +296,16 @@ export class HostState {
this._trim();
}
// Starts the history over, as the interval menu does. Its entries move
// to clearedHistory, which keeps the last maxHistoryPoints of them, as
// the history does, so the reporter still sends those it has not.
clearHistory() {
this.clearedHistory = [...this.clearedHistory, ...this.history].slice(
-CONFIG.maxHistoryPoints,
);
this.history = [];
}
// The min, max, median and average latency of the checks in the history
// that got an answer.
historyStats() {
@@ -429,10 +442,11 @@ function getClientId() {
// Build the delta report body the backend decodes, plus the new per-host
// high-water marks. Pure function of the passed state: `hosts` is an array
// of { name, url, status, history }, `since` maps a host url to the Unix-ms
// timestamp of the last sample already reported for it, and `now` is a Date.
// Only non-paused samples newer than the mark are included. Returns null
// when no host has an unreported sample.
// of { name, url, status, clearedHistory, history }, `since` maps a host url
// to the Unix-ms timestamp of the last sample already reported for it, and
// `now` is a Date. Only non-paused samples newer than the mark are included,
// from clearedHistory as well as history. Returns null when no host has an
// unreported sample.
export function buildReport(hosts, clientId, now, since) {
const reportHosts = [];
const marks = new Map();
@@ -440,7 +454,7 @@ export function buildReport(hosts, clientId, now, since) {
const mark = since.get(host.url) ?? 0;
const samples = [];
let high = mark;
for (const p of host.history) {
for (const p of [...host.clearedHistory, ...host.history]) {
if (p.paused) continue;
if (p.timestamp <= mark) continue;
samples.push({
@@ -481,7 +495,7 @@ export function buildReport(hosts, clientId, now, since) {
// Only one report is ever in flight, and it is abandoned after half the
// interval, so a slow POST can neither overlap the next report (which would
// carry the same samples) nor stall reporting for good.
class Reporter {
export class Reporter {
constructor(state, clientId, intervalMs) {
this.state = state;
this.clientId = clientId;
@@ -1502,7 +1516,7 @@ async function init() {
// Clear all host history and reset state
for (const host of state.allHosts) {
host.history = [];
host.clearHistory();
host.lastLatency = null;
host.status = "pending";
}