: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 Vercel deployment check runs table (#79893)
posthog[bot]2ac99acbd88e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.pyindex 0f8c92339fce..632241894de4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py@@ -85,6 +85,22 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"deploymentId": "Identifier of the deployment the alias points to.",},},+ "check_runs": {+ "description": "A Vercel check run: one pass/fail gate (a build check or CI integration) that ran against a deployment. Where a deployment's state only reports that it failed, check runs report which gate failed.",+ "docs_url": "https://vercel.com/docs/rest-api/reference/endpoints/checks-v2/list-check-runs-for-a-deployment",+ "columns": {+ "id": "Unique identifier for the check run.",+ "deploymentId": "Identifier of the deployment the check run ran against.",+ "name": "Display name of the check run.",+ "ownerId": "Identifier of the user or team that owns the check run.",+ "source": "Where the check run originated, such as the integration or Vercel CI that produced it.",+ "status": "Lifecycle state of the check run: registered, running, or completed.",+ "checkId": "Identifier of the project-level check definition this run belongs to. Absent for Vercel CI runs that have no parent check.",+ "timeout": "Time in milliseconds after which the check run is considered timed out.",+ "createdAt": "Time the check run was created, as a Unix timestamp in milliseconds.",+ "updatedAt": "Time the check run was last updated, as a Unix timestamp in milliseconds.",+ },+ },# Column keys are the normalized (snake_case) names the columns land under in the warehouse, not# the PascalCase FOCUS field names from the API."billing_charges": {diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.pyindex 83b7dfbab0cb..46523068cb3b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py@@ -48,6 +48,14 @@ class VercelEndpointConfig:cursor_from_field: Optional[str] = None# Static query params this endpoint needs on every request, merged over the shared ones.extra_params: dict[str, str] = field(default_factory=dict)+ # Fan-out: this endpoint is a child fetched once per row of `fan_out_parent`. `path` carries a+ # `{fan_out_path_param}` placeholder filled from each parent row's `fan_out_parent_field`. Fan-out+ # endpoints are full refresh only (Vercel documents no server-side time filter on them) and+ # non-resumable: a re-run re-fans over every parent and the pipeline's full-refresh replace+ # rewrites the table. None means this is a flat top-level list handled by the paginating transport.+ fan_out_parent: Optional[str] = None+ fan_out_path_param: Optional[str] = None+ fan_out_parent_field: str = "uid"# Charges get restated after they first post (usage finalization, plus adjustments, credits, and tax@@ -148,6 +156,23 @@ VERCEL_ENDPOINTS: dict[str, VercelEndpointConfig] = {response_data_key="aliases",primary_key="uid",),+ # First fan-out endpoint in this source: one GET /v2/deployments/{deploymentId}/check-runs per+ # deployment already synced by the `deployments` table. Check runs are the structured pass/fail+ # gates (build checks, CI integrations) that ran against a deployment, each with its own status,+ # so they answer *which* gate failed where the deployment's own `state` only says *that* it did.+ # The response is {"runs": [...]} with no pagination envelope and no documented server-side time+ # filter, so it's full refresh. Every run row already carries `deploymentId`, so no parent field+ # is injected. `createdAt`/`updatedAt` are Unix ms, so this stays unpartitioned like `events` and+ # `deployments` (the datetime partitioner reads a raw int as seconds and raises on a ms value).+ "check_runs": VercelEndpointConfig(+ name="check_runs",+ path="/v2/deployments/{deploymentId}/check-runs",+ response_data_key="runs",+ primary_key="id",+ fan_out_parent="deployments",+ fan_out_path_param="deploymentId",+ fan_out_parent_field="uid",+ ),# Team billing usage & cost, in the FOCUS v1.3 open cost-and-usage standard. Streamed as JSONL# over a `from`/`to` window at 1-day granularity. FOCUS records carry no natural id, so the# transport synthesizes a stable `id` from the charge period plus its billing dimensions (seediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.pyindex c92d37849ee9..46311e720140 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py@@ -50,7 +50,7 @@ class VercelSource(ResumableSource[VercelSourceConfig, VercelResumeConfig]):category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,label="Vercel",releaseStatus=ReleaseStatus.BETA,- caption="""Enter a Vercel access token to pull your Vercel deployments, projects, teams, domains, aliases, and billing usage into the PostHog Data warehouse.+ caption="""Enter a Vercel access token to pull your Vercel deployments, deployment check runs, projects, teams, domains, aliases, and billing usage into the PostHog Data warehouse.Create an access token in your [Vercel account settings](https://vercel.com/account/tokens). A read-only token is sufficient.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.pyindex 80d063da0be7..f03aa52ac710 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py@@ -340,6 +340,79 @@ class TestGetRows:assert manager.saved == [VercelResumeConfig(until=200)]+def _collect_fanout(monkeypatch: Any, responses: list[dict], team_id: str | None = None):+ calls = _patch_fetch(monkeypatch, responses)+ rows: list[dict] = []+ for table in vercel.get_fanout_rows(access_token="t", endpoint="check_runs", team_id=team_id, logger=MagicMock()):+ rows.extend(table.to_pylist())+ return rows, calls+++class TestGetFanoutRows:+ def test_fans_out_one_child_request_per_parent_deployment(self, monkeypatch: Any) -> None:+ responses: list[dict] = [+ {+ "deployments": [{"uid": "d1", "created": 200}, {"uid": "d2", "created": 100}],+ "pagination": {"next": None},+ },+ {"runs": [{"id": "r1", "deploymentId": "d1"}]},+ {"runs": [{"id": "r2", "deploymentId": "d2"}, {"id": "r3", "deploymentId": "d2"}]},+ ]+ rows, calls = _collect_fanout(monkeypatch, responses, team_id="team_1")++ assert [r["id"] for r in rows] == ["r1", "r2", "r3"]+ # The parent is paged from the deployments endpoint; each child request fills the deployment+ # id into the check-runs path and carries teamId.+ assert "/v6/deployments" in calls[0]+ assert "/v2/deployments/d1/check-runs" in calls[1]+ assert "/v2/deployments/d2/check-runs" in calls[2]+ assert "teamId=team_1" in calls[1]+ # The check-runs endpoint documents no limit/pagination params, so the shared `limit` must+ # not be appended to the child request.+ assert "limit=" not in calls[1]++ def test_deployment_with_no_check_runs_still_visits_every_parent(self, monkeypatch: Any) -> None:+ responses: list[dict] = [+ {+ "deployments": [{"uid": "d1", "created": 200}, {"uid": "d2", "created": 100}],+ "pagination": {"next": None},+ },+ {"runs": []},+ {"runs": [{"id": "r2", "deploymentId": "d2"}]},+ ]+ rows, calls = _collect_fanout(monkeypatch, responses)++ assert [r["id"] for r in rows] == ["r2"]+ assert len(calls) == 3++ def test_parent_row_missing_the_fan_out_field_is_skipped(self, monkeypatch: Any) -> None:+ # A deployment row without `uid` can't seed a child path; skip it rather than crash the sync.+ responses: list[dict] = [+ {"deployments": [{"uid": "d1", "created": 200}, {"created": 100}], "pagination": {"next": None}},+ {"runs": [{"id": "r1", "deploymentId": "d1"}]},+ ]+ rows, calls = _collect_fanout(monkeypatch, responses)++ assert [r["id"] for r in rows] == ["r1"]+ # Only the uid-bearing parent issues a child request.+ assert len(calls) == 2++ def test_fans_out_across_every_parent_page(self, monkeypatch: Any) -> None:+ # The parent deployments list paginates; the fan-out must visit deployments from every page,+ # not silently cap the child table at the first page of parents.+ responses: list[dict] = [+ {"deployments": [{"uid": "d1", "created": 300}], "pagination": {"next": 300}},+ {"runs": [{"id": "r1", "deploymentId": "d1"}]},+ {"deployments": [{"uid": "d2", "created": 100}], "pagination": {"next": None}},+ {"runs": [{"id": "r2", "deploymentId": "d2"}]},+ ]+ rows, calls = _collect_fanout(monkeypatch, responses)++ assert [r["id"] for r in rows] == ["r1", "r2"]+ # Page two of the parent is requested with the first page's cursor.+ assert "until=300" in calls[2]++class TestVercelSource:@parameterized.expand([@@ -349,6 +422,7 @@ class TestVercelSource:("teams", "id"),("domains", "id"),("aliases", "uid"),+ ("check_runs", "id"),])def test_source_response_primary_key_and_sort(self, endpoint: str, expected_pk: str) -> None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.pyindex 5d83084dede4..261a224292f6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py@@ -72,6 +72,7 @@ class TestVercelSource:"teams","domains","aliases",+ "check_runs","billing_charges",}@@ -98,7 +99,9 @@ class TestVercelSource:assert billing.incremental_fields[0]["field_type"] == IncrementalFieldType.DateTimeassert billing.default_incremental_lookback_seconds == 60 * 60 * 24 * 35- for full_refresh in ("projects", "teams", "domains", "aliases"):+ # check_runs is a full-refresh fan-out over deployments: Vercel documents no server-side time+ # filter on the check-runs endpoint, so it re-fans every sync with no incremental cursor.+ for full_refresh in ("projects", "teams", "domains", "aliases", "check_runs"):assert schemas[full_refresh].supports_incremental is Falseassert schemas[full_refresh].supports_append is Falseassert schemas[full_refresh].incremental_fields == []diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.pyindex aa6324a834fa..bd25d1b5cc5a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py@@ -254,6 +254,88 @@ def get_rows(yield batcher.get_table()+def _iter_parent_rows(+ session: requests.Session,+ config: VercelEndpointConfig,+ team_id: str | None,+ headers: dict[str, str],+ logger: FilteringBoundLogger,+) -> Iterator[dict[str, Any]]:+ """Page a flat parent endpoint to completion and yield every row, for a fan-out child to seed+ its per-parent requests from. Full refresh: no incremental cutoff is applied, so every parent is+ visited each sync. Reuses the same cursor model as `get_rows` (walk `pagination.next` back as+ `until`, or derive it from the oldest row when the endpoint carries no envelope)."""+ until: int | None = None+ page_count = 0+ while True:+ url = _build_url(config.path, _build_params(config, team_id, None, until))+ data = _fetch_page(session, url, headers, logger)++ items = data.get(config.response_data_key) or []+ if not items:+ return+ yield from items++ next_until = (data.get("pagination") or {}).get("next")+ if next_until is None and config.cursor_from_field:+ next_until = _cursor_from_page(items, config.cursor_from_field)++ page_count += 1+ if next_until is None:+ return+ if next_until == until:+ logger.warning(f"Vercel: {config.name} pagination cursor did not advance (until={until}); stopping")+ return+ if page_count >= MAX_PAGES:+ logger.warning(f"Vercel: {config.name} hit MAX_PAGES={MAX_PAGES}; remaining pages skipped")+ return+ until = next_until+++def get_fanout_rows(+ access_token: str,+ endpoint: str,+ team_id: str | None,+ logger: FilteringBoundLogger,+) -> Iterator[Any]:+ """Fan out a child endpoint over every row of its parent: page the parent to completion, then+ issue one GET per parent id with the id filled into the child path's `{fan_out_path_param}`.++ Full refresh only. The child endpoint (check_runs) returns its whole list in one response with no+ pagination envelope, so each per-parent call is a single fetch. A parent row missing the fan-out+ field is skipped rather than crashing the sync."""+ config = VERCEL_ENDPOINTS[endpoint]+ assert config.fan_out_parent is not None and config.fan_out_path_param is not None+ parent_config = VERCEL_ENDPOINTS[config.fan_out_parent]+ headers = _get_headers(access_token)+ batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)+ session = make_tracked_session()++ try:+ for parent in _iter_parent_rows(session, parent_config, team_id, headers, logger):+ parent_id = parent.get(config.fan_out_parent_field)+ if parent_id is None:+ continue++ child_path = config.path.format(**{config.fan_out_path_param: parent_id})+ # The child endpoint documents no `limit`/pagination params, so build a minimal param set+ # rather than reusing `_build_params` (which always appends `limit`).+ params: dict[str, Any] = {**config.extra_params}+ if config.team_scoped and team_id:+ params["teamId"] = team_id++ data = _fetch_page(session, _build_url(child_path, params), headers, logger)+ for item in data.get(config.response_data_key) or []:+ batcher.batch(item)+ if batcher.should_yield():+ yield batcher.get_table()++ if batcher.should_yield(include_incomplete_chunk=True):+ yield batcher.get_table()+ finally:+ session.close()++def _iso8601_utc(moment: datetime) -> str:"""Vercel's billing window params want ISO 8601 UTC with a trailing Z, e.g.2025-01-01T00:00:00.000Z."""@@ -421,6 +503,21 @@ def vercel_source(partition_keys=[endpoint_config.partition_key] if endpoint_config.partition_key else None,)+ if endpoint_config.fan_out_parent is not None:+ return SourceResponse(+ name=endpoint,+ items=lambda: get_fanout_rows(+ access_token=access_token,+ endpoint=endpoint,+ team_id=team_id,+ logger=logger,+ ),+ primary_keys=[endpoint_config.primary_key],+ # Full-refresh fan-out with no incremental field, so sort_mode drives no watermark; kept+ # consistent with the resource endpoints below.+ sort_mode="desc",+ )+return SourceResponse(name=endpoint,items=lambda: get_rows(