: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 digitalocean project, dns and database tables (#105906)
Tom Owerseabffb0cab49
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 1d45a813712f..84cb849a8021 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@@ -2492,13 +2492,13 @@ Diffed against: <https://api-engineering.nyc3.cdn.digitaloceanspaces.com/spec-ci- [x] `/v2/customers/my/invoices/{invoice_uuid} (invoice items) and /invoices/{invoice_uuid}/summary` — per-resource invoice line items; invoices are synced as headers only, so spend cannot be attributed to droplets or databases (high)- [x] `/v2/sizes` — lookup resolving the droplet size slug on every droplet into vCPU, memory, disk and hourly/monthly price (high)- [x] `/v2/regions` — lookup resolving the region slug carried by droplets, databases, load balancers and volumes (high)-- [ ] `/v2/projects/{project_id}/resources (and /v2/projects/default/resources)` — the join table mapping every synced resource URN to a project — projects are synced but the membership is not (high)+- [x] `/v2/projects/{project_id}/resources (and /v2/projects/default/resources)` — the join table mapping every synced resource URN to a project — projects are synced but the membership is not (high) — added as `project_resources` (`/v2/projects/default/resources` is an alias for the project flagged `is_default`, which the fan-out over `/v2/projects` already visits)- [x] `/v2/actions (and /v2/droplets/{droplet_id}/actions)` — account-wide action history: creates, resizes, power cycles with status and timing — the state-transition log for infrastructure (high)- [ ] `/v2/apps/{app_id}/deployments (+ /v2/apps/{app_id}/events)` — App Platform deployment history and phase transitions; apps are synced but not their deploy activity (medium)- [ ] `/v2/kubernetes/clusters/{cluster_id}/node_pools` — node pool sizing per cluster, needed to explain Kubernetes cost and capacity (medium)-- [ ] `/v2/tags/{tag_id}/resources` — resolves tags (already synced as names) to the resources they are applied to (medium)-- [ ] `/v2/domains/{domain_name}/records` — DNS records under the domains already synced (medium)-- [ ] `/v2/databases/{database_cluster_uuid}/backups and /v2/databases/{database_cluster_uuid}/events` — backup inventory and cluster event history for managed databases (medium)+- [ ] `/v2/tags/{tag_id}/resources` — resolves tags (already synced as names) to the resources they are applied to (medium) — not buildable: the spec exposes only POST and DELETE on this path, so tag membership cannot be read back. `/v2/tags` carries per-resource-type counts and a `last_tagged_uri`, which is the closest available data and is already synced.+- [x] `/v2/domains/{domain_name}/records` — DNS records under the domains already synced (medium) — added as `domain_records`+- [x] `/v2/databases/{database_cluster_uuid}/backups and /v2/databases/{database_cluster_uuid}/events` — backup inventory and cluster event history for managed databases (medium) — added as `database_backups` and `database_events`- [ ] `/v2/uptime/checks (+ /checks/{check_id}/state)` — uptime check inventory and current state for availability reporting (low)- [ ] `/v2/registry/{registry_name}/repositories (+ /tags, /digests)` — container registry repository and tag inventory with sizes (low)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/canonical_descriptions.pyindex 42646aa40216..49745d88dd9c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/canonical_descriptions.py@@ -276,4 +276,53 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"credits_and_adjustments": "Credits and adjustments contributing to the invoice.",},},+ "project_resources": {+ "description": "Membership table mapping each resource URN to the project it is assigned to.",+ "docs_url": "https://docs.digitalocean.com/reference/api/api-reference/#tag/Project-Resources",+ "columns": {+ "project_id": "UUID of the project the resource belongs to, taken from the parent project.",+ "urn": "Uniform resource name of the assigned resource, such as `do:droplet:13457723`.",+ "assigned_at": "Time the resource was assigned to the project (ISO 8601).",+ "links": "Links object whose `self` URI retrieves the resource.",+ "status": "Status of assigning and fetching the resource (e.g. ok, not_found).",+ },+ },+ "domain_records": {+ "description": "DNS records configured under each domain in the account.",+ "docs_url": "https://docs.digitalocean.com/reference/api/api-reference/#tag/Domain-Records",+ "columns": {+ "domain_name": "Name of the domain the record belongs to, taken from the parent domain.",+ "id": "Identifier of the record, unique within its domain.",+ "type": "Type of the DNS record (e.g. A, CNAME, MX, TXT).",+ "name": "Host name, alias, or service the record defines.",+ "data": "Value of the record, which varies by record type.",+ "priority": "Priority for SRV and MX records, null for other types.",+ "port": "Port for SRV records, null for other types.",+ "ttl": "Time to live for the record, in seconds.",+ "weight": "Weight for SRV records, null for other types.",+ "flags": "Unsigned integer between 0 and 255 used by CAA records.",+ "tag": "Parameter tag for CAA records (issue, issuewild, or iodef).",+ },+ },+ "database_backups": {+ "description": "Backups available for each managed database cluster. Caching and Valkey clusters have none.",+ "docs_url": "https://docs.digitalocean.com/reference/api/api-reference/#tag/Databases",+ "columns": {+ "database_cluster_uuid": "UUID of the cluster the backup belongs to, taken from the parent cluster.",+ "created_at": "Time the backup was created (ISO 8601).",+ "size_gigabytes": "Size of the backup, in gigabytes.",+ "incremental": "Whether the backup is incremental rather than full. MySQL only.",+ },+ },+ "database_events": {+ "description": "Event log for each managed database cluster, covering creates, updates, maintenance, and power cycles.",+ "docs_url": "https://docs.digitalocean.com/reference/api/api-reference/#tag/Databases",+ "columns": {+ "database_cluster_uuid": "UUID of the cluster the event belongs to, taken from the parent cluster.",+ "id": "Identifier of the event.",+ "cluster_name": "Name of the cluster the event was recorded on.",+ "event_type": "Type of the event (e.g. cluster_create, cluster_maintenance_perform).",+ "create_time": "Time the event was generated (ISO 8601).",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/settings.pyindex d94858a37626..2dbf2fe16028 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/settings.py@@ -253,6 +253,97 @@ DIGITALOCEAN_ENDPOINTS: dict[str, DigitalOceanEndpointConfig] = {parent_params={"per_page": PAGE_SIZE},),),+ # The join table between projects and everything in them: `/v2/projects` syncs the project+ # headers, but membership only exists behind this per-project endpoint. Resources are+ # identified by URN (`do:droplet:13457723`), which resolves against the id columns already+ # synced on droplets, databases, volumes and the rest.+ # `/v2/projects/default/resources` is an alias for whichever project carries `is_default`,+ # and that project is in the `/v2/projects` listing, so fanning out over every project+ # already covers it.+ "project_resources": DigitalOceanEndpointConfig(+ name="project_resources",+ path="/v2/projects/{project_id}/resources",+ data_selector="resources",+ # A resource sits in one project at a time, but the API does not document the URN as+ # unique across the whole fan-out, so the parent id is part of the key.+ primary_keys=["project_id", "urn"],+ partition_key="assigned_at",+ fanout=DependentEndpointConfig(+ parent_name="projects",+ resolve_param="project_id",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "project_id"},+ parent_params={"per_page": PAGE_SIZE},+ child_params={"per_page": PAGE_SIZE},+ ),+ ),+ # DNS records under each synced domain. The domain itself is only a name, so the records+ # are where the zone's actual contents live.+ "domain_records": DigitalOceanEndpointConfig(+ name="domain_records",+ path="/v2/domains/{domain_name}/records",+ data_selector="domain_records",+ # The record id is documented as unique per domain, not across the account.+ primary_keys=["domain_name", "id"],+ fanout=DependentEndpointConfig(+ parent_name="domains",+ resolve_param="domain_name",+ resolve_field="name",+ include_from_parent=["name"],+ # Renamed off the parent prefix, and away from the record's own `name` column,+ # which holds the host part of the record rather than the zone.+ parent_field_renames={"name": "domain_name"},+ parent_params={"per_page": PAGE_SIZE},+ child_params={"per_page": PAGE_SIZE},+ ),+ ),+ # Backup inventory per managed database cluster, so retention and backup size can be read+ # alongside the cluster metadata. The endpoint takes no page params and returns the whole+ # list in one response.+ "database_backups": DigitalOceanEndpointConfig(+ name="database_backups",+ path="/v2/databases/{database_cluster_uuid}/backups",+ data_selector="backups",+ # A backup record has no id of its own; it is identified by when it was taken.+ primary_keys=["database_cluster_uuid", "created_at"],+ partition_key="created_at",+ # Both legs of the fan-out share one session, and the parent leg is `/v2/databases`,+ # whose response embeds live connection URIs and passwords.+ captures_http_samples=False,+ fanout=DependentEndpointConfig(+ parent_name="databases",+ resolve_param="database_cluster_uuid",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "database_cluster_uuid"},+ parent_params={"per_page": PAGE_SIZE},+ # Caching and Valkey clusters do not support backups, and the fan-out visits every+ # cluster the account has. Treating the endpoint's documented not-found response as+ # an empty page keeps one such cluster from failing the whole table.+ child_response_actions=[{"status_code": 404, "action": "ignore"}],+ ),+ ),+ # Cluster event history (create, update, maintenance, failover, power cycles) — the+ # state-transition log for managed databases, which `/v2/actions` does not cover.+ "database_events": DigitalOceanEndpointConfig(+ name="database_events",+ path="/v2/databases/{database_cluster_uuid}/events",+ data_selector="events",+ # The event id is only documented as identifying the event within its cluster.+ primary_keys=["database_cluster_uuid", "id"],+ partition_key="create_time",+ # Same shared-session reason as `database_backups`: the parent leg is `/v2/databases`.+ captures_http_samples=False,+ fanout=DependentEndpointConfig(+ parent_name="databases",+ resolve_param="database_cluster_uuid",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "database_cluster_uuid"},+ parent_params={"per_page": PAGE_SIZE},+ ),+ ),}ENDPOINTS = tuple(DIGITALOCEAN_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean.py b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean.pyindex 8e7dee1ac7b3..e06d69996356 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean.py@@ -20,6 +20,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.digitaloceTOP_LEVEL_ENDPOINTS = [name for name, config in DIGITALOCEAN_ENDPOINTS.items() if config.fanout is None]INVOICE_UUID = "22737513-0ea7-4206-8ceb-98a575af7681"+PROJECT_ID = "4e1bfbc3-dc3e-41f2-a18f-1b4d7ba71679"+DATABASE_UUID = "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30"def _make_response(json_body: dict[str, Any] | None = None, status_code: int = 200) -> Response:@@ -34,6 +36,11 @@ def _endpoint(resource: Any) -> dict[str, Any]:return cast(dict[str, Any], resource["endpoint"])+def _rows(endpoint: str) -> list[dict[str, Any]]:+ resource = digitalocean_source("dop_v1_token", endpoint, team_id=1, job_id="job-1")+ return [row for page in resource for row in page]++class TestDigitalOceanPaginator:def test_advances_on_next_page_url(self) -> None:# DigitalOcean nests the next-page URL under links.pages.next; a page that has one must@@ -153,6 +160,8 @@ class TestDigitalOceanSensitiveFields:pytest.param("databases", True, id="secrets_in_the_response"),pytest.param("invoice_summaries", True, id="billing_identity_in_the_response"),pytest.param("invoice_items", True, id="resource_level_spend_in_the_response"),+ pytest.param("database_backups", True, id="secrets_in_the_fanout_parent_response"),+ pytest.param("database_events", True, id="secrets_in_the_other_fanout_parent_response"),pytest.param("droplets", False, id="nothing_to_withhold"),],)@@ -214,10 +223,6 @@ class TestDigitalOceanValidateCredentials:class TestDigitalOceanInvoiceFanout:- def _rows(self, endpoint: str) -> list[dict[str, Any]]:- resource = digitalocean_source("dop_v1_token", endpoint, team_id=1, job_id="job-1")- return [row for page in resource for row in page]-def _mock_invoice_list(self, requests_mock: Any) -> None:requests_mock.get(f"{DIGITALOCEAN_BASE_URL}/v2/customers/my/invoices",@@ -233,7 +238,7 @@ class TestDigitalOceanInvoiceFanout:json={"invoice_items": [{"product": "Droplets", "amount": "12.34"}]},)- assert self._rows("invoice_items") == [{"product": "Droplets", "amount": "12.34", "invoice_uuid": INVOICE_UUID}]+ assert _rows("invoice_items") == [{"product": "Droplets", "amount": "12.34", "invoice_uuid": INVOICE_UUID}]def test_invoice_items_paginate_within_one_invoice(self, requests_mock: Any) -> None:# An invoice with hundreds of resources spans pages; the child must follow@@ -248,7 +253,7 @@ class TestDigitalOceanInvoiceFanout:],)- assert [row["product"] for row in self._rows("invoice_items")] == ["Droplets", "Spaces"]+ assert [row["product"] for row in _rows("invoice_items")] == ["Droplets", "Spaces"]@pytest.mark.parametrize("summary",@@ -267,7 +272,7 @@ class TestDigitalOceanInvoiceFanout:self._mock_invoice_list(requests_mock)requests_mock.get(f"{DIGITALOCEAN_BASE_URL}/v2/customers/my/invoices/{INVOICE_UUID}/summary", json=summary)- assert self._rows("invoice_summaries") == [{**summary, "invoice_uuid": INVOICE_UUID}]+ assert _rows("invoice_summaries") == [{**summary, "invoice_uuid": INVOICE_UUID}]def test_both_sides_of_the_fanout_ask_for_the_max_page(self, requests_mock: Any) -> None:# The fan-out helper is wired with no page-size param of its own, so `per_page` rides on@@ -278,7 +283,103 @@ class TestDigitalOceanInvoiceFanout:json={"invoices": [{"invoice_uuid": INVOICE_UUID}]},)items = requests_mock.get(f"{DIGITALOCEAN_BASE_URL}/v2/customers/my/invoices/{INVOICE_UUID}", json={})- self._rows("invoice_items")+ _rows("invoice_items")assert invoices.last_request.qs["per_page"] == [str(PAGE_SIZE)]assert items.last_request.qs["per_page"] == [str(PAGE_SIZE)]+++class TestDigitalOceanResourceFanouts:+ def test_project_resources_carry_their_parent_project_id(self, requests_mock: Any) -> None:+ # A resource row is only a URN and an assignment time; without the parent projection+ # (and its rename off the `_projects_` prefix) there is no project column to join on,+ # which is the whole point of the table.+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/projects",+ json={"projects": [{"id": PROJECT_ID, "name": "web", "is_default": True}]},+ )+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/projects/{PROJECT_ID}/resources",+ json={"resources": [{"urn": "do:droplet:13457723", "assigned_at": "2018-09-28T19:26:37Z"}]},+ )++ assert _rows("project_resources") == [+ {"urn": "do:droplet:13457723", "assigned_at": "2018-09-28T19:26:37Z", "project_id": PROJECT_ID}+ ]++ def test_domain_records_keep_their_own_name_alongside_the_zone(self, requests_mock: Any) -> None:+ # A record's `name` is the host part, while the parent's `name` is the zone. Projecting+ # the parent onto `domain_name` keeps both; renaming it to `name` would overwrite the host.+ requests_mock.get(f"{DIGITALOCEAN_BASE_URL}/v2/domains", json={"domains": [{"name": "example.com"}]})+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/domains/example.com/records",+ json={"domain_records": [{"id": 28448429, "type": "A", "name": "www", "data": "1.2.3.4"}]},+ )++ assert _rows("domain_records") == [+ {"id": 28448429, "type": "A", "name": "www", "data": "1.2.3.4", "domain_name": "example.com"}+ ]++ @pytest.mark.parametrize(+ "endpoint,child_path,child_body,expected",+ [+ pytest.param(+ "database_backups",+ "backups",+ {"backups": [{"created_at": "2019-01-11T18:42:27Z", "size_gigabytes": 0.03}]},+ {"created_at": "2019-01-11T18:42:27Z", "size_gigabytes": 0.03, "database_cluster_uuid": DATABASE_UUID},+ id="backups",+ ),+ pytest.param(+ "database_events",+ "events",+ {"events": [{"id": "pe8u2huh", "event_type": "cluster_create"}]},+ {"id": "pe8u2huh", "event_type": "cluster_create", "database_cluster_uuid": DATABASE_UUID},+ id="events",+ ),+ ],+ )+ def test_database_children_key_on_their_cluster_without_inheriting_its_credentials(+ self, requests_mock: Any, endpoint: str, child_path: str, child_body: dict[str, Any], expected: dict[str, Any]+ ) -> None:+ # A backup has no id at all and an event id is only unique within its cluster, so the+ # cluster uuid has to reach every row or the primary key collapses across clusters. The+ # parent is `/v2/databases`, which carries connection URIs and passwords, so the+ # projection must stay narrow enough that none of them ride along into the child table.+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/databases",+ json={+ "databases": [+ {+ "id": DATABASE_UUID,+ "name": "prod-pg",+ "connection": {"uri": "postgresql://doadmin:secret@host:25060/defaultdb"},+ }+ ]+ },+ )+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/databases/{DATABASE_UUID}/{child_path}",+ json=child_body,+ )++ assert _rows(endpoint) == [expected]++ def test_a_cluster_without_backups_does_not_fail_the_table(self, requests_mock: Any) -> None:+ # Caching and Valkey clusters support no backups, and the fan-out visits every cluster+ # on the account. Without the 404 action, one such cluster fails the whole sync for a+ # team whose other clusters back up fine.+ valkey_uuid = "0b1f8d3a-1c2e-4f5a-9b7c-2d3e4f5a6b7c"+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/databases",+ json={"databases": [{"id": valkey_uuid, "engine": "valkey"}, {"id": DATABASE_UUID, "engine": "pg"}]},+ )+ requests_mock.get(f"{DIGITALOCEAN_BASE_URL}/v2/databases/{valkey_uuid}/backups", status_code=404, json={})+ requests_mock.get(+ f"{DIGITALOCEAN_BASE_URL}/v2/databases/{DATABASE_UUID}/backups",+ json={"backups": [{"created_at": "2019-01-11T18:42:27Z", "size_gigabytes": 0.03}]},+ )++ assert _rows("database_backups") == [+ {"created_at": "2019-01-11T18:42:27Z", "size_gigabytes": 0.03, "database_cluster_uuid": DATABASE_UUID}+ ]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean_source.pyindex e9aab1de48a8..636f40a2df1f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/digitalocean/tests/test_digitalocean_source.py@@ -78,22 +78,36 @@ class TestDigitalOceanValidateCredentials:class TestDigitalOceanSourceForPipeline:@pytest.mark.parametrize(- "endpoint,expected_pk,expects_partition",+ "endpoint,expected_pk,expected_partition_key",[- pytest.param("droplets", ["id"], True, id="droplets_id_pk_partitioned"),- pytest.param("domains", ["name"], False, id="domains_name_pk_no_partition"),- pytest.param("reserved_ips", ["ip"], False, id="reserved_ips_ip_pk_no_partition"),+ pytest.param("droplets", ["id"], "created_at", id="droplets_id_pk_partitioned"),+ pytest.param("domains", ["name"], None, id="domains_name_pk_no_partition"),+ pytest.param("reserved_ips", ["ip"], None, id="reserved_ips_ip_pk_no_partition"),pytest.param("billing_history",["date", "type", "amount", "description"],- False,+ None,id="billing_history_composite_pk",),+ # Fan-out children key on their parent as well as their own id, because neither a+ # DNS record id nor a database event id is documented as unique across parents, and+ # a backup has no id at all.+ pytest.param("project_resources", ["project_id", "urn"], "assigned_at", id="project_resources_parent_pk"),+ pytest.param("domain_records", ["domain_name", "id"], None, id="domain_records_parent_pk"),+ pytest.param(+ "database_backups",+ ["database_cluster_uuid", "created_at"],+ "created_at",+ id="database_backups_parent_pk",+ ),+ pytest.param(+ "database_events", ["database_cluster_uuid", "id"], "create_time", id="database_events_parent_pk"+ ),],)@patch("products.warehouse_sources.backend.temporal.data_imports.sources.digitalocean.source.digitalocean_source")def test_plumbs_primary_keys_and_partitioning(- self, mock_source: MagicMock, endpoint: str, expected_pk: list[str], expects_partition: bool+ self, mock_source: MagicMock, endpoint: str, expected_pk: list[str], expected_partition_key: str | None) -> None:resource = MagicMock()resource.name = endpoint@@ -109,10 +123,10 @@ class TestDigitalOceanSourceForPipeline:assert response.name == endpointassert response.primary_keys == expected_pk- if expects_partition:- # Partition only on the stable created_at timestamp, never on keyless resources.+ if expected_partition_key:+ # Partition only on a stable creation timestamp, never on keyless resources.assert response.partition_mode == "datetime"- assert response.partition_keys == ["created_at"]+ assert response.partition_keys == [expected_partition_key]else:assert response.partition_mode is None