Skip to content

Data quality automatic dashboard #4785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
14dad53
feature: Added automatic dashboard feature for DefaultModelMonitor cr…
Jul 12, 2024
ee2a606
tests: Verify correctness of dashboard class and methods with basic u…
Jul 12, 2024
cfeb219
fix: fix dashboard tests, TODO: fix assertion error in test_automatic…
Jul 12, 2024
83661cf
feat: Add ability to create a model monitoring dashboard and refactor…
Jul 19, 2024
edc830c
chore: Add docstrings to functions and add check for the case where i…
Jul 19, 2024
15b5cdc
fix: Add strong regex checking for model quality dashboard
Jul 19, 2024
812228b
feature: add enable_automatic_dashboard and dashboard_name parameter …
Jul 22, 2024
04c912e
fix: Fix circular dependecy with EndpointInput and dashboards
Jul 23, 2024
1fb0692
fix: temporary fix to allow unit tests to pass
Jul 23, 2024
6854606
chore: fix style issues
Jul 24, 2024
b531ccf
test: add unit tests for dashboard generation and error handling
Jul 25, 2024
c2c9334
feature: add enable_automatic_dashboard and dashboard_name parameter …
Jul 27, 2024
90c400f
chore: code refatoring
Jul 30, 2024
7c65edf
fix: modify the mock boto client so that it correctly raises a Client…
Jul 31, 2024
69e8eae
tests: Add integration tests to publish dashboard, TODO: Verify dashb…
Aug 1, 2024
7737941
fix: Added additional filtering to dashboard variable in data quality…
Aug 2, 2024
34d21dc
fix: Fix source code to properly filter using dashboard variables and…
Aug 7, 2024
efde767
fix: Fix docstyle check related errors
Aug 8, 2024
efbeab3
fix: Fix trailing whitespace mistakes
Aug 8, 2024
827427a
fix: Fix all style checks
Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/sagemaker/dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Imports the classes in this module to simplify customer imports

Example:
>>> from sagemaker.dashboard import AutomaticDataQualityDashboard

"""
from __future__ import absolute_import

from sagemaker.dashboard.data_quality_dashboard import AutomaticDataQualityDashboard # noqa: F401
from sagemaker.dashboard.model_quality_dashboard import AutomaticModelQualityDashboard # noqa: F401
from sagemaker.dashboard.dashboard_variables import DashboardVariable # noqa: F401
from sagemaker.dashboard.dashboard_widgets import ( # noqa: F401
DashboardWidget,
DashboardWidgetProperties,
)
87 changes: 87 additions & 0 deletions src/sagemaker/dashboard/dashboard_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""This module contains code containing wrapper classes for dashboard variables in CloudWatch.

These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
and ModelMonitor.
"""
from __future__ import absolute_import
import json


class DashboardVariable:
"""Represents a dashboard variable used for dynamic configuration in CloudWatch Dashboards.

Attributes:
variable_type (str): Type of dashboard variable ('property' or 'pattern').
variable_property (str): Property affected by the variable, such as metric dimension.
inputType (str): Type of input field ('input', 'select', or 'radio') for user interaction.
id (str): Identifier for the variable, up to 32 characters.
label (str): Label displayed for the input field (optional, defaults based on context).
search (str): Metric search expression to populate fields (required for 'select').
populateFrom (str): Dimension name used to populate fields from search results.
"""

def __init__(
self, variable_type, variable_property, inputType, variable_id, label, search, populateFrom
):
"""Initializes a DashboardVariable instance.

Args:
variable_type (str): Type of dashboard variable ('property' or 'pattern').
variable_property (str): Property affected by the variable, such as metric dimension.
inputType (str): Type of input field ('input', 'select', or 'radio').
variable_id (str): Identifier for the variable, up to 32 characters.
label (str, optional): Label displayed for the input field (default is None).
search (str, optional): Metric search expression to populate input options.
populateFrom (str, optional): Dimension name used to populate field.
"""
self.variable_type = variable_type
self.variable_property = variable_property
self.inputType = inputType
self.id = variable_id
self.label = label
self.search = search
self.populateFrom = populateFrom

