Document Scheduler Health fields and boundaries in in-app API Help

Expand the Scheduler Health section in docs/API.md and its shipped
frontend-modern/public/docs/API.md mirror so operators clicking through
from GET /api/state/summary in in-app Help can read updatedAt, enabled,
queue counts and oldestOverdueSeconds, pollStatus partial-read errors,
breaker retryAt, dead-letter recovery clearing, deleted availability
check retirement and the scope boundary separating scheduled polling
from agent reports, WebSocket delivery and alert evaluation. Note
deleted availability-check retirement in docs/api/SCHEDULER_HEALTH.md
and verify fields, routes and shipped Help links against live Go structs.

Refs: #5089
Contract-Neutral: Documents existing GET /api/monitoring/scheduler/health fields, retirement behaviour and read-only diagnostic boundaries with no runtime, API, collection or release changes.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-11-26 18:52:31 +00:00
parent 40e8847bad
commit f75afe3953
4 changed files with 262 additions and 4 deletions
+52 -2
View File
@@ -1504,8 +1504,58 @@ Writes the SSH config used for temperature collection. Requires admin + `setting
Tests SSH connectivity for temperature collection. Requires admin + `settings:write`. Setup tokens are not accepted.
### Scheduler Health
`GET /api/monitoring/scheduler/health`
Returns scheduler health, DLQ, and breaker status. Requires authentication (session or API token); no specific scope is enforced.
`GET /api/monitoring/scheduler/health` (also accepts `HEAD`)
Returns a read-only snapshot of scheduled polling for the active workspace,
including queue backlog, circuit breakers, dead-letter tasks and per-connection
poll outcomes. Requires authentication (a signed-in browser session or an API
token). No specific scope is enforced. For automated requests, send the token
from a private header file as in [Authentication](#-authentication), never in a
command line or URL, and keep the saved JSON private because it contains
infrastructure names, addresses and error messages.
Key fields to compare across two snapshots separated by the connection's normal
poll interval:
- **`updatedAt` and `enabled`**: `updatedAt` is when the snapshot was captured,
not when a poll last succeeded. `enabled: false` means adaptive timing is off.
Configured connections still poll at fixed intervals, and their queue and
outcomes still appear here. Neither `enabled` nor `queue.depth` is a health
verdict.
- **`queue`**: `depth` and `perType` count tasks currently waiting in the active
queue. `dueWithinSeconds` is a **task count** (tasks due now or within 12
seconds), not a duration. `oldestOverdueSeconds` is how many seconds past its
scheduled time the oldest timestamped queued poll was at capture. Zero means
no queued task was past its scheduled time, and older builds omit the field.
It excludes future retries, claimed work already held by a worker and
dead-letter entries. Deleting a saved availability check removes its queued
poll when Pulse reads the updated catalogue without disturbing other
providers, while a catalogue read failure leaves queued work unchanged.
- **`instances[].pollStatus`**: Compare `lastSuccess`, `lastError` (`at`,
`category`, `message`) and `consecutiveFailures` for the same connection
`key`. A complete success clears `lastError`. A `partial` read can advance
`lastSuccess` while leaving `lastError` with `category: "partial"` and
`consecutiveFailures: 0`, meaning Pulse reached the target but some readings
were unavailable. Having no error rows does not prove polling ran.
- **`instances[].breaker` and `breakers`**: `state` is `closed`, `open` or
`half_open`, and `retryAt` is the earliest time the breaker will allow the
next probe. Passing `retryAt` does not prove a poll ran, and the state can
stay `open` until scheduled work reaches it. Top-level `breakers` lists only
breakers outside the default `closed`/zero-failure state.
- **`instances[].deadLetter` and `deadLetter`**: `deadLetter.count` and up to
25 `tasks` summarise terminal poll entries. Each instance entry exposes
`present`, `reason` and `nextRetry`. `nextRetry` does not schedule a poll. A
later successful scheduled poll clears the dead-letter entry on current
builds, though older builds may retain it after recovery.
This endpoint covers scheduled polling only. Zero overdue queued tasks or
advancing `lastSuccess` does not prove that a poll claimed by a worker finished,
that host or Docker agent reports arrived, that WebSocket state reached the
browser or that alert rules ran. Check those paths separately with
[System Health](#system-health), [missing-data checks](FAQ.md#no-data-showing)
and [outage detection](ALERTING.md#detect-an-outage-of-pulse-itself). Do not
reset breakers, toggle adaptive polling or restart Pulse just to gather a
reading.
### Updates (Admin)
- `GET /api/updates/check`
+3
View File
@@ -104,6 +104,9 @@ The scheduler's record of each connection's recent poll results.
most overdue timestamped poll still in the queue was at capture. Zero
means none was past its scheduled time. It does not count future work
(including a future scheduled retry), claimed work or dead-letter entries.
Deleting a saved availability check retires its queued poll on catalogue
refresh without disturbing unrelated providers, while a failed catalogue
read leaves existing scheduled work unchanged.
* **`deadLetter`**: Aggregate DLQ summary plus up to 25 queued tasks.
### Optional Summaries
+52 -2
View File
@@ -1504,8 +1504,58 @@ Writes the SSH config used for temperature collection. Requires admin + `setting
Tests SSH connectivity for temperature collection. Requires admin + `settings:write`. Setup tokens are not accepted.
### Scheduler Health
`GET /api/monitoring/scheduler/health`
Returns scheduler health, DLQ, and breaker status. Requires authentication (session or API token); no specific scope is enforced.
`GET /api/monitoring/scheduler/health` (also accepts `HEAD`)
Returns a read-only snapshot of scheduled polling for the active workspace,
including queue backlog, circuit breakers, dead-letter tasks and per-connection
poll outcomes. Requires authentication (a signed-in browser session or an API
token). No specific scope is enforced. For automated requests, send the token
from a private header file as in [Authentication](#-authentication), never in a
command line or URL, and keep the saved JSON private because it contains
infrastructure names, addresses and error messages.
Key fields to compare across two snapshots separated by the connection's normal
poll interval:
- **`updatedAt` and `enabled`**: `updatedAt` is when the snapshot was captured,
not when a poll last succeeded. `enabled: false` means adaptive timing is off.
Configured connections still poll at fixed intervals, and their queue and
outcomes still appear here. Neither `enabled` nor `queue.depth` is a health
verdict.
- **`queue`**: `depth` and `perType` count tasks currently waiting in the active
queue. `dueWithinSeconds` is a **task count** (tasks due now or within 12
seconds), not a duration. `oldestOverdueSeconds` is how many seconds past its
scheduled time the oldest timestamped queued poll was at capture. Zero means
no queued task was past its scheduled time, and older builds omit the field.
It excludes future retries, claimed work already held by a worker and
dead-letter entries. Deleting a saved availability check removes its queued
poll when Pulse reads the updated catalogue without disturbing other
providers, while a catalogue read failure leaves queued work unchanged.
- **`instances[].pollStatus`**: Compare `lastSuccess`, `lastError` (`at`,
`category`, `message`) and `consecutiveFailures` for the same connection
`key`. A complete success clears `lastError`. A `partial` read can advance
`lastSuccess` while leaving `lastError` with `category: "partial"` and
`consecutiveFailures: 0`, meaning Pulse reached the target but some readings
were unavailable. Having no error rows does not prove polling ran.
- **`instances[].breaker` and `breakers`**: `state` is `closed`, `open` or
`half_open`, and `retryAt` is the earliest time the breaker will allow the
next probe. Passing `retryAt` does not prove a poll ran, and the state can
stay `open` until scheduled work reaches it. Top-level `breakers` lists only
breakers outside the default `closed`/zero-failure state.
- **`instances[].deadLetter` and `deadLetter`**: `deadLetter.count` and up to
25 `tasks` summarise terminal poll entries. Each instance entry exposes
`present`, `reason` and `nextRetry`. `nextRetry` does not schedule a poll. A
later successful scheduled poll clears the dead-letter entry on current
builds, though older builds may retain it after recovery.
This endpoint covers scheduled polling only. Zero overdue queued tasks or
advancing `lastSuccess` does not prove that a poll claimed by a worker finished,
that host or Docker agent reports arrived, that WebSocket state reached the
browser or that alert rules ran. Check those paths separately with
[System Health](#system-health), [missing-data checks](FAQ.md#no-data-showing)
and [outage detection](ALERTING.md#detect-an-outage-of-pulse-itself). Do not
reset breakers, toggle adaptive polling or restart Pulse just to gather a
reading.
### Updates (Admin)
- `GET /api/updates/check`
@@ -0,0 +1,155 @@
#!/usr/bin/env python3
"""Verify shipped Scheduler Health API Help matches live runtime structs and routes.
Binds the in-app API.md Scheduler Health section and docs/api/SCHEDULER_HEALTH.md
to the live Go response structs, route registration, and shipped Help headings.
"""
from __future__ import annotations
from pathlib import Path
import re
import unittest
ROOT = Path(__file__).resolve().parents[2]
API_DOC = ROOT / "docs/API.md"
SHIPPED_API_DOC = ROOT / "frontend-modern/public/docs/API.md"
SCHEDULER_DOC = ROOT / "docs/api/SCHEDULER_HEALTH.md"
def scheduler_section() -> str:
text = API_DOC.read_text(encoding="utf-8")
marker = "### Scheduler Health\n"
if marker not in text:
raise AssertionError("missing Scheduler Health section in docs/API.md")
after = text.split(marker, 1)[1]
return after.split("\n### ", 1)[0]
def heading_slug(title: str) -> str:
slug = title.strip().lower()
slug = re.sub(r"[^\w\s-]", "", slug)
return re.sub(r"\s+", "-", slug).strip("-")
class SchedulerHealthAPIHelpDocsTest(unittest.TestCase):
def test_shipped_api_copy_matches_source(self) -> None:
self.assertEqual(API_DOC.read_bytes(), SHIPPED_API_DOC.read_bytes())
def test_route_methods_and_auth_match_server_registration(self) -> None:
section = " ".join(scheduler_section().split())
routes = (ROOT / "internal/api/router_routes_monitoring.go").read_text(
encoding="utf-8"
)
router = (ROOT / "internal/api/router.go").read_text(encoding="utf-8")
self.assertIn(
'r.mux.HandleFunc("/api/monitoring/scheduler/health", RequireAuth(r.config, r.handleSchedulerHealth))',
routes,
)
self.assertIn(
"req.Method != http.MethodGet && req.Method != http.MethodHead",
router.split("func (r *Router) handleSchedulerHealth", 1)[1][:400],
)
self.assertIn("`GET /api/monitoring/scheduler/health` (also accepts `HEAD`)", section)
self.assertIn("No specific scope is enforced.", section)
def test_documented_fields_match_go_response_structs(self) -> None:
section = " ".join(scheduler_section().split())
monitor = (ROOT / "internal/monitoring/monitor.go").read_text(encoding="utf-8")
task_queue = (ROOT / "internal/monitoring/task_queue.go").read_text(
encoding="utf-8"
)
for field, source in (
("updatedAt", monitor),
("enabled", monitor),
("queue", monitor),
("depth", task_queue),
("dueWithinSeconds", task_queue),
("perType", task_queue),
("oldestOverdueSeconds", task_queue),
("deadLetter", monitor),
("count", monitor),
("tasks", monitor),
("breakers", monitor),
("instances", monitor),
("key", monitor),
("pollStatus", monitor),
("lastSuccess", monitor),
("lastError", monitor),
("at", monitor),
("category", monitor),
("message", monitor),
("consecutiveFailures", monitor),
("breaker", monitor),
("state", monitor),
("retryAt", monitor),
("present", monitor),
("reason", monitor),
("nextRetry", monitor),
):
with self.subTest(field=field):
self.assertIn(field, section)
self.assertRegex(source, rf'json:"{re.escape(field)}(?:,omitempty)?"')
def test_runtime_boundaries_and_retirement_notes_present(self) -> None:
section = " ".join(scheduler_section().split())
sched_doc = " ".join(SCHEDULER_DOC.read_text(encoding="utf-8").split())
availability_poller = (
ROOT / "internal/monitoring/availability_poller.go"
).read_text(encoding="utf-8")
self.assertIn("RefreshAvailabilityTargets", availability_poller)
for boundary in (
"`dueWithinSeconds` is a **task count**",
"not a duration",
"excludes future retries, claimed work already held by a worker and dead-letter entries",
"Deleting a saved availability check removes its queued poll",
"catalogue read failure leaves queued work unchanged",
"`category: \"partial\"` and `consecutiveFailures: 0`",
"Having no error rows does not prove polling ran.",
"Passing `retryAt` does not prove a poll ran",
"`nextRetry` does not schedule a poll.",
"This endpoint covers scheduled polling only.",
"that host or Docker agent reports arrived",
"that alert rules ran.",
"never in a command line or URL",
):
with self.subTest(boundary=boundary):
self.assertIn(boundary, section)
self.assertIn(
"Deleting a saved availability check retires its queued poll",
sched_doc,
)
self.assertIn(
"failed catalogue read leaves existing scheduled work unchanged",
sched_doc,
)
def test_in_app_links_target_real_shipped_docs_and_headings(self) -> None:
section = scheduler_section()
links = re.findall(r"\[[^\]]+\]\(([^)]+)\)", section)
self.assertGreaterEqual(len(links), 4)
for target in links:
self.assertFalse(target.startswith("http"), target)
if target.startswith("#"):
doc_path = SHIPPED_API_DOC
fragment = target[1:]
else:
file_part, _, fragment = target.partition("#")
doc_path = ROOT / "frontend-modern/public/docs" / file_part
self.assertTrue(doc_path.is_file(), f"missing shipped doc for link {target}")
if fragment and not fragment.startswith("-"):
headings = re.findall(
r"^#{1,6}\s+(.+)$", doc_path.read_text(encoding="utf-8"), re.M
)
slugs = {heading_slug(h) for h in headings}
self.assertIn(fragment, slugs, f"missing heading #{fragment} in {doc_path.name}")
if __name__ == "__main__":
unittest.main()