Skip to content

feat: Support for one time monitoring schedule #4131

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

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 46 additions & 2 deletions src/sagemaker/model_monitor/clarify_model_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def create_monitoring_schedule(
schedule_cron_expression=None,
enable_cloudwatch_metrics=True,
batch_transform_input=None,
data_analysis_start_time=None,
data_analysis_end_time=None,
):
"""Creates a monitoring schedule.

Expand All @@ -586,6 +588,10 @@ def create_monitoring_schedule(
the baselining or monitoring jobs. (default: True)
batch_transform_input (sagemaker.model_monitor.BatchTransformInput): Inputs to run
the monitoring schedule on the batch transform (default: None)
data_analysis_start_time (str): Start time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
data_analysis_end_time (str): End time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
"""
# we default ground_truth_input to None in the function signature
# but verify they are giving here for positional argument
Expand All @@ -610,6 +616,12 @@ def create_monitoring_schedule(
_LOGGER.error(message)
raise ValueError(message)

self._check_monitoring_schedule_cron_validity(
schedule_cron_expression=schedule_cron_expression,
data_analysis_start_time=data_analysis_start_time,
data_analysis_end_time=data_analysis_end_time,
)

# create job definition
monitor_schedule_name = self._generate_monitoring_schedule_name(
schedule_name=monitor_schedule_name
Expand Down Expand Up @@ -649,6 +661,8 @@ def create_monitoring_schedule(
monitor_schedule_name=monitor_schedule_name,
job_definition_name=new_job_definition_name,
schedule_cron_expression=schedule_cron_expression,
data_analysis_start_time=data_analysis_start_time,
data_analysis_end_time=data_analysis_end_time,
)
self.job_definition_name = new_job_definition_name
self.monitoring_schedule_name = monitor_schedule_name
Expand Down Expand Up @@ -684,6 +698,8 @@ def update_monitoring_schedule(
env=None,
network_config=None,
batch_transform_input=None,
data_analysis_start_time=None,
data_analysis_end_time=None,
):
"""Updates the existing monitoring schedule.

Expand Down Expand Up @@ -778,7 +794,12 @@ def update_monitoring_schedule(
)
self.sagemaker_session.sagemaker_client.create_model_bias_job_definition(**request_dict)
try:
self._update_monitoring_schedule(new_job_definition_name, schedule_cron_expression)
self._update_monitoring_schedule(
new_job_definition_name,
schedule_cron_expression,
data_analysis_start_time=data_analysis_start_time,
data_analysis_end_time=data_analysis_end_time,
)
self.job_definition_name = new_job_definition_name
if role is not None:
self.role = role
Expand Down Expand Up @@ -988,6 +1009,8 @@ def create_monitoring_schedule(
schedule_cron_expression=None,
enable_cloudwatch_metrics=True,
batch_transform_input=None,
data_analysis_start_time=None,
data_analysis_end_time=None,
):
"""Creates a monitoring schedule.

Expand All @@ -1011,6 +1034,10 @@ def create_monitoring_schedule(
the baselining or monitoring jobs.
batch_transform_input (sagemaker.model_monitor.BatchTransformInput): Inputs to
run the monitoring schedule on the batch transform
data_analysis_start_time (str): Start time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
data_analysis_end_time (str): End time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
"""
if self.job_definition_name is not None or self.monitoring_schedule_name is not None:
message = (
Expand All @@ -1030,6 +1057,12 @@ def create_monitoring_schedule(
_LOGGER.error(message)
raise ValueError(message)

self._check_monitoring_schedule_cron_validity(
schedule_cron_expression=schedule_cron_expression,
data_analysis_start_time=data_analysis_start_time,
data_analysis_end_time=data_analysis_end_time,
)

# create job definition
monitor_schedule_name = self._generate_monitoring_schedule_name(
schedule_name=monitor_schedule_name
Expand Down Expand Up @@ -1104,6 +1137,8 @@ def update_monitoring_schedule(
env=None,
network_config=None,
batch_transform_input=None,
data_analysis_start_time=None,
data_analysis_end_time=None,
):
"""Updates the existing monitoring schedule.

Expand Down Expand Up @@ -1144,6 +1179,10 @@ def update_monitoring_schedule(
inter-container traffic, security group IDs, and subnets.
batch_transform_input (sagemaker.model_monitor.BatchTransformInput): Inputs to
run the monitoring schedule on the batch transform
data_analysis_start_time (str): Start time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
data_analysis_end_time (str): End time for the data analysis window
for the one time monitoring schedule (NOW), e.g. "-PT1H" (default: None)
"""
valid_args = {
arg: value for arg, value in locals().items() if arg != "self" and value is not None
Expand Down Expand Up @@ -1200,7 +1239,12 @@ def update_monitoring_schedule(
**request_dict
)
try:
self._update_monitoring_schedule(new_job_definition_name, schedule_cron_expression)
self._update_monitoring_schedule(
new_job_definition_name,
schedule_cron_expression,
data_analysis_start_time=data_analysis_start_time,
data_analysis_end_time=data_analysis_end_time,
)
self.job_definition_name = new_job_definition_name
if role is not None:
self.role = role
Expand Down
5 changes: 5 additions & 0 deletions src/sagemaker/model_monitor/cron_expression_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ def daily_every_x_hours(hour_interval, starting_hour=0):

"""
return "cron(0 {}/{} ? * * *)".format(starting_hour, hour_interval)

@staticmethod
def now():
"""Returns the string used to depict the one-time schedule"""
return "NOW"
Loading