: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 config, package, tuning and automl tables to aws sagemaker (#117696)
Tom Owers1cf028c61abd
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 530afc0d1817..0c8c27bcaebf 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@@ -1262,10 +1262,10 @@ Today (4): `endpoints`, `models`, `processing_jobs`, `training_jobs`Diffed against: <https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/sagemaker/2017-07-24/service-2.json>-- [ ] `Endpoint configurations (ListEndpointConfigs and DescribeEndpointConfig, POST /)` — resolve EndpointConfigName on synced endpoints to deployed model names and instance types (high)-- [ ] `Model packages (ListModelPackages and DescribeModelPackage, POST /)` — resolve model package references in models and training jobs to registered versions, approval status, and evaluation results (high)-- [ ] `Hyperparameter tuning jobs (ListHyperParameterTuningJobs and DescribeHyperParameterTuningJob, POST /)` — resolve TuningJobArn on training jobs and compare tuning objectives, outcomes, and resource use (high)-- [ ] `AutoML jobs (ListAutoMLJobs, DescribeAutoMLJob and DescribeAutoMLJobV2, POST /)` — resolve AutoMLJobArn on training jobs and compare automated training outcomes and best candidates (high)+- [x] `Endpoint configurations (ListEndpointConfigs and DescribeEndpointConfig, POST /)` — resolve EndpointConfigName on synced endpoints to deployed model names and instance types (high)+- [x] `Model packages (ListModelPackages and DescribeModelPackage, POST /)` — resolve model package references in models and training jobs to registered versions, approval status, and evaluation results (high)+- [x] `Hyperparameter tuning jobs (ListHyperParameterTuningJobs and DescribeHyperParameterTuningJob, POST /)` — resolve TuningJobArn on training jobs and compare tuning objectives, outcomes, and resource use (high)+- [x] `AutoML jobs (ListAutoMLJobs, DescribeAutoMLJob and DescribeAutoMLJobV2, POST /)` — resolve AutoMLJobArn on training jobs and compare automated training outcomes and best candidates (high)- [ ] `Experiments, trials, and trial components (ListExperiments, ListTrials, ListTrialComponents and their Describe operations, POST /)` — resolve ExperimentConfig references on training jobs and compare experiment runs, parameters, and metrics (high)- [ ] `Transform jobs (ListTransformJobs and DescribeTransformJob, POST /)` — analyze batch inference status, duration, failures, and model use (high)- [ ] `Pipeline executions (ListPipelineExecutions and DescribePipelineExecution, POST /)` — measure workflow success rates, execution duration, and repeated failures (high)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/aws_sagemaker.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/aws_sagemaker.pyindex ba8907c9bd00..ac4a2b118f67 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/aws_sagemaker.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/aws_sagemaker.py@@ -52,6 +52,8 @@ _TIMESTAMP_FIELDS = {"TrainingEndTime","ProcessingStartTime","ProcessingEndTime",+ "HyperParameterTuningEndTime",+ "EndTime",}@@ -182,7 +184,12 @@ def get_rows(client = AwsSagemakerClient(config, api_version)try:while True:- payload: dict[str, Any] = {"MaxResults": MAX_RESULTS, "SortBy": "CreationTime", "SortOrder": "Ascending"}+ payload: dict[str, Any] = {+ "MaxResults": MAX_RESULTS,+ "SortBy": "CreationTime",+ "SortOrder": "Ascending",+ **dict(settings.list_filters),+ }if watermark is not None and incremental and settings.incremental:payload["CreationTimeAfter"] = watermarkif token:@@ -192,9 +199,7 @@ def get_rows(if next_token == token and next_token is not None:raise ValueError("AWS SageMaker returned a repeated pagination token.")rows = [- normalize_row(- client.request(settings.describe_operation, {settings.name_field: item[settings.name_field]})- )+ normalize_row(client.request(settings.describe_operation, settings.describe_payload(item)))for item in page[settings.result_key]]for row in rows:@@ -224,10 +229,9 @@ def validate_credentials(except ValueError as error:return False, str(error)try:- page = client.request(settings.list_operation, {"MaxResults": 1})+ page = client.request(settings.list_operation, {"MaxResults": 1, **dict(settings.list_filters)})if schema_name and page.get(settings.result_key):- item = page[settings.result_key][0]- client.request(settings.describe_operation, {settings.name_field: item[settings.name_field]})+ client.request(settings.describe_operation, settings.describe_payload(page[settings.result_key][0]))except AwsSagemakerError as error:if error.code in {"AccessDenied", "AccessDeniedException"}:if schema_name is None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/canonical_descriptions.pyindex 5fb2c6d8ede4..ac713d068b27 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/canonical_descriptions.py@@ -61,4 +61,68 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"vpc_config": "The VPC subnets and security groups used by the model.",},},+ "endpoint_configs": {+ "description": "SageMaker endpoint configurations, including the models and instance types each production variant deploys.",+ "docs_url": "https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeEndpointConfig.html",+ "columns": {+ "endpoint_config_arn": "The Amazon Resource Name of the endpoint configuration.",+ "endpoint_config_name": "The name of the endpoint configuration.",+ "creation_time": "The time AWS created the endpoint configuration.",+ "production_variants": "The production variants, including model names, instance types, and instance counts.",+ "shadow_production_variants": "The shadow variants that receive a copy of production traffic.",+ "data_capture_config": "The settings for capturing endpoint requests and responses.",+ "async_inference_config": "The settings for asynchronous inference.",+ "kms_key_id": "The KMS key used to encrypt data on the ML storage volume.",+ },+ },+ "model_packages": {+ "description": "SageMaker model packages, including Model Registry versions, approval status, and model metrics.",+ "docs_url": "https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeModelPackage.html",+ "columns": {+ "model_package_arn": "The Amazon Resource Name of the model package.",+ "model_package_name": "The name of the model package.",+ "model_package_group_name": "The model package group of a versioned model package.",+ "model_package_version": "The version number of a versioned model package.",+ "model_package_status": "The status of the model package.",+ "model_approval_status": "The approval status of the model package.",+ "creation_time": "The time AWS created the model package.",+ "last_modified_time": "The time AWS last modified the model package.",+ "inference_specification": "The containers and instance types supported for inference.",+ "model_metrics": "The metrics that evaluate the model package.",+ },+ },+ "hyperparameter_tuning_jobs": {+ "description": "SageMaker hyperparameter tuning jobs, including their objective, status, and best training job.",+ "docs_url": "https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeHyperParameterTuningJob.html",+ "columns": {+ "hyper_parameter_tuning_job_arn": "The Amazon Resource Name of the tuning job.",+ "hyper_parameter_tuning_job_name": "The name of the tuning job.",+ "hyper_parameter_tuning_job_status": "The status of the tuning job.",+ "hyper_parameter_tuning_job_config": "The tuning strategy, objective metric, and resource limits.",+ "creation_time": "The time AWS created the tuning job.",+ "hyper_parameter_tuning_end_time": "The time the tuning job ended.",+ "last_modified_time": "The time AWS last modified the tuning job.",+ "training_job_status_counters": "The number of training jobs the tuning job started, grouped by status.",+ "best_training_job": "The training job with the best objective metric value.",+ "consumed_resources": "The total resources the tuning job consumed, such as runtime.",+ "failure_reason": "The reason the tuning job failed.",+ },+ },+ "automl_jobs": {+ "description": "SageMaker AutoML jobs, including their problem type, objective, status, and best candidate.",+ "docs_url": "https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeAutoMLJobV2.html",+ "columns": {+ "auto_ml_job_arn": "The Amazon Resource Name of the AutoML job.",+ "auto_ml_job_name": "The name of the AutoML job.",+ "auto_ml_job_status": "The status of the AutoML job.",+ "auto_ml_job_secondary_status": "The detailed status of the AutoML job.",+ "auto_ml_job_objective": "The objective metric the AutoML job optimizes.",+ "auto_ml_problem_type_config_name": "The type of problem the AutoML job solves.",+ "creation_time": "The time AWS created the AutoML job.",+ "end_time": "The time the AutoML job ended.",+ "last_modified_time": "The time AWS last modified the AutoML job.",+ "best_candidate": "The best model candidate the AutoML job found.",+ "failure_reason": "The reason the AutoML job failed.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/settings.pyindex d4d2c4421448..388f62a5b542 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/settings.py@@ -1,3 +1,5 @@+from typing import Any+from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import incremental_field@@ -16,6 +18,11 @@ class SageMakerEndpoint:name_field: strprimary_key: strincremental: bool = False+ describe_key: str | None = None+ list_filters: tuple[tuple[str, str], ...] = ()++ def describe_payload(self, item: dict[str, Any]) -> dict[str, Any]:+ return {self.name_field: item[self.describe_key or self.name_field]}ENDPOINTS: dict[str, SageMakerEndpoint] = {@@ -48,13 +55,53 @@ ENDPOINTS: dict[str, SageMakerEndpoint] = {primary_key="model_arn",incremental=True,),+ "endpoint_configs": SageMakerEndpoint(+ list_operation="ListEndpointConfigs",+ result_key="EndpointConfigs",+ describe_operation="DescribeEndpointConfig",+ name_field="EndpointConfigName",+ primary_key="endpoint_config_arn",+ incremental=True,+ ),+ "model_packages": SageMakerEndpoint(+ list_operation="ListModelPackages",+ result_key="ModelPackageSummaryList",+ describe_operation="DescribeModelPackage",+ name_field="ModelPackageName",+ primary_key="model_package_arn",+ # Versioned packages share their group's name, so only the ARN identifies one version.+ describe_key="ModelPackageArn",+ # The API lists only unversioned packages by default, which hides Model Registry versions.+ list_filters=(("ModelPackageType", "Both"),),+ ),+ "hyperparameter_tuning_jobs": SageMakerEndpoint(+ list_operation="ListHyperParameterTuningJobs",+ result_key="HyperParameterTuningJobSummaries",+ describe_operation="DescribeHyperParameterTuningJob",+ name_field="HyperParameterTuningJobName",+ primary_key="hyper_parameter_tuning_job_arn",+ ),+ "automl_jobs": SageMakerEndpoint(+ list_operation="ListAutoMLJobs",+ result_key="AutoMLJobSummaries",+ describe_operation="DescribeAutoMLJobV2",+ name_field="AutoMLJobName",+ primary_key="auto_ml_job_arn",+ ),}# Mutable resources cannot sort by modification time, so creation cursors would miss later changes.-INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {"models": [incremental_field("creation_time")]}+INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {+ "models": [incremental_field("creation_time")],+ "endpoint_configs": [incremental_field("creation_time")],+}ENDPOINT_DESCRIPTIONS = {"training_jobs": "Training jobs with status, resource settings, metrics, and billable duration.","processing_jobs": "Processing jobs with status, input and output settings, and compute resources.","endpoints": "Inference endpoints with status, deployment settings, and production variants.","models": "Models with container settings, execution roles, and creation times.",+ "endpoint_configs": "Endpoint configurations with production variants, instance types, and data capture settings.",+ "model_packages": "Model packages and Model Registry versions with approval status, metrics, and inference settings.",+ "hyperparameter_tuning_jobs": "Hyperparameter tuning jobs with objectives, best training jobs, and consumed resources.",+ "automl_jobs": "AutoML jobs with problem type, objective, status, and best candidate.",}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/source.pyindex fcd67eac3478..b557ffc150d7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/source.py@@ -135,9 +135,13 @@ class AwsSagemakerSource(ResumableSource[AwsSagemakerSourceConfig, AwsSagemakerR"`sagemaker:ListTrainingJobs`, `sagemaker:DescribeTrainingJob`, ""`sagemaker:ListProcessingJobs`, `sagemaker:DescribeProcessingJob`, ""`sagemaker:ListEndpoints`, `sagemaker:DescribeEndpoint`, "- "`sagemaker:ListModels`, and `sagemaker:DescribeModel`. "- "Jobs and endpoints use full refresh to capture status changes. "- "Models also support incremental sync by creation time."+ "`sagemaker:ListModels`, `sagemaker:DescribeModel`, "+ "`sagemaker:ListEndpointConfigs`, `sagemaker:DescribeEndpointConfig`, "+ "`sagemaker:ListModelPackages`, `sagemaker:DescribeModelPackage`, "+ "`sagemaker:ListHyperParameterTuningJobs`, `sagemaker:DescribeHyperParameterTuningJob`, "+ "`sagemaker:ListAutoMLJobs`, and `sagemaker:DescribeAutoMLJobV2`. "+ "Jobs, endpoints, and model packages use full refresh to capture status changes. "+ "Models and endpoint configurations also support incremental sync by creation time."),iconPath="/static/services/aws_sagemaker.png",releaseStatus=ReleaseStatus.ALPHA,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/tests/test_aws_sagemaker.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/tests/test_aws_sagemaker.pyindex c50704ef77fa..daf84bb3d3c0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/tests/test_aws_sagemaker.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_sagemaker/tests/test_aws_sagemaker.py@@ -113,7 +113,7 @@ def test_signed_json_request(@pytest.mark.parametrize(- "endpoint,list_operation,result_key,describe_operation,name_field,arn_field,column",+ "endpoint,list_operation,result_key,describe_operation,name_field,arn_field,column,list_filters,describe_payload",[("training_jobs",@@ -123,6 +123,8 @@ def test_signed_json_request("TrainingJobName","TrainingJobArn","training_job_arn",+ {},+ {"TrainingJobName": "example"},),("processing_jobs",@@ -132,9 +134,75 @@ def test_signed_json_request("ProcessingJobName","ProcessingJobArn","processing_job_arn",+ {},+ {"ProcessingJobName": "example"},+ ),+ (+ "endpoints",+ "ListEndpoints",+ "Endpoints",+ "DescribeEndpoint",+ "EndpointName",+ "EndpointArn",+ "endpoint_arn",+ {},+ {"EndpointName": "example"},+ ),+ (+ "models",+ "ListModels",+ "Models",+ "DescribeModel",+ "ModelName",+ "ModelArn",+ "model_arn",+ {},+ {"ModelName": "example"},+ ),+ (+ "endpoint_configs",+ "ListEndpointConfigs",+ "EndpointConfigs",+ "DescribeEndpointConfig",+ "EndpointConfigName",+ "EndpointConfigArn",+ "endpoint_config_arn",+ {},+ {"EndpointConfigName": "example"},+ ),+ (+ "model_packages",+ "ListModelPackages",+ "ModelPackageSummaryList",+ "DescribeModelPackage",+ "ModelPackageName",+ "ModelPackageArn",+ "model_package_arn",+ {"ModelPackageType": "Both"},+ {"ModelPackageName": "arn-of-example"},+ ),+ (+ "hyperparameter_tuning_jobs",+ "ListHyperParameterTuningJobs",+ "HyperParameterTuningJobSummaries",+ "DescribeHyperParameterTuningJob",+ "HyperParameterTuningJobName",+ "HyperParameterTuningJobArn",+ "hyper_parameter_tuning_job_arn",+ {},+ {"HyperParameterTuningJobName": "example"},+ ),+ (+ "automl_jobs",+ "ListAutoMLJobs",+ "AutoMLJobSummaries",+ "DescribeAutoMLJobV2",+ "AutoMLJobName",+ "AutoMLJobArn",+ "auto_ml_job_arn",+ {},+ {"AutoMLJobName": "example"},),- ("endpoints", "ListEndpoints", "Endpoints", "DescribeEndpoint", "EndpointName", "EndpointArn", "endpoint_arn"),- ("models", "ListModels", "Models", "DescribeModel", "ModelName", "ModelArn", "model_arn"),],)def test_pagination_describes_rows_and_stages_only_complete_pages(@@ -147,9 +215,11 @@ def test_pagination_describes_rows_and_stages_only_complete_pages(name_field: str,arn_field: str,column: str,+ list_filters: dict[str, str],+ describe_payload: dict[str, str],) -> None:transport.post.side_effect = [- response({result_key: [{name_field: "example"}], "NextToken": "second"}),+ response({result_key: [{name_field: "example", arn_field: "arn-of-example"}], "NextToken": "second"}),response({arn_field: "arn:aws:sagemaker:eu-west-1:123456789012:example/item",@@ -158,7 +228,7 @@ def test_pagination_describes_rows_and_stages_only_complete_pages(}),response({result_key: [], "NextToken": "last"}),- response({result_key: [{name_field: "other"}]}),+ response({result_key: [{name_field: "other", arn_field: "arn-of-other"}]}),response({arn_field: "arn:aws:sagemaker:eu-west-1:123456789012:example/other", "CreationTime": 1704153600}),]resume = manager()@@ -181,8 +251,9 @@ def test_pagination_describes_rows_and_stages_only_complete_pages("MaxResults": 100,"SortBy": "CreationTime","SortOrder": "Ascending",+ **list_filters,}- assert json.loads(calls[1].kwargs["data"]) == {name_field: "example"}+ assert json.loads(calls[1].kwargs["data"]) == describe_payloadassert json.loads(calls[2].kwargs["data"])["NextToken"] == "second"assert json.loads(calls[3].kwargs["data"])["NextToken"] == "last"assert [call.args[0] for call in resume.save_state.call_args_list] == [