:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add honeycomb signals and historical anomalies tables (#119250)
Tom Owers01210888934a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex bd47e247fd25..214cef483b06 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -5962,7 +5962,7 @@ Note: Static endpoint list; source dir products/warehouse_sources/backend/tempor## Honeycomb — gaps-Today (11): `board_views`, `boards`, `burn_alerts`, `columns`, `datasets`, `derived_columns`, `markers`, `recipients`, `slo_counts_history`, `slos`, `triggers`+Today (13): `board_views`, `boards`, `burn_alerts`, `columns`, `datasets`, `derived_columns`, `markers`, `recipients`, `signal_historical_anomalies`, `signals`, `slo_counts_history`, `slos`, `triggers`Diffed against: <https://api-docs.honeycomb.io/api/openapi-public.yaml>@@ -5975,6 +5975,8 @@ Diffed against: <https://api-docs.honeycomb.io/api/openapi-public.yaml>- [ ] `/1/reporting/slos/historical` — weekly historical SLO breakdown across multiple SLOs in one call (medium)- [ ] `/1/query_annotations/{datasetSlug}` — named/annotated queries used to label saved analyses (low)- [ ] `/1/marker_settings/{datasetSlug}` — lookup resolving marker types to display settings for the markers we sync (low)+- [x] `/1/signals` — Anomaly Detection Signals: the services whose error rate or presence Honeycomb monitors (medium). Added as `signals` (cursor-paginated, full refresh; needs the Manage Signals permission, off by default).+- [x] `/1/signals/{signalId}/historical_anomalies` — resolved anomalies per Signal (medium). Added as `signal_historical_anomalies` (fan-out over `signals`, incremental on `started_at` via the `start_time`/`end_time` window; off by default).Note: Diffed against the machine-readable OpenAPI spec (api-docs.honeycomb.io/api/openapi-public.yaml). Coverage of top-level v1 resources is good; the gaps are the SLO measurement sub-resources and the v2 environments lookup.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/canonical_descriptions.pyindex 838f7b434239..a5b1fee36c55 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/canonical_descriptions.py@@ -148,4 +148,36 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"is_partial": "Whether the bucket covers the in-progress hour; its counts keep growing until the hour completes.",},},+ "signals": {+ "description": "An Anomaly Detection Signal: a service in a dataset whose error rate or presence Honeycomb monitors against a trained baseline.",+ "docs_url": "https://api-docs.honeycomb.io/api/anomaly-detection",+ "columns": {+ "id": "Unique identifier for the Signal.",+ "service_name": "Name of the service the Signal monitors.",+ "dataset_slug": "Slug of the dataset the Signal's service reports to.",+ "environment_slug": "Slug of the environment the Signal belongs to.",+ "measured_signal": "Kind of measurement the Signal is trained on (error_rate or presence).",+ "enabled": "Whether the Signal is enabled. Disabled Signals do not fire.",+ "status": "Lifecycle status of the Signal (onboarding, normal, anomalous, off, or ineligible).",+ "sensitivity": "How far a measurement must deviate from the trained normal band before the Signal fires. Null for presence Signals and Signals that have not trained yet.",+ "auto_investigate": "Whether Honeycomb starts an investigation automatically when the Signal fires.",+ "currently_anomalous": "Whether the Signal is in an anomalous state now.",+ "last_anomaly_started_at": "Start of the most recent anomaly as a Unix timestamp in seconds. Null when the Signal has never been anomalous.",+ "last_anomaly_ended_at": "End of the most recent anomaly as a Unix timestamp in seconds. Null when no anomaly has ended yet, or the Signal is anomalous now.",+ "created_at": "When the Signal was created.",+ "updated_at": "When the Signal was last modified.",+ },+ },+ "signal_historical_anomalies": {+ "description": "A resolved anomaly that an Anomaly Detection Signal fired for.",+ "docs_url": "https://api-docs.honeycomb.io/api/anomaly-detection",+ "columns": {+ "id": "Identifier for the anomaly, derived from the Signal, its measured kind, and the anomaly's start time.",+ "signal_id": "ID of the Signal the anomaly belongs to (added by PostHog during sync).",+ "started_at": "When the anomaly started, as a Unix timestamp in seconds.",+ "ended_at": "When the anomaly ended, as a Unix timestamp in seconds.",+ "measurement": "The measured value that triggered the anomaly.",+ "normal_range": "The trained normal band (lower and upper bounds) the measurement exceeded. Null for presence Signals.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/honeycomb.py b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/honeycomb.pyindex f4fd66f86a1e..cb23a676ba2b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/honeycomb.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/honeycomb.py@@ -2,7 +2,7 @@ import dataclassesfrom collections.abc import Iteratorfrom datetime import UTC, datetime, timedeltafrom typing import Any-from urllib.parse import urlencode+from urllib.parse import urlencode, urljoin, urlsplitimport requestsfrom structlog.types import FilteringBoundLogger@@ -46,6 +46,16 @@ SLO_COUNTS_HISTORY_LOOKBACK = timedelta(days=90)SLO_COUNTS_HISTORY_WINDOW = timedelta(days=7)SECONDS_PER_HOUR = 3600+# Largest page Honeycomb's cursor-paginated endpoints accept.+CURSOR_PAGE_SIZE = 100+# How far back a full refresh (or the first incremental sync) reads Signal historical anomalies.+SIGNAL_ANOMALIES_LOOKBACK = timedelta(days=90)+# Each historical anomalies walk covers one window per Signal; the API caps a window at 30 days.+SIGNAL_ANOMALIES_WINDOW = timedelta(days=7)+# Only resolved anomalies are listed, so one that started before the watermark appears only after+# it ends. Incremental syncs re-read this far behind the watermark and merge dedupes the overlap.+SIGNAL_ANOMALIES_REREAD = timedelta(days=7)+class HoneycombRetryableError(Exception):pass@@ -55,6 +65,10 @@ class HoneycombSloCountsUnavailableError(Exception):pass+class HoneycombUnsafeUrlError(Exception):+ pass++@dataclasses.dataclass(frozen=True)class HoneycombResumeConfig:# The fan-out dataset currently being processed, bookmarked by its stable slug (not a@@ -65,6 +79,8 @@ class HoneycombResumeConfig:dataset_slug: str | None = None# The same bookmark for the board views fan-out, which walks boards instead of datasets.board_id: str | None = None+ # The next page URL of a cursor-paginated environment endpoint (signals).+ next_url: str | None = Nonedef _get_headers(api_key: str) -> dict[str, str]:@@ -84,8 +100,14 @@ def _base_url(region: str) -> str:wait=wait_exponential_jitter(initial=1, max=60),reraise=True,)-def _fetch_page(session: requests.Session, url: str, headers: dict[str, str], logger: FilteringBoundLogger):- response = session.get(url, headers=headers, timeout=60)+def _fetch_page(+ session: requests.Session,+ url: str,+ headers: dict[str, str],+ logger: FilteringBoundLogger,+ allow_redirects: bool = True,+):+ response = session.get(url, headers=headers, timeout=60, allow_redirects=allow_redirects)# Honeycomb rate limits per key/team and returns 429 on exceed; retry those plus# transient 5xx with exponential backoff.@@ -148,6 +170,46 @@ def _fetch_slo_counts_buckets(return buckets if isinstance(buckets, list) else []+def _is_same_origin(url: str, base_url: str) -> bool:+ candidate, base = urlsplit(url), urlsplit(base_url)+ return (candidate.scheme, candidate.netloc) == (base.scheme, base.netloc)+++def _iter_cursor_pages(+ session: requests.Session,+ base_url: str,+ url: str,+ headers: dict[str, str],+ response_key: str,+ logger: FilteringBoundLogger,+) -> Iterator[tuple[list[dict[str, Any]], str | None]]:+ """Walk a cursor-paginated endpoint, yielding each page's rows with the next page's URL.++ Rows sit under ``response_key`` and ``links.next`` holds a relative URL for the next page,+ null on the last one. The API key rides in a header on every request, so a next link or+ redirect that leaves the Honeycomb origin fails the sync instead of being followed."""+ while True:+ if not _is_same_origin(url, base_url):+ raise HoneycombUnsafeUrlError(f"Honeycomb: refusing to request a URL outside {base_url}")+ response = _fetch_page(session, url, headers, logger, allow_redirects=False)+ if response.is_redirect:+ raise HoneycombUnsafeUrlError(f"Honeycomb: refusing to follow a redirect from {base_url}")+ data = response.json()+ if not isinstance(data, dict):+ logger.warning(f"Honeycomb: expected a JSON object from {url}, got {type(data).__name__}; skipping")+ return+ rows = data.get(response_key)+ links = data.get("links")+ next_path = links.get("next") if isinstance(links, dict) else None+ next_url = urljoin(base_url, next_path) if next_path else None+ if next_url == url:+ next_url = None+ yield (rows if isinstance(rows, list) else []), next_url+ if next_url is None:+ return+ url = next_url++def _to_epoch_seconds(value: Any) -> int | None:"""Normalise a persisted watermark (int epoch, datetime, or string) to epoch seconds."""if value is None or isinstance(value, bool):@@ -341,6 +403,79 @@ def _iter_slo_counts_history(window_start = window_end+def _iter_signals(+ session: requests.Session,+ base_url: str,+ headers: dict[str, str],+ config: HoneycombEndpointConfig,+ logger: FilteringBoundLogger,+ manager: ResumableSourceManager[HoneycombResumeConfig],+) -> Iterator[list[dict[str, Any]]]:+ """Emit every Signal page by page, bookmarking the next page's URL."""+ assert config.response_key is not None+ resume = manager.load_state() if manager.can_resume() else None+ if resume is not None and resume.next_url is not None and _is_same_origin(resume.next_url, base_url):+ url = resume.next_url+ logger.debug(f"Honeycomb: resuming {config.name} from {url}")+ else:+ url = f"{base_url}{config.path}?{urlencode({'page[size]': CURSOR_PAGE_SIZE})}"++ for rows, next_url in _iter_cursor_pages(session, base_url, url, headers, config.response_key, logger):+ if next_url is not None:+ manager.save_state(HoneycombResumeConfig(next_url=next_url))+ if rows:+ yield rows+ else:+ manager.safe_point()+++def _iter_signal_historical_anomalies(+ session: requests.Session,+ base_url: str,+ headers: dict[str, str],+ config: HoneycombEndpointConfig,+ logger: FilteringBoundLogger,+ manager: ResumableSourceManager[HoneycombResumeConfig],+ db_incremental_field_last_value: Any,+) -> Iterator[list[dict[str, Any]]]:+ """Emit resolved anomalies page by page, walking time windows oldest first across every Signal.++ Each page is yielded as it arrives, so a checkpoint can move the watermark into the current+ window before every Signal is read. That loses no rows: the watermark never passes the window+ end, and the next sync re-reads SIGNAL_ANOMALIES_REREAD (at least one window) behind it."""+ assert config.response_key is not None+ now = int(datetime.now(UTC).timestamp())+ floor = now - int(SIGNAL_ANOMALIES_LOOKBACK.total_seconds())+ watermark = _to_epoch_seconds(db_incremental_field_last_value)+ start = floor if watermark is None else max(watermark - int(SIGNAL_ANOMALIES_REREAD.total_seconds()), floor)++ signals_url = f"{base_url}/1/signals?{urlencode({'page[size]': CURSOR_PAGE_SIZE})}"+ signal_ids: list[str] = []+ for signals, _ in _iter_cursor_pages(session, base_url, signals_url, headers, "signals", logger):+ signal_ids.extend(signal["id"] for signal in signals)+ manager.safe_point()++ window_seconds = int(SIGNAL_ANOMALIES_WINDOW.total_seconds())+ window_start = start+ while window_start < now:+ window_end = min(window_start + window_seconds, now)+ query = urlencode({"start_time": window_start, "end_time": window_end, "page[size]": CURSOR_PAGE_SIZE})+ for signal_id in signal_ids:+ url = f"{base_url}{config.path.format(signal_id=signal_id)}?{query}"+ try:+ for anomalies, _ in _iter_cursor_pages(session, base_url, url, headers, config.response_key, logger):+ if anomalies:+ yield [{**anomaly, "signal_id": signal_id} for anomaly in anomalies]+ else:+ manager.safe_point()+ except requests.HTTPError as exc:+ # A Signal deleted since the listing 404s; its anomalies are genuinely gone.+ if exc.response is None or exc.response.status_code != 404:+ raise+ manager.safe_point()+ window_start = window_end++def get_rows(api_key: str,region: str,@@ -373,6 +508,16 @@ def get_rows(yield from _iter_slo_counts_history(session, base_url, headers, config, logger, db_incremental_field_last_value)return+ if config.scope == HoneycombScope.ENVIRONMENT_PAGINATED:+ yield from _iter_signals(session, base_url, headers, config, logger, resumable_source_manager)+ return++ if config.scope == HoneycombScope.PER_SIGNAL_TIME_WINDOW:+ yield from _iter_signal_historical_anomalies(+ session, base_url, headers, config, logger, resumable_source_manager, db_incremental_field_last_value+ )+ return+yield from _iter_fan_out(session, base_url, headers, config, logger, resumable_source_manager)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/settings.pyindex f1f3c14597c1..91c705bbdf89 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/settings.py@@ -27,6 +27,11 @@ class HoneycombScope(Enum):PER_SLO_TIME_WINDOW = "per_slo_time_window"# Fan out over every board in the environment (GET /1/boards/{board_id}/views).PER_BOARD = "per_board"+ # Environment-wide collection returned in cursor-paginated pages (GET /1/signals).+ ENVIRONMENT_PAGINATED = "environment_paginated"+ # Fan out over every Signal in the environment, one paginated walk per Signal per time window+ # (GET /1/signals/{signal_id}/historical_anomalies?start_time=…&end_time=…).+ PER_SIGNAL_TIME_WINDOW = "per_signal_time_window"@dataclass(frozen=False)@@ -34,7 +39,8 @@ class HoneycombEndpointConfig:name: strscope: HoneycombScope# Path template. Dataset fan-out paths contain ``{dataset_slug}`` (and ``{slo_id}`` for- # PER_SLO_TIME_WINDOW), PER_BOARD paths contain ``{board_id}``; ENVIRONMENT paths are static.+ # PER_SLO_TIME_WINDOW), PER_BOARD paths contain ``{board_id}``, PER_SIGNAL_TIME_WINDOW paths+ # contain ``{signal_id}``; ENVIRONMENT paths are static.path: str# Primary key columns used for merge dedup. For fan-out children the dataset slug is# included (and injected into every row) so the key stays unique across the whole table —@@ -50,10 +56,12 @@ class HoneycombEndpointConfig:include_environment_wide: bool = False# The menu of incremental cursor candidates advertised to the user. Empty = full refresh# only — Honeycomb's v1 config endpoints expose no server-side timestamp filter; only the- # SLO counts history takes a start_time/end_time range.+ # SLO counts history and Signal historical anomalies take a start_time/end_time range.incremental_fields: list[IncrementalField] = field(default_factory=list)# Whether the table is selected for sync by default in the connection wizard.should_sync_default: bool = True+ # Body key holding the rows of a cursor-paginated response; v1 config endpoints return a bare array.+ response_key: Optional[str] = NoneHONEYCOMB_ENDPOINTS: dict[str, HoneycombEndpointConfig] = {@@ -150,6 +158,34 @@ HONEYCOMB_ENDPOINTS: dict[str, HoneycombEndpointConfig] = {# Enterprise-only and enabled per team on request, so most keys get a 403/404 here.should_sync_default=False,),+ "signals": HoneycombEndpointConfig(+ name="signals",+ scope=HoneycombScope.ENVIRONMENT_PAGINATED,+ path="/1/signals",+ response_key="signals",+ primary_keys=["id"],+ partition_key="created_at",+ # Needs the Manage Signals permission, which keys created for the other tables usually lack.+ should_sync_default=False,+ ),+ "signal_historical_anomalies": HoneycombEndpointConfig(+ name="signal_historical_anomalies",+ scope=HoneycombScope.PER_SIGNAL_TIME_WINDOW,+ path="/1/signals/{signal_id}/historical_anomalies",+ response_key="historical_anomalies",+ # Anomaly ids are derived from the Signal, so the injected signal id is part of the key.+ primary_keys=["id", "signal_id"],+ partition_key="started_at",+ incremental_fields=[+ {+ "label": "started_at",+ "type": IncrementalFieldType.DateTime,+ "field": "started_at",+ "field_type": IncrementalFieldType.Integer,+ },+ ],+ should_sync_default=False,+ ),}ENDPOINTS = tuple(HONEYCOMB_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/source.pyindex a577c4658d41..b05f6471ffd7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/source.py@@ -128,7 +128,7 @@ class HoneycombSource(ResumableSource[HoneycombSourceConfig, HoneycombResumeConfreleaseStatus=ReleaseStatus.ALPHA,caption="""Enter a Honeycomb configuration API key to pull your Honeycomb observability configuration — datasets, SLOs, burn alerts, triggers, markers, boards, and more — into the PostHog Data warehouse.-You can create a configuration key under **Environment settings → API keys** in your [Honeycomb account](https://ui.honeycomb.io/). Grant read access for the resources you want to sync: Manage Queries and Columns, Manage SLOs, Manage Triggers, Manage Markers, Manage Boards, and Manage Recipients.+You can create a configuration key under **Environment settings → API keys** in your [Honeycomb account](https://ui.honeycomb.io/). Grant read access for the resources you want to sync: Manage Queries and Columns, Manage SLOs, Manage Triggers, Manage Markers, Manage Boards, Manage Recipients, and Manage Signals.Keys are region-specific — pick the region that matches your Honeycomb account.""",iconPath="/static/services/honeycomb.png",@@ -202,6 +202,13 @@ Keys are region-specific — pick the region that matches your Honeycomb account"Hourly good and bad event counts per SLO. Requires the Honeycomb Enterprise plan ""with SLO counts history enabled for your team.")+ if endpoint_config.scope is HoneycombScope.ENVIRONMENT_PAGINATED:+ return "Anomaly Detection Signals. Requires the Manage Signals permission on the API key."+ if endpoint_config.scope is HoneycombScope.PER_SIGNAL_TIME_WINDOW:+ return (+ "Resolved anomalies for every Anomaly Detection Signal. Requires the Manage Signals "+ "permission on the API key."+ )if endpoint_config.include_environment_wide:return "Includes environment-wide rows under the __all__ dataset slug alongside per-dataset rows."return Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/tests/test_honeycomb.py b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/tests/test_honeycomb.pyindex ea24443312b3..5cbd2d68bb49 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/tests/test_honeycomb.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/honeycomb/tests/test_honeycomb.py@@ -15,6 +15,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.honeycomb.HoneycombResumeConfig,HoneycombRetryableError,HoneycombSloCountsUnavailableError,+ HoneycombUnsafeUrlError,_base_url,get_rows,validate_credentials,@@ -37,6 +38,9 @@ class _FakeResumableManager:def save_state(self, data: HoneycombResumeConfig) -> None:self.saved.append(data)+ def safe_point(self) -> None:+ pass+def _make_response(status_code: int, body: Any = None) -> requests.Response:response = requests.Response()@@ -53,7 +57,9 @@ class _FakeSession:self._responses = list(responses)self.requested_urls: list[str] = []- def get(self, url: str, headers: dict[str, str] | None = None, timeout: int | None = None) -> requests.Response:+ def get(+ self, url: str, headers: dict[str, str] | None = None, timeout: int | None = None, **kwargs: Any+ ) -> requests.Response:self.requested_urls.append(url)return self._responses.pop(0)@@ -226,7 +232,9 @@ class _UrlSession:self._responses = responsesself.requested_urls: list[str] = []- def get(self, url: str, headers: dict[str, str] | None = None, timeout: int | None = None) -> requests.Response:+ def get(+ self, url: str, headers: dict[str, str] | None = None, timeout: int | None = None, **kwargs: Any+ ) -> requests.Response:self.requested_urls.append(url)if url not in self._responses:raise AssertionError(f"unexpected URL requested: {url}")@@ -346,6 +354,112 @@ class TestSloCountsHistory:_collect_counts_history(responses, watermark_hour, monkeypatch)+SIGNALS_FIRST_PAGE = f"{US}/1/signals?page%5Bsize%5D=100"+++def _collect_signals_endpoint(+ endpoint: str,+ responses: Mapping[str, Any],+ manager: _FakeResumableManager,+ monkeypatch: Any,+ last_value: Any = None,+) -> tuple[list[list[dict]], _UrlSession]:+ session = _UrlSession(responses)+ monkeypatch.setattr(honeycomb, "make_tracked_session", lambda *args, **kwargs: session)+ with time_machine.travel(NOW, tick=False):+ batches = list(+ get_rows(+ api_key="key",+ region="us",+ endpoint=endpoint,+ logger=MagicMock(),+ resumable_source_manager=manager, # type: ignore[arg-type]+ db_incremental_field_last_value=last_value,+ )+ )+ return batches, session+++def _anomalies_url(signal_id: str, start: int, end: int) -> str:+ return f"{US}/1/signals/{signal_id}/historical_anomalies?start_time={start}&end_time={end}&page%5Bsize%5D=100"+++class TestSignals:+ def test_follows_relative_next_links_and_stages_cursor_before_each_page(self, monkeypatch: Any) -> None:+ responses = {+ SIGNALS_FIRST_PAGE: {"signals": [{"id": "s1"}], "links": {"next": "/1/signals?page[after]=c1"}},+ f"{US}/1/signals?page[after]=c1": {"signals": [{"id": "s2"}], "links": {"next": None}},+ }+ manager = _FakeResumableManager()+ batches, _ = _collect_signals_endpoint("signals", responses, manager, monkeypatch)+ assert batches == [[{"id": "s1"}], [{"id": "s2"}]]+ assert [state.next_url for state in manager.saved] == [f"{US}/1/signals?page[after]=c1"]++ @parameterized.expand(+ [+ ("absolute_next_link_off_origin", "https://attacker.example/collect"),+ ("protocol_relative_next_link", "//attacker.example/collect"),+ ]+ )+ def test_next_link_off_origin_fails_without_sending_the_key(self, _name: str, next_link: str) -> None:+ responses = {SIGNALS_FIRST_PAGE: {"signals": [{"id": "s1"}], "links": {"next": next_link}}}+ # parameterized.expand can't also receive the `monkeypatch` fixture, so manage our own.+ with pytest.MonkeyPatch.context() as mp:+ with pytest.raises(HoneycombUnsafeUrlError):+ _collect_signals_endpoint("signals", responses, _FakeResumableManager(), mp)++ def test_resume_starts_from_saved_next_url(self, monkeypatch: Any) -> None:+ resume_url = f"{US}/1/signals?page[after]=c1"+ responses = {resume_url: {"signals": [{"id": "s2"}], "links": {"next": None}}}+ manager = _FakeResumableManager(HoneycombResumeConfig(next_url=resume_url))+ batches, session = _collect_signals_endpoint("signals", responses, manager, monkeypatch)+ assert batches == [[{"id": "s2"}]]+ assert session.requested_urls == [resume_url]+++class TestSignalHistoricalAnomalies:+ @parameterized.expand(+ [+ ("no_watermark", None, NOW - 90 * DAY),+ # Incremental syncs re-read a week behind the watermark for anomalies that resolved late.+ ("watermark", NOW - 2 * DAY, NOW - 9 * DAY),+ ("iso_watermark", "2026-01-13T12:30:00+00:00", NOW - 9 * DAY),+ ("watermark_older_than_lookback", 84513, NOW - 90 * DAY),+ ]+ )+ def test_walks_windows_across_every_signal(self, _name: str, last_value: Any, first_start: int) -> None:+ window_starts = list(range(first_start, NOW, 7 * DAY))+ responses: dict[str, Any] = {+ SIGNALS_FIRST_PAGE: {"signals": [{"id": "s1"}, {"id": "gone"}], "links": {"next": None}},+ }+ for start in window_starts:+ end = min(start + 7 * DAY, NOW)+ responses[_anomalies_url("s1", start, end)] = {+ "historical_anomalies": [{"id": f"a{start}", "started_at": start}],+ "links": {"next": f"/1/signals/s1/historical_anomalies?page[after]={start}"},+ }+ responses[f"{US}/1/signals/s1/historical_anomalies?page[after]={start}"] = {+ "historical_anomalies": [{"id": f"b{start}", "started_at": start}],+ "links": {"next": None},+ }+ # A Signal deleted since the listing 404s; that must drop its rows, not fail the sync.+ responses[_anomalies_url("gone", start, end)] = 404++ # parameterized.expand can't also receive the `monkeypatch` fixture, so manage our own.+ with pytest.MonkeyPatch.context() as mp:+ batches, session = _collect_signals_endpoint(+ "signal_historical_anomalies", responses, _FakeResumableManager(), mp, last_value+ )++ # One batch per page, so a window never buffers every Signal before yielding.+ assert len(batches) == 2 * len(window_starts)+ assert batches[:2] == [+ [{"id": f"a{first_start}", "started_at": first_start, "signal_id": "s1"}],+ [{"id": f"b{first_start}", "started_at": first_start, "signal_id": "s1"}],+ ]+ assert session.requested_urls[-1] == _anomalies_url("gone", window_starts[-1], NOW)++class TestRecipientCredentialScrubbing:"""Recipient payloads carry live credentials (PagerDuty integration keys, webhook signingsecrets, webhook / MS Teams capability URLs). Dropping the sanitization would hand those to