Cache the watchdog payload, and stop reading trailing comments as conf values

The tab collected over SSH on every 30s poll — 8.3s a load with HOST2 down.
vv_parse_conf_scalar() captured to end of line, so a commented toggle parsed as
"true   # HOST2 back online": every threshold read right because (int) stops at
the first non-digit, and 38 booleans read wrong. The Fallback tab has been
showing failover disabled while it was on.
This commit is contained in:
Gmer4Lfe
2026-08-14 10:45:17 -04:00
parent 8808cbfc04
commit 1f4b751fbb
5 changed files with 100 additions and 10 deletions
+29 -3
View File
@@ -33,15 +33,41 @@
// Remote collection degrades per node — one unreachable partner drops that node's card and
// leaves the local host and every other partner intact.
//
// Served from cache, collected only on a miss.
// vv_wd_all() SSHes to every configured partner, so its cost is set by the slowest node
// rather than by how much data there is. Measured at 8.3s on this host with HOST2 down —
// paid by every visitor, every 30 seconds, because the tab polls. The cache check happens
// before the heavy include, so a hit costs one file read and no SSH at all.
//
// The window is deliberately wider than the poll. Watchdog state only changes when the
// orchestrator runs, which is every 15 minutes; polling it every 30 seconds was never
// reading anything new, it was just re-paying for the same answer.
//
// REQUEST
// GET, no parameters
// GET served from the 300s cache when one is present
// GET ?live bypass the cache and collect everything fresh
//
// RESPONSE
// vv_wd_all() verbatim — per-node watchdog state plus the resolved threshold set
//
// DEPENDS ON
// include/watchdog.php vv_wd_all()
// include/config.php vv_cache_read()
// include/watchdog.php vv_wd_all() — required only on a miss
// Tools/api_cache_writer.php writes the cache this endpoint normally serves
// ═══════════════════════════════════════════════════════════════════════════════════════════════
header('Content-Type: application/json');
require_once dirname(__DIR__) . '/include/config.php';
if (!isset($_GET['live'])) {
$_vv_cached = vv_cache_read('watchdog', 300);
if ($_vv_cached !== null) { echo json_encode($_vv_cached); exit; }
unset($_vv_cached);
}
require_once dirname(__DIR__) . '/include/watchdog.php';
echo json_encode(vv_wd_all());
$_vv_wd = vv_wd_all();
// Written on the miss as well as by the background writer. Without this the first visitor after
// a restart pays the full collection and so does the next one, until the writer's next minute
// happens to land.
vv_cache_write('watchdog', $_vv_wd);
echo json_encode($_vv_wd);