@@ -1543,7 +1543,6 @@ def _check_dashboard_validity_without_checking_in_use(
1543
1543
self ,
1544
1544
monitor_schedule_name ,
1545
1545
enable_cloudwatch_metrics = True ,
1546
- enable_automatic_dashboard = False ,
1547
1546
dashboard_name = None ,
1548
1547
):
1549
1548
"""Checks if the parameters are valid, without checking if dashboard name is taken
@@ -1552,44 +1551,33 @@ def _check_dashboard_validity_without_checking_in_use(
1552
1551
monitor_schedule_name (str): Monitoring schedule name.
1553
1552
enable_cloudwatch_metrics (bool): Whether to publish cloudwatch metrics as part of
1554
1553
the baselining or monitoring jobs.
1555
- enable_automatic_dashboard (bool): Whether to publish dashboard as part of
1556
- the monitoring job.
1557
1554
dashboard_name (str): The name to use when publishing dashboard
1558
1555
"""
1559
- if ( not enable_cloudwatch_metrics ) and enable_automatic_dashboard :
1556
+ if not enable_cloudwatch_metrics :
1560
1557
message = (
1561
1558
"Could not create automatic dashboard. "
1562
1559
"Please set enable_cloudwatch_metrics to True."
1563
1560
)
1564
1561
_LOGGER .error (message )
1565
1562
raise ValueError (message )
1566
1563
1567
- if (not enable_automatic_dashboard ) and dashboard_name is not None :
1564
+ if dashboard_name is None :
1565
+ dashboard_name = monitor_schedule_name
1566
+ dashboard_name_validation = bool (re .match (r"^[0-9A-Za-z\-_]{1,255}$" , dashboard_name ))
1567
+ if not dashboard_name_validation :
1568
1568
message = (
1569
- "Parameter dashboard_name was provided, but enable_automatic_dashboard "
1570
- "parameter was False. Dashboard will not be generated."
1569
+ f"Dashboard name { dashboard_name } is not a valid dashboard name. "
1570
+ "Dashboard name can be at most 255 characters long "
1571
+ "and valid characters in dashboard names include '0-9A-Za-z-_'."
1571
1572
)
1572
- _LOGGER .warning (message )
1573
-
1574
- if enable_automatic_dashboard :
1575
- # verify that the provided dashboard name is not taken
1576
- dashboard_name = monitor_schedule_name if dashboard_name is None else dashboard_name
1577
-
1578
- dashboard_name_validation = bool (re .match (r"^[0-9A-Za-z\-_]{1,255}$" , dashboard_name ))
1579
- if not dashboard_name_validation :
1580
- message = (
1581
- f"Dashboard name { dashboard_name } is not a valid dashboard name. "
1582
- "Dashboard name can be at most 255 characters long "
1583
- "and valid characters in dashboard names include '0-9A-Za-z-_'."
1584
- )
1585
- _LOGGER .error (message )
1586
- raise ValueError (message )
1573
+ _LOGGER .error (message )
1574
+ raise ValueError (message )
1587
1575
1588
1576
def _check_automatic_dashboard_validity (
1589
1577
self ,
1578
+ cw_client ,
1590
1579
monitor_schedule_name ,
1591
1580
enable_cloudwatch_metrics = True ,
1592
- enable_automatic_dashboard = False ,
1593
1581
dashboard_name = None ,
1594
1582
):
1595
1583
"""Checks if the parameters provided to generate an automatic dashboard are valid
@@ -1598,35 +1586,30 @@ def _check_automatic_dashboard_validity(
1598
1586
monitor_schedule_name (str): Monitoring schedule name.
1599
1587
enable_cloudwatch_metrics (bool): Whether to publish cloudwatch metrics as part of
1600
1588
the baselining or monitoring jobs.
1601
- enable_automatic_dashboard (bool): Whether to publish dashboard as part of
1602
- the monitoring job.
1603
1589
dashboard_name (str): The name to use when publishing dashboard
1604
1590
"""
1605
1591
1606
1592
self ._check_dashboard_validity_without_checking_in_use (
1607
1593
monitor_schedule_name = monitor_schedule_name ,
1608
1594
enable_cloudwatch_metrics = enable_cloudwatch_metrics ,
1609
- enable_automatic_dashboard = enable_automatic_dashboard ,
1610
1595
dashboard_name = dashboard_name ,
1611
1596
)
1612
- cw_client = self .sagemaker_session .boto_session .client ("cloudwatch" )
1613
1597
1614
- if enable_automatic_dashboard :
1615
- try :
1616
- # try to access the dashboard to see if it exists already
1617
- cw_client .get_dashboard (DashboardName = dashboard_name )
1618
- message = (
1619
- f"Dashboard name { dashboard_name } is already in use. "
1620
- "Please provide a different dashboard name, or delete the already "
1621
- "existing dashboard."
1622
- )
1623
- _LOGGER .error (message )
1624
- raise ValueError (message )
1625
- except Exception as e :
1626
- _LOGGER .log (f"Correctly received error { e } ." )
1627
- # in this case, the dashboard name is not in use
1628
- # and we are free to write to it without overwriting any
1629
- # customer data.
1598
+ # flag to check if dashboard with name dashboard_name exists already
1599
+ dashboard_exists = True
1600
+ try :
1601
+ cw_client .get_dashboard (DashboardName = dashboard_name )
1602
+ except Exception as e :
1603
+ dashboard_exists = False
1604
+
1605
+ if dashboard_exists :
1606
+ message = (
1607
+ f"Dashboard name { dashboard_name } is already in use. "
1608
+ "Please provide a different dashboard name, or delete the already "
1609
+ "existing dashboard."
1610
+ )
1611
+ _LOGGER .error (message )
1612
+ raise ValueError (message )
1630
1613
1631
1614
def _create_monitoring_schedule_from_job_definition (
1632
1615
self ,
@@ -2113,10 +2096,11 @@ def create_monitoring_schedule(
2113
2096
)
2114
2097
2115
2098
if enable_automatic_dashboard :
2099
+ cw_client = self .sagemaker_session .boto_session .client ("cloudwatch" )
2116
2100
self ._check_automatic_dashboard_validity (
2101
+ cw_client = cw_client ,
2117
2102
monitor_schedule_name = monitor_schedule_name ,
2118
2103
enable_cloudwatch_metrics = enable_cloudwatch_metrics ,
2119
- enable_automatic_dashboard = enable_automatic_dashboard ,
2120
2104
dashboard_name = dashboard_name ,
2121
2105
)
2122
2106
@@ -2214,8 +2198,8 @@ def update_monitoring_schedule(
2214
2198
env = None ,
2215
2199
network_config = None ,
2216
2200
enable_cloudwatch_metrics = None ,
2217
- # enable_automatic_dashboard=False,
2218
- # dashboard_name=None,
2201
+ enable_automatic_dashboard = False ,
2202
+ dashboard_name = None ,
2219
2203
role = None ,
2220
2204
batch_transform_input = None ,
2221
2205
data_analysis_start_time = None ,
@@ -2302,8 +2286,6 @@ def update_monitoring_schedule(
2302
2286
env = env ,
2303
2287
network_config = network_config ,
2304
2288
enable_cloudwatch_metrics = enable_cloudwatch_metrics ,
2305
- # enable_automatic_dashboard=enable_automatic_dashboard,
2306
- # dashboard_name=dashboard_name,
2307
2289
role = role ,
2308
2290
batch_transform_input = batch_transform_input ,
2309
2291
data_analysis_start_time = data_analysis_start_time ,
@@ -2425,8 +2407,6 @@ def _update_data_quality_monitoring_schedule(
2425
2407
statistics = None ,
2426
2408
schedule_cron_expression = None ,
2427
2409
enable_cloudwatch_metrics = None ,
2428
- # enable_automatic_dashboard=False,
2429
- # dashboard_name=None,
2430
2410
role = None ,
2431
2411
instance_count = None ,
2432
2412
instance_type = None ,
@@ -3307,10 +3287,11 @@ def create_monitoring_schedule(
3307
3287
)
3308
3288
3309
3289
if enable_automatic_dashboard :
3290
+ cw_client = self .sagemaker_session .boto_session .client ("cloudwatch" )
3310
3291
self ._check_automatic_dashboard_validity (
3292
+ cw_client = cw_client ,
3311
3293
monitor_schedule_name = monitor_schedule_name ,
3312
3294
enable_cloudwatch_metrics = enable_cloudwatch_metrics ,
3313
- enable_automatic_dashboard = enable_automatic_dashboard ,
3314
3295
dashboard_name = dashboard_name ,
3315
3296
)
3316
3297
@@ -3373,8 +3354,6 @@ def create_monitoring_schedule(
3373
3354
raise
3374
3355
3375
3356
if enable_automatic_dashboard :
3376
- if dashboard_name is None :
3377
- dashboard_name = monitor_schedule_name
3378
3357
if isinstance (endpoint_input , EndpointInput ):
3379
3358
endpoint_name = endpoint_input .endpoint_name
3380
3359
else :
@@ -3402,8 +3381,6 @@ def update_monitoring_schedule(
3402
3381
constraints = None ,
3403
3382
schedule_cron_expression = None ,
3404
3383
enable_cloudwatch_metrics = None ,
3405
- # enable_automatic_dashboard=False,
3406
- # dashboard_name=None,
3407
3384
role = None ,
3408
3385
instance_count = None ,
3409
3386
instance_type = None ,
0 commit comments