Skip to content

Commit 6924aa9

Browse files
author
Sushanth Sathish Kumar
committed
feature: add enable_automatic_dashboard and dashboard_name parameter to update_monitoring_schedule methods for Data Quality and Model Quality
1 parent 21bf4d0 commit 6924aa9

File tree

2 files changed

+107
-161
lines changed

2 files changed

+107
-161
lines changed

src/sagemaker/model_monitor/model_monitoring.py

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ def update_monitoring_schedule(
21982198
env=None,
21992199
network_config=None,
22002200
enable_cloudwatch_metrics=None,
2201-
enable_automatic_dashboard=False,
2201+
enable_automatic_dashboard=None,
22022202
dashboard_name=None,
22032203
role=None,
22042204
batch_transform_input=None,
@@ -2266,6 +2266,15 @@ def update_monitoring_schedule(
22662266
)
22672267
logger.error(message)
22682268
raise ValueError(message)
2269+
2270+
# error checking for dashboard
2271+
if enable_automatic_dashboard:
2272+
self._check_dashboard_validity_without_checking_in_use(
2273+
monitor_schedule_name=self.monitoring_schedule_name,
2274+
enable_cloudwatch_metrics=enable_cloudwatch_metrics,
2275+
enable_automatic_dashboard=enable_automatic_dashboard,
2276+
dashboard_name=dashboard_name,
2277+
)
22692278

22702279
# check if this schedule is in v2 format and update as per v2 format if it is
22712280
if self.job_definition_name is not None:
@@ -2396,6 +2405,26 @@ def update_monitoring_schedule(
23962405
)
23972406

23982407
self._wait_for_schedule_changes_to_apply()
2408+
2409+
if enable_automatic_dashboard:
2410+
if dashboard_name is None:
2411+
dashboard_name = self.monitoring_schedule_name
2412+
if isinstance(endpoint_input, EndpointInput):
2413+
endpoint_name = endpoint_input.endpoint_name
2414+
else:
2415+
endpoint_name = endpoint_input
2416+
2417+
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
2418+
cw_client.put_dashboard(
2419+
DashboardName=dashboard_name,
2420+
DashboardBody=AutomaticDataQualityDashboard(
2421+
endpoint_name=endpoint_name,
2422+
monitoring_schedule_name=self.monitoring_schedule_name,
2423+
batch_transform_input=batch_transform_input,
2424+
region_name=self.sagemaker_session.boto_region_name,
2425+
).to_json(),
2426+
)
2427+
23992428

24002429
def _update_data_quality_monitoring_schedule(
24012430
self,
@@ -2443,10 +2472,6 @@ def _update_data_quality_monitoring_schedule(
24432472
expressions. Default: Daily.
24442473
enable_cloudwatch_metrics (bool): Whether to publish cloudwatch metrics as part of
24452474
the baselining or monitoring jobs.
2446-
enable_automatic_dashboard (bool): Whether to publish an automatic dashboard as part of
2447-
the baselining or monitoring jobs.
2448-
dashboard_name (str): Name to use for the published dashboard. When not provided,
2449-
defaults to monitoring schedule name.
24502475
role (str): An AWS IAM role. The Amazon SageMaker jobs use this role.
24512476
instance_count (int): The number of instances to run
24522477
the jobs with.
@@ -2503,15 +2528,6 @@ def _update_data_quality_monitoring_schedule(
25032528
"ScheduleExpression"
25042529
]
25052530

2506-
# error checking for dashboard
2507-
# if enable_automatic_dashboard:
2508-
# self._check_dashboard_validity_without_checking_in_use(
2509-
# monitor_schedule_name=self.monitoring_schedule_name,
2510-
# enable_cloudwatch_metrics=enable_cloudwatch_metrics,
2511-
# enable_automatic_dashboard=enable_automatic_dashboard,
2512-
# dashboard_name=dashboard_name,
2513-
# )
2514-
25152531
# Need to update schedule with a new job definition
25162532
job_desc = self.sagemaker_session.sagemaker_client.describe_data_quality_job_definition(
25172533
JobDefinitionName=self.job_definition_name
@@ -2575,24 +2591,6 @@ def _update_data_quality_monitoring_schedule(
25752591
logger.exception(message)
25762592
raise
25772593

2578-
# if enable_automatic_dashboard:
2579-
# if dashboard_name is None:
2580-
# dashboard_name = self.monitoring_schedule_name
2581-
# if isinstance(endpoint_input, EndpointInput):
2582-
# endpoint_name = endpoint_input.endpoint_name
2583-
# else:
2584-
# endpoint_name = endpoint_input
2585-
2586-
# cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
2587-
# cw_client.put_dashboard(
2588-
# DashboardName=dashboard_name,
2589-
# DashboardBody=AutomaticDataQualityDashboard(
2590-
# endpoint_name=endpoint_name,
2591-
# monitoring_schedule_name=self.monitoring_schedule_name,
2592-
# batch_transform_input=batch_transform_input,
2593-
# region_name=self.sagemaker_session.boto_region_name,
2594-
# ).to_json(),
2595-
# )
25962594

25972595
def delete_monitoring_schedule(self):
25982596
"""Deletes the monitoring schedule and its job definition."""
@@ -3381,6 +3379,8 @@ def update_monitoring_schedule(
33813379
constraints=None,
33823380
schedule_cron_expression=None,
33833381
enable_cloudwatch_metrics=None,
3382+
enable_automatic_dashboard=None,
3383+
dashboard_name=None,
33843384
role=None,
33853385
instance_count=None,
33863386
instance_type=None,
@@ -3472,13 +3472,13 @@ def update_monitoring_schedule(
34723472
logger.error(message)
34733473
raise ValueError(message)
34743474

3475-
# if enable_automatic_dashboard:
3476-
# self._check_dashboard_validity_without_checking_in_use(
3477-
# monitor_schedule_name=self.monitoring_schedule_name,
3478-
# enable_cloudwatch_metrics=enable_cloudwatch_metrics,
3479-
# enable_automatic_dashboard=enable_automatic_dashboard,
3480-
# dashboard_name=dashboard_name,
3481-
# )
3475+
if enable_automatic_dashboard:
3476+
self._check_dashboard_validity_without_checking_in_use(
3477+
monitor_schedule_name=self.monitoring_schedule_name,
3478+
enable_cloudwatch_metrics=enable_cloudwatch_metrics,
3479+
enable_automatic_dashboard=enable_automatic_dashboard,
3480+
dashboard_name=dashboard_name,
3481+
)
34823482

34833483
# Need to update schedule with a new job definition
34843484
job_desc = self.sagemaker_session.sagemaker_client.describe_model_quality_job_definition(
@@ -3549,24 +3549,24 @@ def update_monitoring_schedule(
35493549
logger.exception(message)
35503550
raise
35513551

3552-
# if enable_automatic_dashboard:
3553-
# if dashboard_name is None:
3554-
# dashboard_name = self.monitoring_schedule_name
3555-
# if isinstance(endpoint_input, EndpointInput):
3556-
# endpoint_name = endpoint_input.endpoint_name
3557-
# else:
3558-
# endpoint_name = endpoint_input
3559-
# cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
3560-
# cw_client.put_dashboard(
3561-
# DashboardName=dashboard_name,
3562-
# DashboardBody=AutomaticModelQualityDashboard(
3563-
# endpoint_name=endpoint_name,
3564-
# monitoring_schedule_name=self.monitoring_schedule_name,
3565-
# batch_transform_input=batch_transform_input,
3566-
# problem_type=problem_type,
3567-
# region_name=self.sagemaker_session.boto_region_name,
3568-
# ).to_json(),
3569-
# )
3552+
if enable_automatic_dashboard:
3553+
if dashboard_name is None:
3554+
dashboard_name = self.monitoring_schedule_name
3555+
if isinstance(endpoint_input, EndpointInput):
3556+
endpoint_name = endpoint_input.endpoint_name
3557+
else:
3558+
endpoint_name = endpoint_input
3559+
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
3560+
cw_client.put_dashboard(
3561+
DashboardName=dashboard_name,
3562+
DashboardBody=AutomaticModelQualityDashboard(
3563+
endpoint_name=endpoint_name,
3564+
monitoring_schedule_name=self.monitoring_schedule_name,
3565+
batch_transform_input=batch_transform_input,
3566+
problem_type=problem_type,
3567+
region_name=self.sagemaker_session.boto_region_name,
3568+
).to_json(),
3569+
)
35703570

35713571
def delete_monitoring_schedule(self):
35723572
"""Deletes the monitoring schedule and its job definition."""

0 commit comments

Comments
 (0)