def to_dict(self):
"""Converts DashboardVariable instance to a dictionary representation.

Returns:
dict: Dictionary containing variable properties suitable for JSON serialization.
"""
variable_properties_dict = {}
if self.variable_type is not None:
variable_properties_dict["type"] = self.variable_type
if self.variable_property is not None:
variable_properties_dict["property"] = self.variable_property
if self.inputType is not None:
variable_properties_dict["inputType"] = self.inputType
if self.id is not None:
variable_properties_dict["id"] = self.id
if self.label is not None:
variable_properties_dict["label"] = self.label
if self.search is not None:
variable_properties_dict["search"] = self.search
if self.populateFrom is not None:
variable_properties_dict["populateFrom"] = self.populateFrom
return variable_properties_dict

def to_json(self):
"""Converts DashboardVariable instance to a JSON string.

Returns:
str: JSON string representation of the variable properties.
"""
json.dumps(self.to_dict(), indent=4)
144 changes: 144 additions & 0 deletions src/sagemaker/dashboard/dashboard_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""This module contains code containing wrapper classes for dashboard widgets in CloudWatch.

These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
and ModelMonitor.
"""
from __future__ import absolute_import
import json


class DashboardWidgetProperties:
"""Represents properties of a dashboard widget used for metrics in CloudWatch.

Attributes:
view (str): Type of visualization ('timeSeries', 'bar', 'pie', 'table').
stacked (bool): Whether to display graph as stacked lines (applies to 'timeSeries' view).
metrics (list): Array of metrics configurations for the widget.
region (str): Region associated with the metrics.
period (int): Period in seconds for data points on the graph.
title (str): Title displayed for the graph or number (optional).
markdown (str): Markdown content to display within the widget (optional).
"""

def __init__(
self,
view=None,
stacked=None,
metrics=None,
region=None,
period=None,
title=None,
markdown=None,
):
"""Initializes DashboardWidgetProperties instance.

Args:
view (str, optional): Type of visualization ('timeSeries', 'bar', 'pie', 'table').
stacked (bool, optional): Whether to display the graph as stacked lines.
metrics (list, optional): Array of metrics configurations for the widget.
region (str, optional): Region associated with the metrics.
period (int, optional): Period in seconds for data points on the graph.
title (str, optional): Title displayed for the graph or number.
markdown (str, optional): Markdown content to display within the widget.
"""
self.view = view
self.stacked = stacked
self.metrics = metrics
self.region = region
self.period = period
self.title = title
self.markdown = markdown

def to_dict(self):
"""Converts DashboardWidgetProperties instance to a dictionary representation.

Returns:
dict: Dictionary containing widget properties suitable for JSON serialization.
"""
widget_properties_dict = {}
if self.view is not None:
widget_properties_dict["view"] = self.view
if self.period is not None:
widget_properties_dict["period"] = self.period
if self.markdown is not None:
widget_properties_dict["markdown"] = self.markdown
if self.stacked is not None:
widget_properties_dict["stacked"] = self.stacked
if self.region is not None:
widget_properties_dict["region"] = self.region
if self.metrics is not None:
widget_properties_dict["metrics"] = self.metrics
if self.title is not None:
widget_properties_dict["title"] = self.title
return widget_properties_dict

def to_json(self):
"""Converts DashboardWidgetProperties instance to a JSON string.

Returns:
str: JSON string representation of the widget properties.
"""
json.dumps(self.to_dict(), indent=4)


class DashboardWidget:
"""Represents a widget in a CloudWatch dashboard.

Attributes:
height (int): Height of the widget.
width (int): Width of the widget.
type (str): Type of the widget.
properties (DashboardWidgetProperties): Properties specific to the widget type.
"""

def __init__(self, height, width, widget_type, properties=None):
"""Initializes DashboardWidget instance.

Args:
height (int): Height of the widget.
width (int): Width of the widget.
widget_type (str): Type of the widget.
properties (DashboardWidgetProperties, optional): Properties of the widget type.
"""
self.height = height
self.width = width
self.type = widget_type
self.properties = (
properties
if properties
else DashboardWidgetProperties(None, False, [], None, None, None)
)

def to_dict(self):
"""Converts DashboardWidget instance to a dictionary representation.

Returns:
dict: Dictionary containing widget attributes suitable for JSON serialization.
"""
return {
"height": self.height,
"width": self.width,
"type": self.type,
"properties": self.properties.to_dict(),
}

def to_json(self):
"""Converts DashboardWidget instance to a JSON string.

Returns:
str: JSON string representation of the widget attributes.
"""
return json.dumps(self.to_dict(), indent=4)
Loading
Loading