Skip to content

Commit fa5b5f0

Browse files
author
Sushanth Sathish Kumar
committed
feature: add enable_automatic_dashboard and dashboard_name parameter to update_monitoring_schedule
1 parent 42d773d commit fa5b5f0

File tree

6 files changed

+235
-103
lines changed

6 files changed

+235
-103
lines changed

src/sagemaker/dashboard/dashboard_variables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import json
2121

22+
2223
class DashboardVariable:
2324
"""
2425
Represents a dashboard variable used for dynamic configuration in CloudWatch Dashboards.
@@ -32,6 +33,7 @@ class DashboardVariable:
3233
search (str): Metric search expression to populate input options (required for 'select' or 'radio').
3334
populateFrom (str): Dimension name used to populate input options from search results.
3435
"""
36+
3537
def __init__(
3638
self, variable_type, variable_property, inputType, variable_id, label, search, populateFrom
3739
):
@@ -87,4 +89,3 @@ def to_json(self):
8789
str: JSON string representation of the variable properties.
8890
"""
8991
json.dumps(self.to_dict(), indent=4)
90-

src/sagemaker/dashboard/dashboard_widgets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
and ModelMonitor.
1818
"""
1919

20-
import json
20+
import json
21+
2122

2223
class DashboardWidgetProperties:
2324
"""
@@ -32,6 +33,7 @@ class DashboardWidgetProperties:
3233
title (str): Title displayed for the graph or number (optional).
3334
markdown (str): Markdown content to display within the widget (optional).
3435
"""
36+
3537
def __init__(
3638
self,
3739
view=None,
@@ -106,6 +108,7 @@ class DashboardWidget:
106108
type (str): Type of the widget.
107109
properties (DashboardWidgetProperties): Properties specific to the widget type.
108110
"""
111+
109112
def __init__(self, height, width, widget_type, properties=None):
110113
"""
111114
Initializes DashboardWidget instance.

src/sagemaker/dashboard/data_quality_dashboard.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
creation in ModelMonitor.
1515
"""
1616

17-
import json
17+
import json
1818
from sagemaker.dashboard.dashboard_variables import DashboardVariable
1919
from sagemaker.dashboard.dashboard_widgets import DashboardWidget, DashboardWidgetProperties
2020
from sagemaker.model_monitor.model_monitoring import EndpointInput
2121

22+
2223
class AutomaticDataQualityDashboard:
2324
DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE = (
2425
"{aws/sagemaker/Endpoints/data-metrics,Endpoint,Feature,MonitoringSchedule}"
@@ -28,11 +29,11 @@ class AutomaticDataQualityDashboard:
2829
)
2930

3031
def __init__(self, endpoint_name, monitoring_schedule_name, batch_transform_input, region_name):
31-
if type(endpoint_name) == EndpointInput:
32+
if type(endpoint_name) == EndpointInput:
3233
self.endpoint = endpoint_name.endpoint_name
3334
else:
3435
self.endpoint = endpoint_name
35-
36+
3637
self.monitoring_schedule = monitoring_schedule_name
3738
self.batch_transform = batch_transform_input
3839
self.region = region_name
@@ -96,15 +97,15 @@ def _generate_type_counts_widget(self):
9697
f"%^feature_string_counts_.*% OR "
9798
f"%^feature_boolean_counts_.*% OR "
9899
f"%^feature_unknown_counts_.*% "
99-
f"Feature=\"_\" "
100-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
100+
f'Feature="_" '
101+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
101102
f"'Average')"
102103
)
103104
}
104105
]
105106
],
106107
region=self.region,
107-
title="Type Counts"
108+
title="Type Counts",
108109
)
109110

110111
else:
@@ -121,16 +122,16 @@ def _generate_type_counts_widget(self):
121122
f"%^feature_string_counts_.*% OR "
122123
f"%^feature_boolean_counts_.*% OR "
123124
f"%^feature_unknown_counts_.*% "
124-
f"Endpoint=\"{self.endpoint}\" "
125-
f"Feature=\"_\" "
126-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
125+
f'Endpoint="{self.endpoint}" '
126+
f'Feature="_" '
127+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
127128
f"'Average')"
128129
)
129130
}
130131
]
131132
],
132133
region=self.region,
133-
title="Type Counts"
134+
title="Type Counts",
134135
)
135136

136137
return DashboardWidget(
@@ -148,15 +149,15 @@ def _generate_null_counts_widget(self):
148149
"expression": (
149150
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_BATCH_NAMESPACE} "
150151
f"%^feature_null_.*% OR %^feature_non_null_.*% "
151-
f"Feature=\"_\" "
152-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
152+
f'Feature="_" '
153+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
153154
f"'Average')"
154155
)
155156
}
156157
]
157158
],
158159
region=self.region,
159-
title="Missing Data Counts"
160+
title="Missing Data Counts",
160161
)
161162

162163
else:
@@ -167,12 +168,12 @@ def _generate_null_counts_widget(self):
167168
[
168169
{
169170
"expression": (
170-
f'SEARCH( \'{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} '
171-
f'%^feature_null_.*% OR %^feature_non_null_.*% '
171+
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
172+
f"%^feature_null_.*% OR %^feature_non_null_.*% "
172173
f'Endpoint="{self.endpoint}" '
173174
f'Feature="_" '
174175
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
175-
f'\'Average\')'
176+
f"'Average')"
176177
)
177178
}
178179
]
@@ -195,15 +196,15 @@ def _generate_estimated_unique_values_widget(self):
195196
"expression": (
196197
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_BATCH_NAMESPACE} "
197198
f"%^feature_estimated_unique_values_.*% "
198-
f"Feature=\"_\" "
199-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
199+
f'Feature="_" '
200+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
200201
f"'Average')"
201202
)
202203
}
203204
]
204205
],
205206
region=self.region,
206-
title="Estimated Unique Values"
207+
title="Estimated Unique Values",
207208
)
208209

209210
else:
@@ -216,16 +217,16 @@ def _generate_estimated_unique_values_widget(self):
216217
"expression": (
217218
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
218219
f"%^feature_estimated_unique_values_.*% "
219-
f"Endpoint=\"{self.endpoint}\" "
220-
f"Feature=\"_\" "
221-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
220+
f'Endpoint="{self.endpoint}" '
221+
f'Feature="_" '
222+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
222223
f"'Average')"
223224
)
224225
}
225226
]
226227
],
227228
region=self.region,
228-
title="Estimated Unique Values"
229+
title="Estimated Unique Values",
229230
)
230231

231232
return DashboardWidget(
@@ -246,15 +247,15 @@ def _generate_completeness_widget(self):
246247
"expression": (
247248
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_BATCH_NAMESPACE} "
248249
f"%^feature_completeness_.*% "
249-
f"Feature=\"_\" "
250-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
250+
f'Feature="_" '
251+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
251252
f"'Average')"
252253
)
253254
}
254255
]
255256
],
256257
region=self.region,
257-
title="Completeness"
258+
title="Completeness",
258259
)
259260

260261
else:
@@ -267,9 +268,9 @@ def _generate_completeness_widget(self):
267268
"expression": (
268269
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
269270
f"%^feature_completeness_.*% "
270-
f"Endpoint=\"{self.endpoint}\" "
271-
f"Feature=\"_\" "
272-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
271+
f'Endpoint="{self.endpoint}" '
272+
f'Feature="_" '
273+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
273274
f"'Average')"
274275
)
275276
}
@@ -294,8 +295,8 @@ def _generate_baseline_drift_widget(self):
294295
"expression": (
295296
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_BATCH_NAMESPACE} "
296297
f"%^feature_baseline_drift_.*% "
297-
f"Feature=\"_\" "
298-
f"MonitoringSchedule=\"{self.monitoring_schedule}\" ', "
298+
f'Feature="_" '
299+
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
299300
f"'Average')"
300301
)
301302
}
@@ -313,12 +314,12 @@ def _generate_baseline_drift_widget(self):
313314
[
314315
{
315316
"expression": (
316-
f'SEARCH( \'{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} '
317-
f'%^feature_baseline_drift_.*% '
317+
f"SEARCH( '{AutomaticDataQualityDashboard.DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
318+
f"%^feature_baseline_drift_.*% "
318319
f'Endpoint="{self.endpoint}" '
319320
f'Feature="_" '
320321
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
321-
f'\'Average\')'
322+
f"'Average')"
322323
)
323324
}
324325
]

0 commit comments

Comments
 (0)