fix(poller): the health panel must not blank the page, and pass the tunables through (v0.23.20-beta)
Two faults reported against v0.23.19, one of which makes the other much worse. **POLLER_CONCURRENCY was never passed into the container.** It is read from the environment by the backend and documented in .env.example, but docker-compose did not forward it, so setting it did nothing at all. The same was true of the job timeout, interval and both retention limits. Every poller tunable shipped in v0.23.17 was inert for anyone running the compose stack — including the one knob the #114 reply told the reporter to reach for. All five are now forwarded. **The health panel crashed on an unexpected payload**, taking the whole page with it: `cap is undefined` from reading data.capacity without a guard. It also rendered "Loading…" indefinitely on a request error, so a failing endpoint and a slow one looked identical. Both are the wrong failure mode for this screen in particular. It is the page an operator opens precisely when monitoring already looks broken, and a blank white panel at that moment is worse than no panel: it suggests the whole tool is dead rather than that one query failed. Every field is now defaulted, so a backend a version behind or one that answered partially degrades the panel instead of destroying the page, and a failed request renders what actually went wrong with a retry. Verified against the four shapes that could produce the reported crash: capacity missing, an error body arriving with a 2xx, an older backend without the status field, and an empty object. The endpoint is hardened to match. Device count, timing and the stale-device listing are each guarded independently, so a partial failure returns partial numbers rather than a 500 — the same reasoning applied at the other end. I could not reproduce the original crash: at concurrency 48 the endpoint returns a complete payload here, there is no route shadowing, and the axios interceptor rejects errors correctly rather than passing them through as data. The defensive work stands on its own regardless of which of those shapes he actually hit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
745a7cda93
commit
dd71271473
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mikrotik-manager-backend",
|
||||
"version": "0.23.19-beta",
|
||||
"version": "0.23.20-beta",
|
||||
"description": "Mikrotik Network Management Platform - Backend API",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -68,7 +68,10 @@ router.get('/poller', async (_req: Request, res: Response) => {
|
||||
|
||||
// Devices the poller has not managed to reach lately, worst first. This is
|
||||
// the list that answers "which ones is it actually missing?".
|
||||
const stale = await query(
|
||||
// Stale-device listing is a nicety; never let it take the whole payload down.
|
||||
let stale: unknown[] = [];
|
||||
try {
|
||||
stale = await query(
|
||||
`SELECT d.id, d.name, d.status, s.kind,
|
||||
s.last_attempt_at, s.last_success_at, s.last_duration_ms, s.last_error,
|
||||
s.attempts, s.failures,
|
||||
@@ -79,7 +82,10 @@ router.get('/poller', async (_req: Request, res: Response) => {
|
||||
AND (s.last_success_at IS NULL OR s.last_success_at < NOW() - INTERVAL '3 minutes')
|
||||
ORDER BY s.last_success_at ASC NULLS FIRST
|
||||
LIMIT 50`
|
||||
);
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('Poller health: stale-device query failed:', (e as Error).message);
|
||||
}
|
||||
|
||||
res.json({ ...health, stale_devices: stale });
|
||||
} catch (error) {
|
||||
|
||||
@@ -721,14 +721,29 @@ export class PollerService {
|
||||
}
|
||||
}
|
||||
|
||||
const [{ count: deviceCount } = { count: 0 }] = await query<{ count: number }>(
|
||||
`SELECT COUNT(*)::int AS count FROM devices WHERE status != 'disabled'`
|
||||
);
|
||||
const [timing] = await query<{ avg_ms: number | null; p90_ms: number | null }>(
|
||||
`SELECT AVG(last_duration_ms)::int AS avg_ms,
|
||||
(PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY last_duration_ms))::int AS p90_ms
|
||||
FROM device_poll_stats WHERE kind = 'fast' AND last_duration_ms IS NOT NULL`
|
||||
);
|
||||
// Each read is independently guarded. This endpoint is what an operator opens
|
||||
// when monitoring already looks broken, so it must degrade to partial numbers
|
||||
// rather than fail whole — a 500 here reads as "the tool is dead too".
|
||||
let deviceCount = 0;
|
||||
try {
|
||||
const [row] = await query<{ count: number }>(
|
||||
`SELECT COUNT(*)::int AS count FROM devices WHERE status != 'disabled'`
|
||||
);
|
||||
deviceCount = row?.count ?? 0;
|
||||
} catch (e) {
|
||||
console.error('[Poller] Health: device count failed:', (e as Error).message);
|
||||
}
|
||||
|
||||
let timing: { avg_ms: number | null; p90_ms: number | null } | undefined;
|
||||
try {
|
||||
[timing] = await query<{ avg_ms: number | null; p90_ms: number | null }>(
|
||||
`SELECT AVG(last_duration_ms)::int AS avg_ms,
|
||||
(PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY last_duration_ms))::int AS p90_ms
|
||||
FROM device_poll_stats WHERE kind = 'fast' AND last_duration_ms IS NOT NULL`
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('[Poller] Health: timing query failed:', (e as Error).message);
|
||||
}
|
||||
|
||||
// Can the workers keep up? Arrival is one fast poll per device per cycle.
|
||||
const avgSec = (timing?.avg_ms || 0) / 1000;
|
||||
|
||||
Reference in New Issue
Block a user