Skip to content

: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.

feat(data-warehouse): add 4 missing tables to the Secoda source (#117522)

Tom Owerse42853e2aeaa
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.md
index 3a06263916ba..9a917eeb33d3 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
@@ -10566,10 +10566,10 @@ Today (6): `collections`, `columns`, `groups`, `tables`, `tags`, `users`
Diffed against: <https://docs.secoda.co/llms.txt>
-- [ ] `databases (GET /api/v1/database/databases)` — top of the asset hierarchy; lookup resolving the parent of every schema and table already synced (high)
-- [ ] `schemas (GET /api/v1/database/schemas)` — lookup resolving the schema id carried on every synced table (high)
-- [ ] `integrations (GET /api/v1/integration/integrations)` — lookup resolving the integration id present on every resource, i.e. which source system an asset came from (high)
-- [ ] `lineage (GET /api/v1/lineage/manual/)` — the dependency graph between resources — the core analytical object of a catalog (high)
+- [x] `databases (GET /api/v1/database/databases)` — top of the asset hierarchy; lookup resolving the parent of every schema and table already synced (high)
+- [x] `schemas (GET /api/v1/database/schemas)` — lookup resolving the schema id carried on every synced table (high)
+- [x] `integrations (GET /api/v1/integration/integrations)` — lookup resolving the integration id present on every resource, i.e. which source system an asset came from (high)
+- [x] `lineage (GET /api/v1/lineage/manual/)` — the dependency graph between resources — the core analytical object of a catalog (high)
- [ ] `monitors and incidents (/api/v1/monitor/monitors, /monitor/incidents)` — data-quality monitors and the incidents they raise, Secoda's headline reliability metric (high)
- [ ] `monitor measurements (GET /api/v1/monitor/measurements)` — the time series behind each monitor; required for any quality trend analysis (high)
- [ ] `queries (GET /api/v1/query/queries)` — query history driving table popularity and usage rankings (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/canonical_descriptions.py
index 247a0ab54a8c..2dd15253170d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/canonical_descriptions.py
@@ -80,4 +80,77 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"created_at": "When the tag was created.",
},
},
+ "databases": {
+ "description": "A database (or similar top-level container) catalogued in Secoda from a connected integration.",
+ "docs_url": "https://docs.secoda.co/api/reference/databases",
+ "columns": {
+ "id": "Unique identifier for the database.",
+ "title": "The title of the database.",
+ "title_full": "The full title of the database, including its ancestry.",
+ "description": "Description of the database.",
+ "native_type": "The native type of the database as it's referred to in the integration.",
+ "integration": "Identifier for the integration from which the database was extracted.",
+ "parent": "Parent ID of the database.",
+ "children_count": "Number of child entities associated with this database.",
+ "owners": "List of user IDs associated with the database.",
+ "tags": "List of tag IDs associated with the database.",
+ "pii": "Whether the database contains personally identifiable information.",
+ "verified": "Whether the database has been verified.",
+ "archived": "Whether the database is archived.",
+ "created_at": "When the database was created in Secoda.",
+ "updated_at": "When the database was last updated in Secoda.",
+ },
+ },
+ "schemas": {
+ "description": "A schema catalogued in Secoda, nested under a database.",
+ "docs_url": "https://docs.secoda.co/api/reference/schemas",
+ "columns": {
+ "id": "Unique identifier for the schema.",
+ "title": "The title of the schema.",
+ "title_full": "The full title of the schema, including its ancestry.",
+ "description": "Description of the schema.",
+ "native_type": "The native type of the schema as it's referred to in the integration.",
+ "integration": "Identifier for the integration from which the schema was extracted.",
+ "parent": "ID of the database the schema belongs to.",
+ "children_count": "Number of child entities associated with this schema.",
+ "owners": "List of user IDs associated with the schema.",
+ "tags": "List of tag IDs associated with the schema.",
+ "pii": "Whether the schema contains personally identifiable information.",
+ "verified": "Whether the schema has been verified.",
+ "archived": "Whether the schema is archived.",
+ "created_at": "When the schema was created in Secoda.",
+ "updated_at": "When the schema was last updated in Secoda.",
+ },
+ },
+ "integrations": {
+ "description": "An integration (connected source system) active in the Secoda workspace.",
+ "docs_url": "https://docs.secoda.co/api/reference/integrations",
+ "columns": {
+ "id": "The ID of the integration.",
+ "name": "The name of the integration.",
+ "type": "The type of integration.",
+ "workspace_id": "The ID of the associated workspace.",
+ "scheduled_extractions_hour": "Hour for scheduled extractions. Null for custom extractions.",
+ "scheduled_extractions_frequency": "Frequency in days of scheduled extractions. Null for custom extractions.",
+ "scheduled_extractions_next_run": "Next scheduled extraction run time. Null for custom extractions.",
+ "properties": "Additional properties associated with the integration.",
+ "teams": "List of team IDs associated with the integration.",
+ "created_at": "When the integration was created in Secoda.",
+ "updated_at": "When the integration was last updated in Secoda.",
+ },
+ },
+ "lineage": {
+ "description": "A lineage edge recording that one Secoda resource feeds another.",
+ "docs_url": "https://docs.secoda.co/api/reference/lineage",
+ "columns": {
+ "id": "The unique ID of the lineage object.",
+ "from_entity_id": "The ID of the upstream resource.",
+ "to_entity_id": "The ID of the downstream resource.",
+ "direction": "The direction of the lineage relationship.",
+ "is_manual": "Whether the lineage was added manually rather than extracted from an integration.",
+ "workspace_id": "The ID of the associated workspace.",
+ "created_at": "When the lineage object was created.",
+ "updated_at": "When the lineage object was last updated.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/secoda.py b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/secoda.py
index f7b05f9f8d07..4a3c8cfd8b0e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/secoda.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/secoda.py
@@ -9,6 +9,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponsePaginator,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -34,6 +35,10 @@ class SecodaResumeConfig:
next_url: str | None = None
+def _drop_fields(row: dict[str, Any], fields: tuple[str, ...]) -> dict[str, Any]:
+ return {key: value for key, value in row.items() if key not in fields}
+
+
def secoda_source(
api_key: str,
endpoint: str,
@@ -44,6 +49,20 @@ def secoda_source(
) -> SourceResponse:
config = SECODA_ENDPOINTS[endpoint]
+ resource_config: EndpointResource = {
+ "name": endpoint,
+ "endpoint": {
+ "path": config.path,
+ "data_selector": "results",
+ # A 200 whose body isn't the expected ``{"results": [...]}`` shape (bare list,
+ # dict without ``results``, or ``results`` not a list) is treated as transient
+ # and reissued — mirrors the old client raising a retryable error on it.
+ "data_selector_malformed_retryable": True,
+ },
+ }
+ if config.drop_fields:
+ resource_config["data_map"] = lambda row: _drop_fields(row, config.drop_fields)
+
rest_config: RESTAPIConfig = {
"client": {
"base_url": SECODA_BASE_URL,
@@ -51,22 +70,14 @@ def secoda_source(
# logs and raised errors; only the non-secret Accept header is set here.
"headers": {"Accept": "application/json"},
"auth": {"type": "bearer", "token": api_key},
+ # The bearer key must not follow a server-supplied `links.next` (or persisted resume
+ # URL) or a 3xx to another host. `allowed_hosts=[]` pins requests to SECODA_BASE_URL's host.
+ "allowed_hosts": [],
+ "allow_redirects": False,
"paginator": JSONResponsePaginator(next_url_path=NEXT_URL_PATH),
},
"resource_defaults": {},
- "resources": [
- {
- "name": endpoint,
- "endpoint": {
- "path": config.path,
- "data_selector": "results",
- # A 200 whose body isn't the expected ``{"results": [...]}`` shape (bare list,
- # dict without ``results``, or ``results`` not a list) is treated as transient
- # and reissued — mirrors the old client raising a retryable error on it.
- "data_selector_malformed_retryable": True,
- },
- }
- ],
+ "resources": [resource_config],
}
initial_paginator_state: Optional[dict[str, Any]] = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/settings.py
index cfb487ce0a3a..b39f4e37a7c3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/settings.py
@@ -1,14 +1,18 @@
-from dataclasses import dataclass, field
+from dataclasses import field
+
+from posthog.dataclasses import frozen
from products.warehouse_sources.backend.types import IncrementalField
-@dataclass
+@frozen
class SecodaEndpointConfig:
name: str
path: str
# Secoda resource identifiers are workspace-unique UUIDs, so `id` is a safe primary key.
primary_keys: list[str] = field(default_factory=lambda: ["id"])
+ # Top-level keys removed from every row before it reaches the warehouse.
+ drop_fields: tuple[str, ...] = ()
# Secoda v1 REST list endpoints. All are full-refresh only: Secoda's List Resources filter supports
@@ -21,6 +25,14 @@ SECODA_ENDPOINTS: dict[str, SecodaEndpointConfig] = {
"users": SecodaEndpointConfig(name="users", path="/api/v1/user"),
"groups": SecodaEndpointConfig(name="groups", path="/api/v1/auth/group"),
"tags": SecodaEndpointConfig(name="tags", path="/api/v1/tag"),
+ "databases": SecodaEndpointConfig(name="databases", path="/api/v1/database/databases"),
+ "schemas": SecodaEndpointConfig(name="schemas", path="/api/v1/database/schemas"),
+ # Secoda documents `credentials` as redacted, but a credentials blob has no analytical value and
+ # must never land in the warehouse if that redaction ever changes.
+ "integrations": SecodaEndpointConfig(
+ name="integrations", path="/api/v1/integration/integrations", drop_fields=("credentials",)
+ ),
+ "lineage": SecodaEndpointConfig(name="lineage", path="/api/v1/lineage/manual/"),
}
ENDPOINTS = tuple(SECODA_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/source.py
index bb7c10d7ab5f..a89cfd989376 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/source.py
@@ -55,7 +55,7 @@ class SecodaSource(ResumableSource[SecodaSourceConfig, SecodaResumeConfig]):
releaseStatus=ReleaseStatus.ALPHA,
caption="""Enter your Secoda API key to pull your data catalog into the PostHog Data warehouse.
-You can create an API key under **Settings → API** in [Secoda](https://app.secoda.co). The key inherits your workspace permissions and grants read access to your tables, columns, collections, users, groups, and tags.
+You can create an API key under **Settings → API** in [Secoda](https://app.secoda.co). The key inherits your workspace permissions and grants read access to your databases, schemas, tables, columns, lineage, integrations, collections, users, groups, and tags.
""",
iconPath="/static/services/secoda.png",
docsUrl="https://posthog.com/docs/cdp/sources/secoda",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/tests/test_secoda.py b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/tests/test_secoda.py
index 848c4756022c..a7e09836d104 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/tests/test_secoda.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/secoda/tests/test_secoda.py
@@ -84,6 +84,15 @@ class TestTransientResponsesRetried:
assert len(result.requests) == 2
+class TestRowShaping:
+ def test_integration_credentials_never_reach_the_warehouse(self) -> None:
+ row = {"id": "int-1", "name": "Warehouse", "type": "postgres", "credentials": {"password": "fake-pw"}}
+
+ result = _driver().run("integrations", [_page([row])])
+
+ assert result.rows == [{"id": "int-1", "name": "Warehouse", "type": "postgres"}]
+
+
class TestValidateCredentials:
def test_ok(self) -> None:
with scripted_network([ScriptedResponse(status=200, json={})]) as network: