diff --git a/docs/ALERTING.md b/docs/ALERTING.md index dcc2354ef6..0cc8fac98d 100644 --- a/docs/ALERTING.md +++ b/docs/ALERTING.md @@ -131,13 +131,25 @@ sends it based on recent activity in the monitoring loop, not on whether polls finished, agent reports were accepted or alert rules ran. A `200` from `/api/health` only means the web server answered. -If readings look frozen while the monitored systems still respond, compare the -newest sample times in **History** and the reporting agents' **Seen** times in -**Machines**. Allow for normal poll and report intervals, including retry delays. -If you already scrape Prometheus, compare `pulse_monitor_poll_total` by -`result`. Rising errors mean Pulse is still recording poll outcomes. If -several expected sources give no new results, check whether collection has -stopped. [Check real alert delivery separately](#choose-where-notifications-go). +If readings look frozen while the monitored systems still respond, check each +collection path separately, allowing for normal poll and report intervals and +retry delays: + +- **Polled platforms:** Check the newest stored sample times in + [History](METRICS_HISTORY.md#read-a-history-panel) and the live readings on + each expected connection. **Latest from device** and **Latest recorded** can + include points the device kept during a Pulse outage, so a new chart point + alone does not prove Pulse polled again. +- **Agents:** Check **Last seen** (shown as **Seen** on narrow screens) and + the readings you need in **Machines**. Check **Docker** hosts separately: + container reports use their own stream and can stall even while machine + reports keep arriving from the same agent. +- **Prometheus scrapes (if already enabled):** Compare + `pulse_monitor_poll_total` by `result`. Rising errors mean Pulse is still + recording poll outcomes. If several expected sources give no new results, + check whether collection has stopped. + +[Check real alert delivery separately](#choose-where-notifications-go). ### Warn when expected polls stop succeeding @@ -188,7 +200,27 @@ or intentionally pause the target. A poll warning means Pulse has not recorded a fresh success for that connection. An increasing `pulse_monitor_poll_total` series with -`result="error"` means polls are still returning failures. No new results -despite working scrapes does not tell you whether the poll is slow or stuck. -Use the [missing-data checks](FAQ.md#no-data-showing) to narrow it down. -Neither alert checks whether agents reported or Pulse evaluated its rules. +`result="error"` means polls are still returning failures. + +If scrapes keep succeeding with no new poll outcomes, check the scheduler and +agent series already on that scrape target (an absent series on an older build +is not zero): + +- **Backoff still active:** `pulse_scheduler_breaker_retry_seconds` for the + same connection shows time left until the recorded retry deadline. Zero + means the deadline has passed or none was recorded, not that a poll ran. +- **Poll waiting in queue or on a worker:** compare + `pulse_scheduler_queued_poll_overdue_seconds` and + `pulse_scheduler_claimed_poll_overdue_seconds` (`stage="waiting_for_slot"` + and `stage="running"`) across fresh scrapes. Growing ages show queued or + claimed polls falling behind their schedule or timeout budget. Zero does + not prove polling recovered. +- **Agent reports:** inspect `pulse_http_requests_total` with `method="POST"` + separately for `/api/agents/agent/report` (or legacy + `/api/agents/host/report`) and `/api/agents/docker/report`, split by + `status`. Do not add the routes together: machine reports can keep + succeeding while Docker reports stop. + +Use the [missing-data checks](FAQ.md#no-data-showing) to narrow it down +without restarting Pulse or sending test traffic. Neither alert above checks +whether Pulse evaluated its alert rules. diff --git a/frontend-modern/public/docs/ALERTING.md b/frontend-modern/public/docs/ALERTING.md index dcc2354ef6..0cc8fac98d 100644 --- a/frontend-modern/public/docs/ALERTING.md +++ b/frontend-modern/public/docs/ALERTING.md @@ -131,13 +131,25 @@ sends it based on recent activity in the monitoring loop, not on whether polls finished, agent reports were accepted or alert rules ran. A `200` from `/api/health` only means the web server answered. -If readings look frozen while the monitored systems still respond, compare the -newest sample times in **History** and the reporting agents' **Seen** times in -**Machines**. Allow for normal poll and report intervals, including retry delays. -If you already scrape Prometheus, compare `pulse_monitor_poll_total` by -`result`. Rising errors mean Pulse is still recording poll outcomes. If -several expected sources give no new results, check whether collection has -stopped. [Check real alert delivery separately](#choose-where-notifications-go). +If readings look frozen while the monitored systems still respond, check each +collection path separately, allowing for normal poll and report intervals and +retry delays: + +- **Polled platforms:** Check the newest stored sample times in + [History](METRICS_HISTORY.md#read-a-history-panel) and the live readings on + each expected connection. **Latest from device** and **Latest recorded** can + include points the device kept during a Pulse outage, so a new chart point + alone does not prove Pulse polled again. +- **Agents:** Check **Last seen** (shown as **Seen** on narrow screens) and + the readings you need in **Machines**. Check **Docker** hosts separately: + container reports use their own stream and can stall even while machine + reports keep arriving from the same agent. +- **Prometheus scrapes (if already enabled):** Compare + `pulse_monitor_poll_total` by `result`. Rising errors mean Pulse is still + recording poll outcomes. If several expected sources give no new results, + check whether collection has stopped. + +[Check real alert delivery separately](#choose-where-notifications-go). ### Warn when expected polls stop succeeding @@ -188,7 +200,27 @@ or intentionally pause the target. A poll warning means Pulse has not recorded a fresh success for that connection. An increasing `pulse_monitor_poll_total` series with -`result="error"` means polls are still returning failures. No new results -despite working scrapes does not tell you whether the poll is slow or stuck. -Use the [missing-data checks](FAQ.md#no-data-showing) to narrow it down. -Neither alert checks whether agents reported or Pulse evaluated its rules. +`result="error"` means polls are still returning failures. + +If scrapes keep succeeding with no new poll outcomes, check the scheduler and +agent series already on that scrape target (an absent series on an older build +is not zero): + +- **Backoff still active:** `pulse_scheduler_breaker_retry_seconds` for the + same connection shows time left until the recorded retry deadline. Zero + means the deadline has passed or none was recorded, not that a poll ran. +- **Poll waiting in queue or on a worker:** compare + `pulse_scheduler_queued_poll_overdue_seconds` and + `pulse_scheduler_claimed_poll_overdue_seconds` (`stage="waiting_for_slot"` + and `stage="running"`) across fresh scrapes. Growing ages show queued or + claimed polls falling behind their schedule or timeout budget. Zero does + not prove polling recovered. +- **Agent reports:** inspect `pulse_http_requests_total` with `method="POST"` + separately for `/api/agents/agent/report` (or legacy + `/api/agents/host/report`) and `/api/agents/docker/report`, split by + `status`. Do not add the routes together: machine reports can keep + succeeding while Docker reports stop. + +Use the [missing-data checks](FAQ.md#no-data-showing) to narrow it down +without restarting Pulse or sending test traffic. Neither alert above checks +whether Pulse evaluated its alert rules. diff --git a/scripts/tests/test_alerting_outage_help_docs.py b/scripts/tests/test_alerting_outage_help_docs.py new file mode 100644 index 0000000000..7df70041a1 --- /dev/null +++ b/scripts/tests/test_alerting_outage_help_docs.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +"""Verify the shipped Alerting outage-detection Help matches live runtime signals. + +Binds in-app ALERTING.md to the actual Prometheus metrics, agent report routes, +History source labels, and shipped Help headings without touching a live server. +""" + +from __future__ import annotations + +from pathlib import Path +import re +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +DOC = ROOT / "docs/ALERTING.md" +SHIPPED = ROOT / "frontend-modern/public/docs/ALERTING.md" + + +def outage_section() -> str: + text = DOC.read_text(encoding="utf-8") + marker = "## Detect an outage of Pulse itself\n" + if marker not in text: + raise AssertionError("missing outage-detection section in docs/ALERTING.md") + return text.split(marker, 1)[1] + + +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 AlertingOutageHelpDocsTest(unittest.TestCase): + def test_shipped_copy_matches_source(self): + self.assertEqual(DOC.read_bytes(), SHIPPED.read_bytes()) + + def test_distinguishes_device_history_machines_and_docker_reports(self): + section = " ".join(outage_section().split()) + history_model = ( + ROOT / "frontend-modern/src/components/shared/historyChartModel.ts" + ).read_text(encoding="utf-8") + machine_model = ( + ROOT / "frontend-modern/src/features/standalone/agentMachineTableModel.ts" + ).read_text(encoding="utf-8") + + for label in ("Latest from device", "Latest recorded"): + self.assertIn(label, history_model) + self.assertIn(f"**{label}**", section) + self.assertIn("label: 'Last seen'", machine_model) + self.assertIn("**Last seen**", section) + self.assertIn("a new chart point alone does not prove Pulse polled again", section) + self.assertIn("Check **Docker** hosts separately", section) + self.assertIn("machine reports keep arriving from the same agent", section) + + def test_prometheus_scheduler_and_agent_signals_match_runtime_source(self): + section = " ".join(outage_section().split()) + monitoring_metrics = (ROOT / "internal/monitoring/metrics.go").read_text(encoding="utf-8") + queue_metrics = (ROOT / "internal/monitoring/poll_queue_metrics.go").read_text(encoding="utf-8") + work_progress = (ROOT / "internal/monitoring/poll_work_progress.go").read_text(encoding="utf-8") + http_metrics = (ROOT / "internal/api/http_metrics.go").read_text(encoding="utf-8") + routes = (ROOT / "internal/api/router_routes_registration.go").read_text(encoding="utf-8") + + for metric, source in ( + ("pulse_monitor_poll_total", monitoring_metrics), + ("pulse_monitor_poll_last_success_timestamp", monitoring_metrics), + ("pulse_scheduler_breaker_retry_seconds", monitoring_metrics), + ("pulse_scheduler_queued_poll_overdue_seconds", queue_metrics), + ("pulse_scheduler_claimed_poll_overdue_seconds", work_progress), + ("pulse_http_requests_total", http_metrics), + ): + with self.subTest(metric=metric): + self.assertIn(metric, section) + needle = ( + metric.removeprefix("pulse_monitor_") + if metric.startswith("pulse_monitor_") + else metric.removeprefix("pulse_http_") + if metric.startswith("pulse_http_") + else metric + ) + self.assertIn(f'"{needle}"', source) + + for stage in ("waiting_for_slot", "running"): + self.assertIn(f'"{stage}"', work_progress) + self.assertIn(f'`stage="{stage}"`', section) + + for route in ( + "/api/agents/agent/report", + "/api/agents/host/report", + "/api/agents/docker/report", + ): + self.assertIn(f'"{route}"', routes) + self.assertIn(f"`{route}`", section) + + for boundary in ( + "an absent series on an older build is not zero", + "not that a poll ran", + "Zero does not prove polling recovered", + "Do not add the routes together", + "without restarting Pulse or sending test traffic", + "Neither alert above checks whether Pulse evaluated its alert rules", + ): + self.assertIn(boundary, section) + + def test_in_app_links_target_real_shipped_docs_and_headings(self): + section = outage_section() + links = re.findall(r"\[[^\]]+\]\(([^)]+)\)", section) + self.assertGreaterEqual(len(links), 5) + for target in links: + self.assertFalse(target.startswith("http"), target) + if target.startswith("#"): + doc_path = SHIPPED + 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: + 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 anchor #{fragment} in {doc_path.name}") + + +if __name__ == "__main__": + unittest.main()