: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 linearb incidents table (#114502)
Tom Owersb51234652b57
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 5f3af88a6c76..76cebd9b4c43 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -767,7 +767,6 @@1 products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py1 products/warehouse_sources/backend/temporal/data_imports/sources/linear/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/linearb/linearb.py-1 products/warehouse_sources/backend/temporal/data_imports/sources/linearb/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/lingo_dev/lingo_dev.py1 products/warehouse_sources/backend/temporal/data_imports/sources/lingo_dev/settings.py1 products/warehouse_sources/backend/temporal/data_imports/sources/linkrunner/linkrunner.pydiff --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 673daea8bbcb..7853edf7e589 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@@ -5191,7 +5191,7 @@ Today (5): `deployments`, `measurements`, `services`, `teams`, `users`Diffed against: <https://docs.linearb.io/api-overview/>-- [ ] `incidents (GET /api/v1/incidents/search and /api/v1/incidents)` — incident records are the input to change failure rate and MTTR, two of the four DORA metrics LinearB is built around (high)+- [x] `incidents (GET /api/v1/incidents/search and /api/v1/incidents)` — incident records are the input to change failure rate and MTTR, two of the four DORA metrics LinearB is built around (high)Note: LinearB's public API reference lists only measurements v2, deployments, incidents, external custom metrics, teams v1/v2, users, services, jobs and health. PostHog already covers deployments, measurements, services, teams and users. External custom metrics is write-only (report a metric), jobs is an async job-status poll and health is a liveness probe, so incidents is the only genuine readable gap.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/canonical_descriptions.pyindex 1e22fa59b493..ed9d9bc5dcd7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/canonical_descriptions.py@@ -53,6 +53,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"services": "Services associated with the deployment.",},},+ "incidents": {+ "description": "Incidents reported to LinearB, used to compute change failure rate and MTTR.",+ "docs_url": "https://docs.linearb.io/api-incidents/",+ "columns": {+ "provider_id": "Unique identifier of the incident in the incident management provider.",+ "http_url": "URL that opens the incident in the incident management provider.",+ "title": "Incident title.",+ "issued_at": "When the incident was logged and officially opened.",+ "started_at": "When work on the incident started.",+ "ended_at": "When the incident was resolved.",+ "git_ref": "Git reference (commit SHA or tag) of the release that caused the incident.",+ "teams": "LinearB teams related to the incident.",+ "services": "LinearB services related to the incident.",+ "repositories": "Repositories related to the incident.",+ "status": "Incident status: open, in-progress, closed, or deleted.",+ },+ },"measurements": {"description": "Organization-level Git/DORA metrics computed by LinearB, rolled up daily.","docs_url": "https://docs.linearb.io/api-measurements-v2/",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/linearb.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/linearb.pyindex a09a422992dc..2f033dc99655 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/linearb.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/linearb.py@@ -129,7 +129,11 @@ def _iter_list_rows(params[config.page_size_param] = page_sizeparams["offset"] = offset- response = _request(session, "GET", url, headers, logger, params=params)+ if config.method == "POST":+ body = {**(config.request_body or {}), **params}+ response = _request(session, "POST", url, headers, logger, json_body=body)+ else:+ response = _request(session, "GET", url, headers, logger, params=params)payload = response.json()items = payload.get(config.data_selector, []) if config.data_selector else payloadif not items:@@ -216,7 +220,7 @@ def get_rows(# redirect target; LinearB's API never legitimately redirects.session = make_tracked_session(allow_redirects=False)- if config.method == "POST":+ if endpoint == "measurements":yield from _iter_measurements_rows(session, headers, logger)returndiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/settings.pyindex 8376a73cd9c9..fb1cc498511c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/settings.py@@ -1,5 +1,5 @@from dataclasses import dataclass, field-from typing import Literal, Optional+from typing import Any, Literal, Optionalfrom products.warehouse_sources.backend.types import IncrementalField@@ -30,8 +30,12 @@ MEASUREMENT_METRICS: tuple[tuple[str, Optional[str]], ...] = (# a full refresh re-pulls the window each run and merge dedupes on [after, organization_id].MEASUREMENTS_DEFAULT_WINDOW_DAYS = 90+# The incidents search requires an `issued_at` range. This lower bound predates LinearB, so every+# incident the organization has reported is returned.+INCIDENTS_ISSUED_AFTER = "2000-01-01"-@dataclass++@dataclass(frozen=True)class LinearbEndpointConfig:name: strpath: str@@ -43,6 +47,8 @@ class LinearbEndpointConfig:# `None` when the endpoint documents no pagination params (a single response holds every row).page_size_param: Optional[str] = Nonepage_size: Optional[int] = None+ # Fixed JSON body for POST list endpoints, which take their filters and paging params in the body.+ request_body: Optional[dict[str, Any]] = Noneprimary_keys: list[str] = field(default_factory=lambda: ["id"])# Stable creation-time field used for datetime partitioning. Never an updated_at-style field,# which would rewrite partitions on every sync.@@ -79,6 +85,22 @@ LINEARB_ENDPOINTS: dict[str, LinearbEndpointConfig] = {page_size_param="limit",page_size=100,),+ # Incidents can only be listed through the POST search endpoint. Full refresh only: `ended_at` and+ # `status` change after an incident is issued, and the only server-side filter is on `issued_at`.+ "incidents": LinearbEndpointConfig(+ name="incidents",+ path="/api/v1/incidents/search",+ method="POST",+ page_size_param="limit",+ page_size=100,+ request_body={+ "issued_at": {"after": INCIDENTS_ISSUED_AFTER},+ "sort_by": "issued_at",+ "sort_dir": "asc",+ },+ primary_keys=["provider_id"],+ partition_key="issued_at",+ ),# Measurements is a POST metric query rather than a list endpoint. It is plan-gated (LinearB# Business/Enterprise only), so it is off by default; users on an eligible plan opt in."measurements": LinearbEndpointConfig(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/source.pyindex e37493408984..8287cb9eeea5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/source.py@@ -48,7 +48,7 @@ class LinearbSource(ResumableSource[LinearbSourceConfig, LinearbResumeConfig]):releaseStatus=ReleaseStatus.ALPHA,caption="""Enter your LinearB API key to pull your engineering intelligence and DORA metrics into the PostHog Data warehouse.-Generate an API token from **Settings → API Tokens** in your [LinearB account](https://app.linearb.io/). The token grants access to your organization's teams, users, services, deployments, and computed metrics.+Generate an API token from **Settings → API Tokens** in your [LinearB account](https://app.linearb.io/). The token grants access to your organization's teams, users, services, deployments, incidents, and computed metrics.The **Measurements** table is only available on LinearB Business and Enterprise plans and is off by default — enable it if your plan includes API metrics access.""",iconPath="/static/services/linearb.png",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/tests/test_linearb.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/tests/test_linearb.pyindex 7cebe32eb776..f6a97d6eef06 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/tests/test_linearb.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linearb/tests/test_linearb.py@@ -79,7 +79,47 @@ class TestListPagination:manager.can_resume.return_value = Falsereturn manager- def test_paginates_until_total_reached(self) -> None:+ @pytest.mark.parametrize(+ ("config", "expected_requests"),+ [+ (+ _list_config(),+ [+ ("GET", {"params": {"page_size": 2, "offset": 0}, "json": None}),+ ("GET", {"params": {"page_size": 2, "offset": 2}, "json": None}),+ ],+ ),+ (+ LinearbEndpointConfig(+ name="incidents",+ path="/api/v1/incidents/search",+ method="POST",+ page_size_param="limit",+ page_size=2,+ request_body={"issued_at": {"after": "2000-01-01"}, "sort_by": "issued_at", "sort_dir": "asc"},+ ),+ [+ (+ "POST",+ {+ "params": None,+ "json": {+ "issued_at": {"after": "2000-01-01"},+ "sort_by": "issued_at",+ "sort_dir": "asc",+ "limit": 2,+ "offset": offset,+ },+ },+ )+ for offset in (0, 2)+ ],+ ),+ ],+ )+ def test_paginates_until_total_reached(+ self, config: LinearbEndpointConfig, expected_requests: list[tuple[str, dict[str, Any]]]+ ) -> None:# total=3 with page_size=2 -> a full page then a final short page.responses = [_response(payload={"total": 3, "items": [{"id": 1}, {"id": 2}]}),@@ -87,10 +127,13 @@ class TestListPagination:]session = _session_returning(responses)- pages = list(_iter_list_rows(session, {}, mock.MagicMock(), _list_config(), self._manager()))+ pages = list(_iter_list_rows(session, {}, mock.MagicMock(), config, self._manager()))assert [row["id"] for page in pages for row in page] == [1, 2, 3]- assert session.request.call_count == 2+ assert [+ (call.args[0], {"params": call.kwargs["params"], "json": call.kwargs["json"]})+ for call in session.request.call_args_list+ ] == expected_requestsdef test_stops_on_empty_page(self) -> None:session = _session_returning([_response(payload={"total": 0, "items": []})])