1 Commits
Author SHA1 Message Date
sneak c30e15c98f Health box and summary update as each WAN check ends (closes #206)
check / check (push) Canceled after 0s
The health box and the summary were drawn only once every check in a
round had ended, so a target that never answers held them back until
its timeout, after the rows already showed the network was back. tick
now redraws both with each WAN host's row. The "Health:" debug log line
moved from updateHealthBox to the end of the round, so it is still
written once per round.

Model: opus-5-5
2026-11-11 20:29:23 +00:00
3 changed files with 23 additions and 106 deletions

No files matched your search

+7 -7
View File
@@ -116,19 +116,19 @@ half second. As soon as one answers, a new round starts.
### Rows, colors and controls ### Rows, colors and controls
A figure and its line in the graph take the color of the legend in the footer, A figure and its line in the graph take the color of the legend in the footer,
from green under 50 ms to red from 500 ms up; gray is no answer. The dot beside from green under 50 ms to red from 500 ms up; gray is no answer. The graph's
the host's name takes the same color. The graph's axis ends at 1000 ms; a higher axis ends at 1000 ms; a higher latency is drawn at the top, and the figure still
latency is drawn at the top, and the figure still shows its real value. shows its real value.
From time to time, the page sorts the WAN rows by their latest latency: fastest From time to time, the page sorts the WAN rows by their latest latency: fastest
first, failed last. The pin button at the left of a row keeps the row at the first, failed last. The pin button at the left of a row keeps the row at the
top; pinned rows are sorted by name. `datavi.be` is pinned at start. top; pinned rows are sorted by name. `datavi.be` is pinned at start.
`Pause` stops the checks: the graphs keep scrolling with a gap for each paused `Pause` stops the checks: the graphs keep scrolling with a gap for each paused
round, and the figures and dots turn gray. The `Interval` menu sets the time round, and the figures turn gray. The `Interval` menu sets the time between
between rounds: 1, 2, 3, 5, 10, 15, 30 or 60 seconds. Changing it clears the rounds: 1, 2, 3, 5, 10, 15, 30 or 60 seconds. Changing it clears the history and
history and starts a new round at once. The `Debug log` checkbox in the footer starts a new round at once. The `Debug log` checkbox in the footer opens a panel
opens a panel with the page's last 1000 log lines. with the page's last 1000 log lines.
## Reporting ## Reporting
+3 -84
View File
@@ -28,8 +28,8 @@ import {
// a host's row that tick or greyOutUI draws into is a plain object, made // a host's row that tick or greyOutUI draws into is a plain object, made
// the first time a test looks it up and kept in elements under its // the first time a test looks it up and kept in elements under its
// selector until the next test starts. As on a page, writing its text // selector until the next test starts. As on a page, writing its text
// replaces its markup; setting a style keeps it in the element's style // replaces its markup; the status dot greyOutUI looks for in it is not
// object. Drawing a sparkline does nothing; it looks for the pixel ratio on // there. Drawing a sparkline does nothing; it looks for the pixel ratio on
// window and finds none. The commit the page's footer names, which // window and finds none. The commit the page's footer names, which
// vite.config.js fills in when it builds the page, is blank. In each test, // vite.config.js fills in when it builds the page, is blank. In each test,
// console.error and console.info print nothing and keep what they are // console.error and console.info print nothing and keep what they are
@@ -63,7 +63,7 @@ globalThis.document = {
querySelector: (selector) => querySelector: (selector) =>
(elements[selector] ??= { (elements[selector] ??= {
getContext: () => canvasContext, getContext: () => canvasContext,
style: {}, querySelector: () => null,
set textContent(text) { set textContent(text) {
this.innerHTML = text; this.innerHTML = text;
}, },
@@ -83,12 +83,6 @@ function statusText(state, host) {
return elements[`.status-text[data-host="${index}"]`]?.innerHTML; return elements[`.status-text[data-host="${index}"]`]?.innerHTML;
} }
// The color last given to the dot beside host's name.
function statusDot(state, host) {
const index = state.allHosts.indexOf(host);
return elements[`.status-dot[data-host="${index}"]`]?.style.backgroundColor;
}
// What this test wrote to the browser console with console[method]. // What this test wrote to the browser console with console[method].
function consoleLines(method) { function consoleLines(method) {
return console[method].mock.calls.map((call) => call.arguments[0]); return console[method].mock.calls.map((call) => call.arguments[0]);
@@ -689,37 +683,6 @@ test("a check that timed out or found its target unreachable has a grey figure a
assert.equal(latencyHex(null), "#6b7280"); assert.equal(latencyHex(null), "#6b7280");
}); });
test("a check that answers after 488ms turns the dot beside its target's name orange", async (t) => {
const { state, target } = stateWithOneTarget();
mockTargets(t, () => 488);
const round = tick(state, new AbortController().signal);
t.mock.timers.tick(488);
assert.notEqual(await settled(round), "still waiting");
assert.equal(statusDot(state, target), "#f97316");
});
test("a check that fails after one that answered turns the dot beside its target's name gray", async (t) => {
const { state, target } = stateWithOneTarget();
target.pushSample(Date.now(), { latency: 8, error: null });
mockTargets(t, () => 23, target.url);
const round = tick(state, new AbortController().signal);
t.mock.timers.tick(23);
assert.notEqual(await settled(round), "still waiting");
assert.equal(statusDot(state, target), "#6b7280");
});
test("pausing turns the dot beside a target's name gray", async (t) => {
const { state, target } = stateWithOneTarget();
mockTargets(t, () => 8);
const round = tick(state, new AbortController().signal);
t.mock.timers.tick(8);
assert.notEqual(await settled(round), "still waiting");
assert.equal(statusDot(state, target), "#22c55e");
state.paused = true;
greyOutUI(state);
assert.equal(statusDot(state, target), "#6b7280");
});
// buildUI draws the page into #app, here a plain object. Each entry in the // buildUI draws the page into #app, here a plain object. Each entry in the
// footer's color legend is a colored dot and the latencies it stands for, // footer's color legend is a colored dot and the latencies it stands for,
// with < and > written as &lt; and &gt;. A latency takes the color of the // with < and > written as &lt; and &gt;. A latency takes the color of the
@@ -906,50 +869,6 @@ test("at a 30000ms interval, the summary and the health box take in each WAN tar
assert.equal(elements["#summary-checks"].textContent, 3); assert.equal(elements["#summary-checks"].textContent, 3);
}); });
// The user pauses during the first recorded round after the page loads.
// Every WAN target's check ends during the pause. Silent never answers, and
// the user resumes before its check times out. Every element the page looks
// up by id is a plain object, except the debug log's panel, which is not
// there.
test(`at a 30000ms interval, after the user pauses and resumes during a round that records no WAN target's check, the debug log has no "Health:" line`, async (t) => {
CONFIG.updateInterval = 30000;
t.mock.method(globalThis.document, "getElementById", (id) =>
id === "debug-panel" ? null : (elements[`#${id}`] ??= {}),
);
t.mock.method(log, "notice");
t.mock.method(log, "warning");
const state = new AppState([
{ name: "Silent", url: "https://silent.test" },
]);
const silent = state.local[0];
mockTargets(t, (url) => (url === silent.url ? Infinity : 10));
// The second tick: the first that is recorded.
state.tickCount = 1;
const round = tick(state, new AbortController().signal);
// The user pauses, which greys out the summary and the health box, as
// togglePause does.
state.paused = true;
greyOutUI(state);
t.mock.timers.tick(10);
assert.equal(await settled(round), "still waiting");
// The user resumes, which leaves the page as it is.
state.paused = false;
t.mock.timers.tick(CONFIG.requestTimeout - 10);
assert.notEqual(await settled(round), "still waiting");
assert.equal(state.tickCount, 2);
const lines = [...log.notice.mock.calls, ...log.warning.mock.calls].map(
(call) => call.arguments[0],
);
assert.deepEqual(
lines.filter((line) => line.startsWith("Health:")),
[],
);
assert.equal(elements["#health-text"].textContent, "---");
assert.equal(elements["#summary-reachable"].textContent, "--/--");
});
// In the next two tests each of the header's clocks is a plain object, made // In the next two tests each of the header's clocks is a plain object, made
// the first time updateClocks looks it up and kept in elements under "#" and // the first time updateClocks looks it up and kept in elements under "#" and
// its id. // its id.
+13 -15
View File
@@ -30,8 +30,8 @@ export const CONFIG = {
return [0, 1, 2, 3, 4, 5].map((i) => Math.round((d * i) / 5)); return [0, 1, 2, 3, 4, 5].map((i) => Math.round((d * i) / 5));
}, },
canvasHeight: 96, canvasHeight: 96,
// A latency figure, its row's dot and its sparkline take the color of // A latency figure and its sparkline take the color of the first entry
// the first entry whose limit, in ms, the latency is below. // whose limit, in ms, the latency is below.
latencyColors: [ latencyColors: [
{ below: 50, hex: "#22c55e", className: "text-green-500" }, { below: 50, hex: "#22c55e", className: "text-green-500" },
{ below: 100, hex: "#84cc16", className: "text-lime-500" }, { below: 100, hex: "#84cc16", className: "text-lime-500" },
@@ -819,7 +819,7 @@ export function hostRowHTML(host, index, showPin = true) {
${pinBtn} ${pinBtn}
<div class="w-[420px] flex-shrink-0 grid grid-cols-[minmax(0,1fr)_auto] items-center"> <div class="w-[420px] flex-shrink-0 grid grid-cols-[minmax(0,1fr)_auto] items-center">
<div class="flex items-center gap-2 min-w-[200px]"> <div class="flex items-center gap-2 min-w-[200px]">
<div class="status-dot w-3 h-3 rounded-full flex-shrink-0 bg-[#6b7280]" data-host="${index}"></div> <div class="w-3 h-3 rounded-full flex-shrink-0 bg-[#6b7280]"></div>
<span class="font-medium text-white truncate">${escapeHTML(host.name)}</span> <span class="font-medium text-white truncate">${escapeHTML(host.name)}</span>
</div> </div>
<div class="latency-value text-4xl font-bold tabular-nums text-right mt-3" data-host="${index}"> <div class="latency-value text-4xl font-bold tabular-nums text-right mt-3" data-host="${index}">
@@ -982,10 +982,8 @@ function updateHostRow(host, index) {
const canvas = document.querySelector( const canvas = document.querySelector(
`.sparkline-canvas[data-host="${index}"]`, `.sparkline-canvas[data-host="${index}"]`,
); );
const dot = document.querySelector(`.status-dot[data-host="${index}"]`); if (!latencyEl || !statusEl || !canvas) return;
if (!latencyEl || !statusEl || !canvas || !dot) return;
dot.style.backgroundColor = latencyHex(host.lastLatency);
if (host.lastLatency !== null) { if (host.lastLatency !== null) {
const cls = latencyClass(host.lastLatency, host.status); const cls = latencyClass(host.lastLatency, host.status);
latencyEl.innerHTML = `<span class="${cls}">${host.lastLatency}<span class="text-lg">ms</span></span>`; latencyEl.innerHTML = `<span class="${cls}">${host.lastLatency}<span class="text-lg">ms</span></span>`;
@@ -1349,13 +1347,9 @@ export async function tick(state, signal, onOffline) {
updateSummary(state); updateSummary(state);
updateHealthBox(state); updateHealthBox(state);
// Like the health box, the log gives no health until a WAN host's check const health = state.healthStatus();
// is recorded: a pause may have discarded every WAN check so far. if (health === "healthy") log.notice("Health: HEALTHY");
if (state.wan.some((h) => h.status !== "pending")) { else log.warning(`Health: ${health.toUpperCase()}`);
const health = state.healthStatus();
if (health === "healthy") log.notice("Health: HEALTHY");
else log.warning(`Health: ${health.toUpperCase()}`);
}
const reachable = state.allHosts.filter( const reachable = state.allHosts.filter(
(h) => h.status === "online", (h) => h.status === "online",
@@ -1432,8 +1426,12 @@ export function greyOutUI(state) {
statusEl.textContent = "paused"; statusEl.textContent = "paused";
statusEl.className = `${STATUS_TEXT_CLASS} text-gray-500`; statusEl.className = `${STATUS_TEXT_CLASS} text-gray-500`;
} }
const dot = document.querySelector(`.status-dot[data-host="${i}"]`); // Grey out the status dot
if (dot) dot.style.backgroundColor = latencyHex(null); const row = document.querySelector(`.host-row[data-index="${i}"]`);
if (row) {
const dot = row.querySelector(".rounded-full");
if (dot) dot.style.backgroundColor = "#6b7280";
}
}); });
// Grey out summary current stats // Grey out summary current stats