: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 cody user registry table (#113217)
Tom Owers63fa75b422fa
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 83703345705c..19c284cad175 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@@ -1830,13 +1830,13 @@ Note: Static endpoint list; no dynamic table discovery in products/warehouse_sou## Cody — adequate-Today (5): `credits`, `usage_by_user`, `usage_by_user_day`, `usage_by_user_day_client_language`, `usage_by_user_month`+Today (6): `credits`, `usage_by_user`, `usage_by_user_day`, `usage_by_user_day_client_language`, `usage_by_user_month`, `user_registry`Diffed against: <https://sourcegraph.com/docs/analytics/api.md>-No material gaps found.+- [x] `user_registry (GET /api/reports/user-registry)` — CSV snapshot of instance users with service account and site admin flags, documented after the sweep (medium)-Note: The Sourcegraph Analytics API has exactly two endpoints: GET /api/reports/by-user-client-date (granularity = by_user | by_user_month | by_user_day | by_user_day_client_language) and GET /api/credits. PostHog's five tables map 1:1 onto all four granularities plus credits, so coverage is complete. Note the docs page is client-rendered; the .md variant of the URL returns the full text.+Note: The Sourcegraph Analytics API has three endpoints: GET /api/reports/by-user-client-date (granularity = by_user | by_user_month | by_user_day | by_user_day_client_language), GET /api/reports/user-registry, and GET /api/credits. PostHog's six tables map 1:1 onto all four granularities plus the user registry and credits, so coverage is complete. Note the docs page is client-rendered; the .md variant of the URL returns the full text.## Cohere — gapsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/canonical_descriptions.pyindex cf58693b55ce..319c50721638 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/canonical_descriptions.py@@ -4,8 +4,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.can_DOCS_URL = "https://sourcegraph.com/docs/analytics/api"-# Table-level descriptions only: Sourcegraph doesn't publish the CSV column schema for these-# reports, so column descriptions are left to the LLM enrichment pass (which receives the+# Table-level descriptions only, except for the user registry: Sourcegraph doesn't publish the+# CSV column schema for the usage reports, so their column descriptions are left to the LLM enrichment pass (which receives the# docs_url below) rather than curated from guesses.CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"usage_by_user": {@@ -28,4 +28,13 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"description": "Credit bucket allocations and consumption for the Sourcegraph instance, filtered by each bucket's active period.","docs_url": _DOCS_URL,},+ "user_registry": {+ "description": "Current snapshot of the Sourcegraph instance's user registry, one row per user.",+ "docs_url": _DOCS_URL,+ "columns": {+ "instance_user_id": "The numeric ID assigned to the user by the Sourcegraph instance.",+ "service_account": "Whether the user is a service account (true or false).",+ "site_admin": "Whether the user is a site administrator (true or false).",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/cody.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/cody.pyindex f15735a0f845..bde5ac72f34c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/cody.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/cody.py@@ -41,7 +41,7 @@ class CodyCredentialsError(Exception):pass[email protected](frozen=True)class CodyResumeConfig:# ISO date (YYYY-MM-DD) of the first day of the calendar-month window to resume from.window_start: str@@ -299,9 +299,10 @@ def cody_source(return SourceResponse(name=endpoint,- # The CSV column names aren't published and can't be verified without an Enterprise- # token, so no primary keys are declared — every endpoint is full refresh (replace).+ # Most reports' CSV column names aren't published and can't be verified without an+ # Enterprise token, so only endpoints with documented columns declare primary keys.+ # Every endpoint is full refresh (replace).items=get_rows,- primary_keys=None,+ primary_keys=config.primary_keys,sort_mode="asc",)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/settings.pyindex a52a2a4601b2..9c673c489470 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/settings.py@@ -5,9 +5,10 @@ from products.warehouse_sources.backend.types import IncrementalFieldREPORTS_PATH = "/api/reports/by-user-client-date"CREDITS_PATH = "/api/credits"+USER_REGISTRY_PATH = "/api/reports/user-registry"-@dataclass+@dataclass(frozen=True)class CodyEndpointConfig:name: strpath: str@@ -21,6 +22,7 @@ class CodyEndpointConfig:# (including the date column an incremental cursor would track) aren't documented, so every# endpoint ships full refresh until the response schema can be verified against a live token.incremental_fields: list[IncrementalField] = field(default_factory=list)+ primary_keys: Optional[list[str]] = Nonedescription: Optional[str] = Noneshould_sync_default: bool = True@@ -60,6 +62,13 @@ CODY_ENDPOINTS: dict[str, CodyEndpointConfig] = {path=CREDITS_PATH,description="Credit bucket allocations and consumption for the instance. Full refresh only",),+ "user_registry": CodyEndpointConfig(+ name="user_registry",+ path=USER_REGISTRY_PATH,+ # The only Cody export with documented CSV columns; `Instance user ID` normalizes to this.+ primary_keys=["instance_user_id"],+ description="Current snapshot of the instance's users, with service account and site admin flags. Full refresh only",+ ),}ENDPOINTS = tuple(CODY_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody.pyindex 6d5390396df8..5759206e4d8c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody.py@@ -227,7 +227,6 @@ class TestCodyTransport:response = cody_source("token", "example.com", endpoint, mock.Mock(), _manager())assert response.name == endpoint- assert response.primary_keys is Noneassert response.sort_mode == "asc"@parameterized.expand(@@ -251,17 +250,31 @@ class TestCodyTransport:assert params == {"instanceURL": ["example.com"], "granularity": [granularity]}manager.save_state.assert_not_called()- def test_credits_requests_without_granularity(self):+ @parameterized.expand(+ [+ ("credits", "/api/credits", "id,amount\nb1,10\n", {"id": "b1", "amount": "10"}),+ (+ "user_registry",+ "/api/reports/user-registry",+ "Instance user ID,Service Account,Site Admin\n42,false,true\n",+ {"instance_user_id": "42", "service_account": "false", "site_admin": "true"},+ ),+ ]+ )+ def test_non_report_endpoints_request_without_granularity(self, endpoint, path, body, expected_row):session = mock.Mock()- session.get.return_value = _response(200, text="id,amount\nb1,10\n")+ session.get.return_value = _response(200, text=body)with mock.patch.object(cody, "make_tracked_session", return_value=session):- batches = list(_batches(cody_source("token", "example.com", "credits", mock.Mock(), _manager())))+ response = cody_source("token", "example.com", endpoint, mock.Mock(), _manager())+ batches = list(_batches(response))- assert batches == [[{"id": "b1", "amount": "10"}]]+ assert batches == [[expected_row]]+ # A primary key the normalized CSV headers never produce would fail every merge.+ assert set(response.primary_keys or []) <= expected_row.keys()url = session.get.call_args.args[0]- assert url.startswith(f"{cody.CODY_BASE_URL}/api/credits?")- assert "granularity" not in url+ assert url.startswith(f"{cody.CODY_BASE_URL}{path}?")+ assert parse_qs(urlparse(url).query) == {"instanceURL": ["example.com"]}# Reports must stay streamed — buffering the whole body lets a huge report OOM the worker.assert session.get.call_args.kwargs["stream"] is Truediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody_source.pyindex fcaa45df47df..03b5d2ed4b41 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cody/tests/test_cody_source.py@@ -18,6 +18,7 @@ ALL_ENDPOINTS = ["usage_by_user_day","usage_by_user_day_client_language","credits",+ "user_registry",]