: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 history tables to the aws glue source (#117693)
Tom Owers11d43d74b41c
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 0c8c27bcaebf..464bf01606e5 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@@ -1176,14 +1176,14 @@ Note: Compared the official botocore operation model with the static table map a## AWS Glue Data Catalog — **thin**-Today (6): `crawlers`, `databases`, `job_runs`, `jobs`, `partitions`, `tables`+Today (10): `crawlers`, `crawls`, `data_quality_results`, `databases`, `job_runs`, `jobs`, `partitions`, `table_versions`, `tables`, `workflow_runs`Diffed against: <https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/glue/2017-03-31/service-2.json>-- [ ] `Data quality results (ListDataQualityResults, POST /)` — links data quality scores and failed rules to synced tables and job runs (high)-- [ ] `Table versions (GetTableVersions, POST /)` — preserves schema and metadata history for existing catalog tables (medium)-- [ ] `Crawler history (ListCrawls, POST /)` — tracks crawl duration, failures, catalog changes, and compute use beyond the latest crawler result (medium)-- [ ] `Workflow runs (GetWorkflowRuns, POST /)` — measures complete pipeline duration and failures across related jobs and crawlers (medium)+- [x] `Data quality results (ListDataQualityResults, POST /)` — links data quality scores and failed rules to synced tables and job runs (high)+- [x] `Table versions (GetTableVersions, POST /)` — preserves schema and metadata history for existing catalog tables (medium)+- [x] `Crawler history (ListCrawls, POST /)` — tracks crawl duration, failures, catalog changes, and compute use beyond the latest crawler result (medium)+- [x] `Workflow runs (GetWorkflowRuns, POST /)` — measures complete pipeline duration and failures across related jobs and crawlers (medium)- [ ] `Table column statistics (GetColumnStatisticsForTable, POST /)` — provides column distributions, null counts, and cardinality for data profiling (medium)- [ ] `Table optimizer runs (ListTableOptimizerRuns, POST /)` — tracks compaction and cleanup execution history, failures, and resource use for catalog tables (medium)- [ ] `Interactive sessions (ListSessions, POST /)` — measures interactive ETL session duration, status, and compute use alongside scheduled job runs (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/aws_glue_data_catalog.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/aws_glue_data_catalog.pyindex 1d7afe6a8f6e..e23c011de9a8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/aws_glue_data_catalog.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/aws_glue_data_catalog.py@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.aws_glue_dCONTENT_TYPE,ENDPOINTS,ERROR_MESSAGES,+ PARENT_ENDPOINTS,REQUEST_TIMEOUT_SECONDS,TARGET_PREFIXES,GlueEndpoint,@@ -82,6 +83,15 @@ def error_for_response(response: requests.Response) -> AwsGlueError:return error_class(code, message)+def page_items(endpoint: GlueEndpoint, body: dict[str, Any]) -> list[dict[str, Any]]:+ items = body.get(endpoint.result_key, [])+ if endpoint.names_only and isinstance(items, list) and all(isinstance(item, str) for item in items):+ items = [{"Name": item} for item in items]+ if not isinstance(items, list) or any(not isinstance(item, dict) for item in items):+ raise ValueError("AWS Glue returned an invalid list response.")+ return items++class AwsGlueClient:def __init__(self, config: AwsGlueDataCatalogSourceConfig, api_version: str) -> None:if not config.aws_access_key_id or not config.aws_secret_access_key:@@ -148,9 +158,7 @@ class AwsGlueClient:if token:params["NextToken"] = tokenbody = self.request(endpoint.operation, params)- items = body[endpoint.result_key]- if not isinstance(items, list) or any(not isinstance(item, dict) for item in items):- raise ValueError("AWS Glue returned an invalid list response.")+ items = page_items(endpoint, body)next_token = body.get("NextToken") or Noneif next_token is not None and not isinstance(next_token, str):raise ValueError("AWS Glue returned an invalid pagination token.")@@ -162,14 +170,18 @@ class AwsGlueClient:token = next_token+def endpoint_spec(endpoint: str) -> GlueEndpoint:+ return ENDPOINTS[endpoint] if endpoint in ENDPOINTS else PARENT_ENDPOINTS[endpoint]++def normalize_row(endpoint: str, item: dict[str, Any], region: str, parent_payload: dict[str, Any]) -> dict[str, Any]:row = {_CAMEL_BOUNDARY.sub("_", key).lower(): value for key, value in item.items()}row["region"] = region- for column in ENDPOINTS[endpoint].timestamp_columns:+ for column in endpoint_spec(endpoint).timestamp_columns:value = row.get(column)if isinstance(value, int | float) and not isinstance(value, bool):row[column] = datetime.fromtimestamp(value, tz=UTC)- for key in ("DatabaseName", "TableName", "JobName", "CatalogId"):+ for key in ("DatabaseName", "TableName", "JobName", "CrawlerName", "CatalogId"):if key in parent_payload:row[_CAMEL_BOUNDARY.sub("_", key).lower()] = parent_payload[key]if endpoint == "partitions":@@ -181,10 +193,14 @@ def normalize_row(endpoint: str, item: dict[str, Any], region: str, parent_paylodef parent_payload(endpoint: str, parent: dict[str, Any]) -> dict[str, Any]:if endpoint == "job_runs":return {"JobName": parent["name"]}+ if endpoint == "crawls":+ return {"CrawlerName": parent["name"]}+ if endpoint == "workflow_runs":+ return {"Name": parent["name"], "IncludeGraph": False}payload = {"DatabaseName": parent["name"] if endpoint == "tables" else parent["database_name"]}if parent.get("catalog_id"):payload["CatalogId"] = parent["catalog_id"]- if endpoint == "partitions":+ if endpoint in ("partitions", "table_versions"):payload["TableName"] = parent["name"]return payload@@ -195,7 +211,7 @@ def walk_rows(manager: ResumableSourceManager[AwsGlueDataCatalogResumeConfig],checkpoint: bool = False,) -> Iterator[list[dict[str, Any]]]:- spec = ENDPOINTS[endpoint]+ spec = endpoint_spec(endpoint)if spec.parent:for parents in walk_rows(client, spec.parent, manager):for parent in parents:@@ -250,7 +266,7 @@ def aws_glue_data_catalog_source(def probe_endpoint(client: AwsGlueClient, endpoint: str) -> dict[str, Any] | None:- spec = ENDPOINTS[endpoint]+ spec = endpoint_spec(endpoint)payload: dict[str, Any] = {}if spec.parent:parent = probe_endpoint(client, spec.parent)@@ -258,7 +274,7 @@ def probe_endpoint(client: AwsGlueClient, endpoint: str) -> dict[str, Any] | Nonreturn Nonepayload = parent_payload(endpoint, parent)body = client.request(spec.operation, {**payload, "MaxResults": 1})- items = body.get(spec.result_key) or []+ items = page_items(spec, body)return normalize_row(endpoint, items[0], client.region, payload) if items else Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/canonical_descriptions.pyindex 57f372949e48..ff44fd9afd63 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/canonical_descriptions.py@@ -91,4 +91,62 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"region": "AWS region selected for this source.",},},+ "crawls": {+ "description": "Crawl history for each crawler. AWS keeps up to 12 months of crawls.",+ "docs_url": "https://docs.aws.amazon.com/glue/latest/webapi/API_CrawlerHistory.html",+ "columns": {+ "crawler_name": "Name of the crawler that ran the crawl.",+ "crawl_id": "Identifier of the crawl.",+ "state": "State of the crawl.",+ "start_time": "Time when the crawl started.",+ "end_time": "Time when the crawl ended.",+ "summary": "Summary of the crawl in JSON, with the tables and partitions it added, updated, or deleted.",+ "error_message": "Error message associated with the crawl, if any.",+ "log_group": "CloudWatch log group associated with the crawl.",+ "log_stream": "CloudWatch log stream associated with the crawl.",+ "message_prefix": "Prefix of the CloudWatch message for this crawl.",+ "dpu_hour": "Number of data processing units (DPU) the crawl used, in hours.",+ "region": "AWS region selected for this source.",+ },+ },+ "table_versions": {+ "description": "Versions of each catalog table, with the full table definition at that version.",+ "docs_url": "https://docs.aws.amazon.com/glue/latest/webapi/API_TableVersion.html",+ "columns": {+ "database_name": "Name of the database that contains the table.",+ "table_name": "Name of the table.",+ "catalog_id": "Identifier of the Data Catalog that contains the table.",+ "version_id": "Identifier of the table version.",+ "table": "Table definition at this version, including columns and storage settings.",+ "region": "AWS region selected for this source.",+ },+ },+ "workflow_runs": {+ "description": "Runs of each Glue workflow, with status, timing, and action statistics.",+ "docs_url": "https://docs.aws.amazon.com/glue/latest/webapi/API_WorkflowRun.html",+ "columns": {+ "name": "Name of the workflow that ran.",+ "workflow_run_id": "Identifier of the workflow run.",+ "previous_run_id": "Identifier of the previous workflow run.",+ "workflow_run_properties": "Properties set during the run.",+ "started_on": "Time when the run started.",+ "completed_on": "Time when the run completed.",+ "status": "Status of the run.",+ "error_message": "Error message associated with the run, if any.",+ "statistics": "Counts of the run's actions by state, such as succeeded, failed, and timed out.",+ "region": "AWS region selected for this source.",+ },+ },+ "data_quality_results": {+ "description": "Data quality evaluation runs. Each row links a result to the evaluated table and job run.",+ "docs_url": "https://docs.aws.amazon.com/glue/latest/webapi/API_DataQualityResultDescription.html",+ "columns": {+ "result_id": "Identifier of the data quality result.",+ "data_source": "Table that the data quality rules evaluated.",+ "job_name": "Name of the job that ran the evaluation, if any.",+ "job_run_id": "Identifier of the job run that ran the evaluation, if any.",+ "started_on": "Time when the evaluation started.",+ "region": "AWS region selected for this source.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/settings.pyindex f4676ae88b11..262f783324e5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/settings.py@@ -14,6 +14,7 @@ class GlueEndpoint:parent: str | None = Nonepage_size: int = 100timestamp_columns: tuple[str, ...] = ()+ names_only: bool = FalseENDPOINTS: dict[str, GlueEndpoint] = {@@ -56,6 +57,43 @@ ENDPOINTS: dict[str, GlueEndpoint] = {primary_keys=("region", "name"),timestamp_columns=("creation_time", "last_updated"),),+ "crawls": GlueEndpoint(+ operation="ListCrawls",+ result_key="Crawls",+ primary_keys=("region", "crawler_name", "crawl_id"),+ parent="crawlers",+ timestamp_columns=("start_time", "end_time"),+ ),+ "table_versions": GlueEndpoint(+ operation="GetTableVersions",+ result_key="TableVersions",+ primary_keys=("region", "database_name", "table_name", "version_id"),+ parent="tables",+ ),+ "workflow_runs": GlueEndpoint(+ operation="GetWorkflowRuns",+ result_key="Runs",+ primary_keys=("region", "name", "workflow_run_id"),+ parent="workflows",+ timestamp_columns=("started_on", "completed_on"),+ ),+ "data_quality_results": GlueEndpoint(+ operation="ListDataQualityResults",+ result_key="Results",+ primary_keys=("region", "result_id"),+ timestamp_columns=("started_on",),+ ),+}++# ListWorkflows returns only names, so it feeds workflow_runs without being a table of its own.+PARENT_ENDPOINTS: dict[str, GlueEndpoint] = {+ "workflows": GlueEndpoint(+ operation="ListWorkflows",+ result_key="Workflows",+ primary_keys=("region", "name"),+ page_size=25,+ names_only=True,+ ),}ENDPOINT_DESCRIPTIONS = {@@ -65,6 +103,10 @@ ENDPOINT_DESCRIPTIONS = {"jobs": "Job definitions and execution settings.","job_runs": "Job execution history, status, duration, and resource usage.","crawlers": "Crawler settings, state, and the latest crawl result.",+ "crawls": "Crawl history for each crawler, including duration, status, and DPU usage.",+ "table_versions": "Schema and metadata history for each catalog table.",+ "workflow_runs": "Workflow run history, status, timing, and action statistics.",+ "data_quality_results": "Data quality evaluation runs, with the evaluated table and the job run.",}ERROR_MESSAGES = {diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/source.pyindex 1842d2540fe2..a39b6feb2767 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/source.py@@ -119,8 +119,11 @@ class AwsGlueDataCatalogSource(ResumableSource[AwsGlueDataCatalogSourceConfig, Alabel="AWS Glue Data Catalog",caption=("Sync catalog metadata, job history, and crawlers from one AWS region. "- "Grant `glue:GetDatabases`, `glue:GetTables`, and `glue:GetPartitions` for catalog tables. "- "Grant `glue:GetJobs`, `glue:GetJobRuns`, and `glue:GetCrawlers` for jobs and crawlers. "+ "Grant `glue:GetDatabases`, `glue:GetTables`, `glue:GetPartitions`, and `glue:GetTableVersions` "+ "for catalog tables. "+ "Grant `glue:GetJobs`, `glue:GetJobRuns`, `glue:GetCrawlers`, and `glue:ListCrawls` for jobs and crawlers. "+ "Grant `glue:ListWorkflows` and `glue:GetWorkflowRuns` for workflow runs, "+ "and `glue:ListDataQualityResults` for data quality results. ""Lake Formation permissions can also restrict catalog access. ""Enter the access key ID and secret access key. Add a session token for temporary credentials."),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/tests/test_aws_glue_data_catalog.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/tests/test_aws_glue_data_catalog.pyindex 5d8800ec74a9..5a61030c12ab 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/tests/test_aws_glue_data_catalog.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_glue_data_catalog/tests/test_aws_glue_data_catalog.py@@ -178,7 +178,13 @@ def test_body_retry_does_not_repeat_transport_retries(status: int, attempts: int@pytest.mark.parametrize(- "endpoint,result_key", [("databases", "DatabaseList"), ("jobs", "Jobs"), ("crawlers", "Crawlers")]+ "endpoint,result_key",+ [+ ("databases", "DatabaseList"),+ ("jobs", "Jobs"),+ ("crawlers", "Crawlers"),+ ("data_quality_results", "Results"),+ ],)def test_top_level_resume_checkpoints_before_yield_and_clears_after_completion(endpoint: str, result_key: str) -> None:resume = manager(glue.AwsGlueDataCatalogResumeConfig(next_token="saved"))@@ -292,6 +298,79 @@ def test_job_run_full_refresh_keeps_old_runs_and_namespaces_ids_by_job() -> None]+ "endpoint,script,expected_requests,expected_keys",+ [+ (+ "crawls",+ [+ {"Crawlers": [{"Name": "first"}, {"Name": "second"}]},+ {"Crawls": [{"CrawlId": "crawl-1", "StartTime": 1735689600, "DPUHour": 0.5}], "NextToken": "older"},+ {"Crawls": [{"CrawlId": "crawl-0"}]},+ {"Crawls": [{"CrawlId": "crawl-1"}]},+ ],+ [+ {"MaxResults": 100},+ {"MaxResults": 100, "CrawlerName": "first"},+ {"MaxResults": 100, "CrawlerName": "first", "NextToken": "older"},+ {"MaxResults": 100, "CrawlerName": "second"},+ ],+ [+ ("eu-west-1", "first", "crawl-1"),+ ("eu-west-1", "first", "crawl-0"),+ ("eu-west-1", "second", "crawl-1"),+ ],+ ),+ (+ "workflow_runs",+ [+ {"Workflows": ["first"], "NextToken": "more"},+ {"Runs": [{"Name": "first", "WorkflowRunId": "run-1"}]},+ {"Workflows": ["second"]},+ {"Runs": [{"Name": "second", "WorkflowRunId": "run-1"}]},+ ],+ [+ {"MaxResults": 25},+ {"MaxResults": 100, "Name": "first", "IncludeGraph": False},+ {"MaxResults": 25, "NextToken": "more"},+ {"MaxResults": 100, "Name": "second", "IncludeGraph": False},+ ],+ [("eu-west-1", "first", "run-1"), ("eu-west-1", "second", "run-1")],+ ),+ (+ "table_versions",+ [+ {"DatabaseList": [{"Name": "analytics", "CatalogId": "123456789012"}]},+ {"TableList": [{"Name": "events"}, {"Name": "users"}]},+ {"TableVersions": [{"VersionId": "1", "Table": {"Name": "events"}}]},+ {"TableVersions": [{"VersionId": "1", "Table": {"Name": "users"}}]},+ ],+ [+ {"MaxResults": 100},+ {"MaxResults": 100, "DatabaseName": "analytics", "CatalogId": "123456789012"},+ {"MaxResults": 100, "DatabaseName": "analytics", "TableName": "events", "CatalogId": "123456789012"},+ {"MaxResults": 100, "DatabaseName": "analytics", "TableName": "users", "CatalogId": "123456789012"},+ ],+ [("eu-west-1", "analytics", "events", "1"), ("eu-west-1", "analytics", "users", "1")],+ ),+ ],+)+def test_history_fan_out_pages_each_parent_and_keys_rows_by_parent(+ endpoint: str,+ script: list[dict[str, Any]],+ expected_requests: list[dict[str, Any]],+ expected_keys: list[tuple[str, ...]],+) -> None:+ result = driver().run(endpoint, [ScriptedResponse(json=body) for body in script])+ assert result.raised is None+ assert [request.json() for request in result.requests] == expected_requests+ primary_keys = glue.ENDPOINTS[endpoint].primary_keys+ assert [tuple(row[key] for key in primary_keys) for row in result.rows] == expected_keys+ if endpoint == "crawls":+ assert result.rows[0]["start_time"] == datetime(2025, 1, 1, tzinfo=UTC)+ assert result.rows[0]["dpu_hour"] == 0.5++@pytest.mark.parametrize("schema_name", [None, "databases"])@pytest.mark.parametrize("code",@@ -320,22 +399,33 @@ def test_validation_maps_errors_and_accepts_create_time_permission_denials(schemfactory.return_value.close.assert_called_once()-def test_creation_probes_once_and_selected_child_checks_parent_and_child() -> None:+def test_creation_probes_once() -> None:with scripted_network([ScriptedResponse(json={"DatabaseList": []})]) as creation:assert glue.validate_credentials(config(), GLUE_API_VERSION) == (True, None)assert len(creation.requests_log) == 1assert creation.requests_log[0].json() == {"MaxResults": 1}++ "schema_name,parent_body,child_payload",+ [+ ("job_runs", {"Jobs": [{"Name": "example"}]}, {"MaxResults": 1, "JobName": "example"}),+ ("workflow_runs", {"Workflows": ["example"]}, {"MaxResults": 1, "Name": "example", "IncludeGraph": False}),+ ],+)+def test_selected_child_checks_parent_and_child(+ schema_name: str, parent_body: dict[str, Any], child_payload: dict[str, Any]+) -> None:with scripted_network([- ScriptedResponse(json={"Jobs": [{"Name": "example"}]}),+ ScriptedResponse(json=parent_body),ScriptedResponse(status=403, json={"__type": "AccessDeniedException"}),]) as selected:- valid, reason = glue.validate_credentials(config(), GLUE_API_VERSION, "job_runs")+ valid, reason = glue.validate_credentials(config(), GLUE_API_VERSION, schema_name)assert not valid and reasonassert len(selected.requests_log) == 2- assert selected.requests_log[1].json() == {"MaxResults": 1, "JobName": "example"}+ assert selected.requests_log[1].json() == child_payload@pytest.mark.parametrize("endpoint", ["tables", "partitions", "job_runs"])