: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(warehouse-sources): add missing Better Stack endpoint tables (#100946)
Tom Owers276a372f2fa7
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 3a3939307cc1..31ea561b7d7f 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@@ -785,7 +785,7 @@ Diffed against: <https://api.bettermode.com/ (live GraphQL introspection of quer## BetterStack — gaps-Today (13): `escalation_policies`, `heartbeat_groups`, `heartbeats`, `incident_comments`, `incidents`, `monitor_availability`, `monitor_groups`, `monitor_response_times`, `monitors`, `on_calls`, `roles`, `status_pages`, `team_members`+Today (19): `escalation_policies`, `heartbeat_availability`, `heartbeat_groups`, `heartbeats`, `incident_comments`, `incidents`, `monitor_availability`, `monitor_groups`, `monitor_response_times`, `monitors`, `on_call_events`, `on_call_rotations`, `on_calls`, `roles`, `severities`, `severity_groups`, `status_page_resources`, `status_pages`, `team_members`Diffed against: <https://betterstack.com/docs/uptime/api/getting-started-with-uptime-api/>@@ -793,16 +793,16 @@ Diffed against: <https://betterstack.com/docs/uptime/api/getting-started-with-up- [x] `GET monitor response times (/api/v2/monitors/{id}/response-times)` — latency time series per monitor and region; the other core performance metric (high)- [x] `GET /api/v2/team-members (and /api/v2/roles)` — lookup resolving the user IDs referenced by incidents, on-call calendars and escalation policies (high)- [x] `GET incident comments (/api/v2/incidents/{id}/comments)` — acknowledgement and resolution commentary - the timeline behind incident MTTA/MTTR (high)-- [ ] `GET on-call calendar events and rotation` — who was actually on call and when; on_calls only carries the calendar definitions (high)-- [ ] `GET heartbeat availability summary` — the heartbeat equivalent of the monitor SLA summary (medium)-- [ ] `GET severities and severity groups (/api/v2/severities)` — call-routing severity lookup resolving the severity referenced on incidents (medium)-- [ ] `GET status page resources (/api/v2/status-pages/{id}/resources)` — join table mapping status pages to the monitors and heartbeats they display (medium)+- [x] `GET on-call calendar events and rotation` — who was actually on call and when; on_calls only carries the calendar definitions (high)+- [x] `GET heartbeat availability summary` — the heartbeat equivalent of the monitor SLA summary (medium)+- [x] `GET severities and severity groups (/api/v2/urgencies, /api/v2/urgency-groups)` — call-routing severity lookup resolving the severity referenced on incidents (medium)+- [x] `GET status page resources (/api/v2/status-pages/{id}/resources)` — join table mapping status pages to the monitors and heartbeats they display (medium)- [ ] `GET status page reports and report status updates` — published incident reports and their update history - the customer-facing incident record (medium)- [ ] `GET status page subscribers (/api/v2/status-pages/{id}/subscribers)` — audience reach per status page (medium)- [ ] `GET metadata records (/api/v3/metadata)` — the catalog/metadata store used to attach ownership and context to monitors and incidents (medium)- [ ] `GET escalation policy groups and status page groups/sections` — grouping lookups for the policies and status pages already synced (low)-Note: The docs are HTML-only with no downloadable OpenAPI; I enumerated the API reference nav across several fetched pages under /docs/uptime/api/. Excluded: the Reporting page, which is an outbound incident log drain (webhook payload schema), not a queryable resource, and the New Relic integrations endpoint (integration config).+Note: The docs are HTML-only with no downloadable OpenAPI; I enumerated the API reference nav across several fetched pages under /docs/uptime/api/. The severities routes are `/api/v2/urgencies` and `/api/v2/urgency-groups` — `/api/v2/severities` is a 404; the product was renamed but the API paths were not. On-call events and the on-call rotation are two separate per-schedule endpoints, so they became two tables. Excluded: the Reporting page, which is an outbound incident log drain (webhook payload schema), not a queryable resource, and the New Relic integrations endpoint (integration config).## BigMailer — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/better_stack.py b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/better_stack.pyindex fd3b433badf4..0faf79c842e4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/better_stack.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/better_stack.py@@ -224,9 +224,9 @@ def _top_level_source("params": _build_initial_params(config, should_use_incremental_field, db_incremental_field_last_value),- # A missing `data` key is treated as an empty page (matching the API's- # envelope, which always carries `data`), so no data_selector_required here.- "data_selector": "data",+ # A missing envelope key is treated as an empty page (matching the API,+ # which always carries it), so no data_selector_required here.+ "data_selector": config.data_selector,},# Better Stack is JSON:API — hoist each item's `attributes` into the row root."data_map": _flatten_item,@@ -310,8 +310,8 @@ def _fanout_source(# None of the child endpoints take a page-size param; the parent's rides in# `parent_params` above.page_size_param=None,- parent_endpoint_extra={"paginator": BetterStackPaginator(), "data_selector": "data"},- child_endpoint_extra={"paginator": BetterStackPaginator(), "data_selector": "data"},+ parent_endpoint_extra={"paginator": BetterStackPaginator(), "data_selector": parent_config.data_selector},+ child_endpoint_extra={"paginator": BetterStackPaginator(), "data_selector": config.data_selector},resume_hook=save_checkpoint,initial_paginator_state=initial_paginator_state,),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/canonical_descriptions.pyindex 2a67e90f3a85..005b2eaa3cd5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/canonical_descriptions.py@@ -95,6 +95,19 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updated_at": "When the heartbeat was last updated.",},},+ "heartbeat_availability": {+ "description": "Availability summary per heartbeat: uptime percentage and downtime totals since the heartbeat was created.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Identifier of the heartbeat the summary covers.",+ "heartbeat_id": "Identifier of the heartbeat the summary covers.",+ "availability": "Percentage of time the heartbeat was up.",+ "total_downtime": "Total time the heartbeat was down, in seconds.",+ "number_of_incidents": "Number of incidents recorded for the heartbeat.",+ "longest_incident": "Duration of the longest incident, in seconds.",+ "average_incident": "Average incident duration, in seconds.",+ },+ },"heartbeat_groups": {"description": "Groups used to organize heartbeat checks.","docs_url": _DOCS,@@ -142,6 +155,30 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"name": "Name of the on-call calendar.",},},+ "on_call_events": {+ "description": "Resolved on-call shifts per schedule: who was on call over which period, including one-off overrides.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the on-call shift.",+ "on_call_id": "Identifier of the on-call calendar the shift belongs to.",+ "users": "Email addresses of the people on call during the shift.",+ "starts_at": "When the shift starts.",+ "ends_at": "When the shift ends.",+ "override": "Whether the shift is a one-off override of the regular rotation.",+ },+ },+ "on_call_rotations": {+ "description": "The rotation currently driving each on-call calendar: how long a turn lasts and who takes part.",+ "docs_url": _DOCS,+ "columns": {+ "on_call_id": "Identifier of the on-call calendar the rotation belongs to.",+ "rotation_length": "Length of one turn, counted in `rotation_interval` units.",+ "rotation_interval": "Unit the rotation length is counted in (e.g. hour, day, week).",+ "start_rotations_at": "When the rotation starts.",+ "end_rotations_at": "When the rotation ends.",+ "users": "Email addresses of the people taking part in the rotation.",+ },+ },"escalation_policies": {"description": "Escalation policies describing how incidents are escalated to team members.","docs_url": _DOCS,@@ -152,6 +189,52 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"repeat_delay": "Delay between escalation repeats, in seconds.",},},+ "severities": {+ "description": "Severities used to route alerts, resolving the severity referenced on incidents. Better Stack's API names these urgencies.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the severity.",+ "name": "Name of the severity.",+ "team_name": "Name of the team the severity belongs to.",+ "sms": "Whether the severity alerts by SMS.",+ "call": "Whether the severity alerts by phone call.",+ "email": "Whether the severity alerts by email.",+ "push": "Whether the severity alerts by mobile push notification.",+ },+ },+ "severity_groups": {+ "description": "Groups used to organize severities.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the severity group.",+ "name": "Name of the severity group.",+ "sort_index": "Position of the group when sorting groups.",+ "team_name": "Name of the team the group belongs to.",+ "created_at": "When the group was created.",+ "updated_at": "When the group was last updated.",+ },+ },+ "status_page_resources": {+ "description": "The monitors and heartbeats each status page publishes, with the name and availability shown to visitors.",+ "docs_url": _DOCS,+ "columns": {+ "id": "Unique identifier for the status page resource.",+ "status_page_id": "Identifier of the status page the resource appears on.",+ "status_page_section_id": "Identifier of the section the resource is placed in.",+ "resource_id": "Identifier of the monitor or heartbeat the resource points at.",+ "resource_type": "Kind of thing the resource points at (e.g. Monitor, Heartbeat).",+ "public_name": "Name shown for the resource on the status page.",+ "explanation": "Description shown alongside the resource.",+ "widget_type": "How the resource is rendered on the status page (e.g. history, response times).",+ "history": "Whether past availability is shown for the resource.",+ "position": "Position of the resource within its section.",+ "mark_as_down_for": "Which incidents mark the resource as down.",+ "mark_as_degraded_for": "Which incidents mark the resource as degraded.",+ "availability": "Availability shown for the resource, as a fraction of 1.",+ "status": "Current status shown for the resource (e.g. operational, downtime).",+ "status_history": "Per-day status and downtime totals shown on the resource's history bar.",+ },+ },"team_members": {"description": "People in the Better Stack team, including pending invitations, resolving the user ids referenced by incidents and on-call schedules.","docs_url": _DOCS,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/settings.pyindex 7ddad911a69c..4521299a67ba 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/settings.py@@ -39,6 +39,8 @@ class BetterStackEndpointConfig:# Documented default is 50 everywhere; standard v2 collections accept up to 250, the v3# incidents endpoint caps at 50.page_size: int = 50+ # Most collections wrap their rows in the JSON:API `data` envelope; the on-call ones do not.+ data_selector: str = "data"should_sync_default: bool = True# Set where the resource only exists per parent row (e.g. /monitors/{monitor_id}/sla).fanout: Optional[DependentEndpointConfig] = None@@ -68,6 +70,33 @@ _MONITOR_FANOUT = DependentEndpointConfig(child_response_actions=_SKIP_MISSING_PARENT,)+_HEARTBEAT_FANOUT = DependentEndpointConfig(+ parent_name="heartbeats",+ resolve_param="heartbeat_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "heartbeat_id"},+ child_response_actions=_SKIP_MISSING_PARENT,+)++_ON_CALL_FANOUT = DependentEndpointConfig(+ parent_name="on_calls",+ resolve_param="schedule_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "on_call_id"},+ child_response_actions=_SKIP_MISSING_PARENT,+)++_STATUS_PAGE_FANOUT = DependentEndpointConfig(+ parent_name="status_pages",+ resolve_param="status_page_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "status_page_id"},+ child_response_actions=_SKIP_MISSING_PARENT,+)+# Endpoint catalog — the streams a reliability team actually wants from an uptime/incident# platform: monitors and heartbeats (plus their groups), monitor availability and latency,# incident history and commentary, on-call calendars, escalation policies, status pages, and the@@ -140,6 +169,13 @@ BETTER_STACK_ENDPOINTS: dict[str, BetterStackEndpointConfig] = {partition_key="created_at",page_size=250,),+ # Recomputed every sync: the endpoint summarizes the heartbeat's whole life and takes no filter.+ "heartbeat_availability": BetterStackEndpointConfig(+ name="heartbeat_availability",+ path="/v2/heartbeats/{heartbeat_id}/availability",+ primary_keys=["heartbeat_id"],+ fanout=_HEARTBEAT_FANOUT,+ ),"heartbeat_groups": BetterStackEndpointConfig(name="heartbeat_groups",path="/v2/heartbeat-groups",@@ -150,16 +186,51 @@ BETTER_STACK_ENDPOINTS: dict[str, BetterStackEndpointConfig] = {path="/v2/status-pages",page_size=250,),+ "status_page_resources": BetterStackEndpointConfig(+ name="status_page_resources",+ path="/v2/status-pages/{status_page_id}/resources",+ primary_keys=["status_page_id", "id"],+ fanout=_STATUS_PAGE_FANOUT,+ ),# Small configuration collections — page size left at the documented default of 50 since# their maximums aren't documented."on_calls": BetterStackEndpointConfig(name="on_calls",path="/v2/on-calls",),+ # Re-read whole every sync rather than merged: editing a schedule rewrites its future shifts,+ # and a merge would keep rows for shifts that no longer exist.+ "on_call_events": BetterStackEndpointConfig(+ name="on_call_events",+ path="/v2/on-calls/{schedule_id}/events",+ # Rows arrive under `events`, and the endpoint does not paginate.+ data_selector="events",+ partition_key="starts_at",+ primary_keys=["on_call_id", "id"],+ fanout=_ON_CALL_FANOUT,+ ),+ "on_call_rotations": BetterStackEndpointConfig(+ name="on_call_rotations",+ path="/v2/on-calls/{schedule_id}/rotation",+ # A bare object with no envelope and no id of its own, so the schedule id is the key. A+ # schedule with no rotation defined answers 404, which the fan-out skips.+ data_selector="$",+ primary_keys=["on_call_id"],+ fanout=_ON_CALL_FANOUT,+ ),"escalation_policies": BetterStackEndpointConfig(name="escalation_policies",path="/v2/policies",),+ # The routes still carry the feature's former name, `urgencies`.+ "severities": BetterStackEndpointConfig(+ name="severities",+ path="/v2/urgencies",+ ),+ "severity_groups": BetterStackEndpointConfig(+ name="severity_groups",+ path="/v2/urgency-groups",+ ),# People lookups resolving the user ids incidents, on-call calendars and escalation policies# reference. Both are account-level, so they live on the other host."team_members": BetterStackEndpointConfig(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack.py b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack.pyindex bb21a7132279..76d6cf133e74 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack.py@@ -466,6 +466,34 @@ class TestFanout:{"monitor_id": "7", "region": "eu", "at": "2026-04-03T11:00:59.000Z"}]+ @parameterized.expand(+ [+ # (endpoint, parent path, child path, parent id column)+ ("heartbeat_availability", "/v2/heartbeats", "/v2/heartbeats/1/availability", "heartbeat_id"),+ ("status_page_resources", "/v2/status-pages", "/v2/status-pages/1/resources", "status_page_id"),+ ]+ )+ @mock.patch(SESSION_PATCH)+ def test_child_is_bound_to_its_parent(+ self, endpoint: str, parent_path: str, child_path: str, parent_key: str, MockSession+ ) -> None:+ session = MockSession.return_value+ snapshots = _wire(+ session,+ [+ _response([{"id": "1", "attributes": {}}]),+ _object_response({"id": "9", "attributes": {"availability": 99.5}}),+ ],+ )++ rows = _rows(_source(endpoint=endpoint))++ # Each parent has its own resolve param, so a wrong one leaves the path placeholder unbound.+ assert snapshots[0]["url"] == f"{BETTER_STACK_BASE_URL}{parent_path}"+ assert snapshots[0]["params"] == {"per_page": 250}+ assert snapshots[1]["url"] == f"{BETTER_STACK_BASE_URL}{child_path}"+ assert rows == [{"id": "9", parent_key: "1", "availability": 99.5}]+@mock.patch(SESSION_PATCH)def test_incident_comments_carry_their_incident(self, MockSession) -> None:session = MockSession.return_value@@ -575,12 +603,93 @@ class TestFanout:assert _rows(_source(endpoint="monitor_availability")) == [{"id": "2", "monitor_id": "2", "availability": 98.0}]+class TestOnCallSchedules:+ @mock.patch(SESSION_PATCH)+ def test_shifts_are_read_from_the_events_envelope(self, MockSession) -> None:+ session = MockSession.return_value+ events = Response()+ events.status_code = 200+ events._content = json.dumps(+ {+ "events": [+ {+ "id": 12345,+ "users": ["[email protected]"],+ "starts_at": "2026-09-04T22:00:00Z",+ "ends_at": "2026-09-05T22:00:00Z",+ "override": False,+ }+ ]+ }+ ).encode()+ snapshots = _wire(session, [_response([{"id": "3", "type": "on_call", "attributes": {}}]), events])++ rows = _rows(_source(endpoint="on_call_events"))++ # Shifts arrive under `events`, not the `data` envelope every other collection uses.+ assert rows == [+ {+ "id": 12345,+ "on_call_id": "3",+ "users": ["[email protected]"],+ "starts_at": "2026-09-04T22:00:00Z",+ "ends_at": "2026-09-05T22:00:00Z",+ "override": False,+ }+ ]+ assert snapshots[1]["url"] == f"{BETTER_STACK_BASE_URL}/v2/on-calls/3/events"++ @mock.patch(SESSION_PATCH)+ def test_rotation_is_read_from_the_bare_response_body(self, MockSession) -> None:+ session = MockSession.return_value+ rotation = Response()+ rotation.status_code = 200+ rotation._content = json.dumps(+ {+ "rotation_length": 8,+ "rotation_interval": "hour",+ "start_rotations_at": "2026-02-01T07:00:00.000Z",+ "users": ["[email protected]", "[email protected]"],+ }+ ).encode()+ snapshots = _wire(session, [_response([{"id": "3", "type": "on_call", "attributes": {}}]), rotation])++ rows = _rows(_source(endpoint="on_call_rotations"))++ # The rotation has no envelope and no id of its own — the schedule id keys the row.+ assert rows == [+ {+ "on_call_id": "3",+ "rotation_length": 8,+ "rotation_interval": "hour",+ "start_rotations_at": "2026-02-01T07:00:00.000Z",+ "users": ["[email protected]", "[email protected]"],+ }+ ]+ assert snapshots[1]["url"] == f"{BETTER_STACK_BASE_URL}/v2/on-calls/3/rotation"++ @mock.patch(SESSION_PATCH)+ def test_schedule_without_a_rotation_is_skipped(self, MockSession) -> None:+ session = MockSession.return_value+ missing = Response()+ missing.status_code = 404+ missing._content = b"{}"+ _wire(session, [_response([{"id": "3", "attributes": {}}]), missing])++ # A schedule with no rotation defined answers 404 — a normal state, not a sync failure.+ assert _rows(_source(endpoint="on_call_rotations")) == []++class TestProbeCredentialsForFanoutEndpoints:@parameterized.expand([("monitor_availability", f"{BETTER_STACK_BASE_URL}/v2/monitors?per_page=1"),("monitor_response_times", f"{BETTER_STACK_BASE_URL}/v2/monitors?per_page=1"),("incident_comments", f"{BETTER_STACK_BASE_URL}/v3/incidents?per_page=1"),+ ("heartbeat_availability", f"{BETTER_STACK_BASE_URL}/v2/heartbeats?per_page=1"),+ ("status_page_resources", f"{BETTER_STACK_BASE_URL}/v2/status-pages?per_page=1"),+ ("on_call_events", f"{BETTER_STACK_BASE_URL}/v2/on-calls?per_page=1"),+ ("on_call_rotations", f"{BETTER_STACK_BASE_URL}/v2/on-calls?per_page=1"),("team_members", f"{BETTER_STACK_ORG_BASE_URL}/v2/team-members?per_page=1"),])diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack_source.pyindex 1dda300c41bc..ac314849d3e6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/better_stack/tests/test_better_stack_source.py@@ -37,10 +37,16 @@ class TestBetterStackGetSchemas:("monitor_availability", False, False),("monitor_groups", False, False),("heartbeats", False, False),+ ("heartbeat_availability", False, False),("heartbeat_groups", False, False),("status_pages", False, False),+ ("status_page_resources", False, False),("on_calls", False, False),+ ("on_call_events", False, False),+ ("on_call_rotations", False, False),("escalation_policies", False, False),+ ("severities", False, False),+ ("severity_groups", False, False),("team_members", False, False),("roles", False, False),]@@ -137,6 +143,13 @@ class TestBetterStackResumableAndPipeline:("incident_comments", ["incident_id", "id"], ["created_at"], "datetime", "desc"),("monitor_response_times", ["monitor_id", "region", "at"], ["at"], "datetime", "desc"),("monitor_availability", ["monitor_id"], None, None, "asc"),+ ("heartbeat_availability", ["heartbeat_id"], None, None, "asc"),+ # A status page resource id is only unique within its page, and a schedule's shift id+ # only within that schedule, so both carry their parent.+ ("status_page_resources", ["status_page_id", "id"], None, None, "asc"),+ ("on_call_events", ["on_call_id", "id"], ["starts_at"], "datetime", "asc"),+ # A rotation is one row per schedule and carries no id of its own.+ ("on_call_rotations", ["on_call_id"], None, None, "asc"),# Members and pending invitations draw ids from separate spaces.("team_members", ["id", "type"], None, None, "asc"),("roles", ["id"], None, None, "asc"),@@ -145,6 +158,8 @@ class TestBetterStackResumableAndPipeline:("status_pages", ["id"], None, None, "asc"),("on_calls", ["id"], None, None, "asc"),("escalation_policies", ["id"], None, None, "asc"),+ ("severities", ["id"], None, None, "asc"),+ ("severity_groups", ["id"], None, None, "asc"),])def test_source_for_pipeline_per_endpoint(