Skip to content

Commit 9f1adf2

Browse files
author
Sushanth Sathish Kumar
committed
chore: code refatoring
1 parent 6924aa9 commit 9f1adf2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/sagemaker/model_monitor/model_monitoring.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ def _check_automatic_dashboard_validity(
15991599
dashboard_exists = True
16001600
try:
16011601
cw_client.get_dashboard(DashboardName=dashboard_name)
1602-
except Exception as e:
1602+
except Exception as _: # noqa: F841
16031603
dashboard_exists = False
16041604

16051605
if dashboard_exists:
@@ -2266,13 +2266,14 @@ def update_monitoring_schedule(
22662266
)
22672267
logger.error(message)
22682268
raise ValueError(message)
2269-
2269+
22702270
# error checking for dashboard
22712271
if enable_automatic_dashboard:
2272-
self._check_dashboard_validity_without_checking_in_use(
2272+
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
2273+
self._check_automatic_dashboard_validity(
2274+
cw_client=cw_client,
22732275
monitor_schedule_name=self.monitoring_schedule_name,
22742276
enable_cloudwatch_metrics=enable_cloudwatch_metrics,
2275-
enable_automatic_dashboard=enable_automatic_dashboard,
22762277
dashboard_name=dashboard_name,
22772278
)
22782279

@@ -2405,7 +2406,7 @@ def update_monitoring_schedule(
24052406
)
24062407

24072408
self._wait_for_schedule_changes_to_apply()
2408-
2409+
24092410
if enable_automatic_dashboard:
24102411
if dashboard_name is None:
24112412
dashboard_name = self.monitoring_schedule_name
@@ -2425,7 +2426,6 @@ def update_monitoring_schedule(
24252426
).to_json(),
24262427
)
24272428

2428-
24292429
def _update_data_quality_monitoring_schedule(
24302430
self,
24312431
endpoint_input=None,
@@ -2591,7 +2591,6 @@ def _update_data_quality_monitoring_schedule(
25912591
logger.exception(message)
25922592
raise
25932593

2594-
25952594
def delete_monitoring_schedule(self):
25962595
"""Deletes the monitoring schedule and its job definition."""
25972596
super(DefaultModelMonitor, self).delete_monitoring_schedule()
@@ -3473,10 +3472,11 @@ def update_monitoring_schedule(
34733472
raise ValueError(message)
34743473

34753474
if enable_automatic_dashboard:
3476-
self._check_dashboard_validity_without_checking_in_use(
3475+
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
3476+
self._check_automatic_dashboard_validity(
3477+
cw_client=cw_client,
34773478
monitor_schedule_name=self.monitoring_schedule_name,
34783479
enable_cloudwatch_metrics=enable_cloudwatch_metrics,
3479-
enable_automatic_dashboard=enable_automatic_dashboard,
34803480
dashboard_name=dashboard_name,
34813481
)
34823482

tests/unit/sagemaker/monitor/test_model_monitoring.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ def test_data_quality_monitor_invalid_create(data_quality_monitor, sagemaker_ses
957957
constraints=CONSTRAINTS,
958958
statistics=STATISTICS,
959959
)
960-
960+
961+
961962
def test_data_quality_monitor_invalid_dashboard_create(data_quality_monitor, sagemaker_session):
962963
# invalid: cannot create a monitoring schedule with an invalid dashboard name
963964
with pytest.raises(ValueError):
@@ -1102,6 +1103,7 @@ def _test_data_quality_monitor_create_schedule(
11021103
**expected_arguments
11031104
)
11041105

1106+
11051107
def _test_data_quality_batch_transform_monitor_create_schedule(
11061108
data_quality_monitor,
11071109
sagemaker_session,
@@ -1598,7 +1600,7 @@ def test_model_quality_monitor_with_dashboard(model_quality_monitor, sagemaker_s
15981600
model_quality_monitor=model_quality_monitor,
15991601
sagemaker_session=sagemaker_session,
16001602
)
1601-
1603+
16021604
_test_model_quality_monitor_delete_schedule(
16031605
model_quality_monitor=model_quality_monitor,
16041606
sagemaker_session=sagemaker_session,
@@ -1835,6 +1837,7 @@ def _test_model_quality_monitor_create_schedule(
18351837
Tags=TAGS,
18361838
)
18371839

1840+
18381841
def _test_model_quality_monitor_batch_transform_create_schedule(
18391842
model_quality_monitor,
18401843
sagemaker_session,

0 commit comments

Comments
 (0)