Skip to content
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

Ma test fixes #20946

Merged
merged 4 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion sdk/metricsadvisor/azure-ai-metricsadvisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ data_feed = client.create_data_feed(
],
dimensions=[
DataFeedDimension(name="category", display_name="Category"),
DataFeedDimension(name="city", display_name="City")
DataFeedDimension(name="region", display_name="region")
],
timestamp_column="Timestamp"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def list_anomaly_dimension_values(

skip = kwargs.pop("skip", None)
dimension = kwargs.pop("dimension_filter", None)
dimension_filter = DimensionGroupIdentity(dimension=dimension)
dimension_filter = DimensionGroupIdentity(dimension=dimension) if dimension else None
converted_start_time = convert_datetime(start_time)
converted_end_time = convert_datetime(end_time)
anomaly_dimension_query = AnomalyDimensionQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def list_anomaly_dimension_values(

skip = kwargs.pop("skip", None)
dimension = kwargs.pop("dimension_filter", None)
dimension_filter = DimensionGroupIdentity(dimension=dimension)
dimension_filter = DimensionGroupIdentity(dimension=dimension) if dimension else None
converted_start_time = convert_datetime(start_time)
converted_end_time = convert_datetime(end_time)
anomaly_dimension_query = AnomalyDimensionQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def sample_update_alert_config_async(alert_config):
detection_configuration_id=detection_configuration_id,
alert_scope=MetricAnomalyAlertScope(
scope_type="SeriesGroup",
series_group_in_scope={'city': 'Shenzhen'}
series_group_in_scope={'region': 'Shenzhen'}
),
alert_conditions=MetricAnomalyAlertConditions(
metric_boundary_condition=MetricBoundaryCondition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def sample_create_data_feed_async():
],
dimensions=[
DataFeedDimension(name="category", display_name="Category"),
DataFeedDimension(name="city", display_name="City")
DataFeedDimension(name="region", display_name="region")
],
timestamp_column="Timestamp"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ async def sample_update_detection_config_async(detection_config):
detection_config,
series_group_detection_conditions=[
MetricSeriesGroupDetectionCondition(
series_group_key={"city": "Seoul"},
series_group_key={"region": "Seoul"},
smart_detection_condition=smart_detection_condition
)
],
series_detection_conditions=[
MetricSingleSeriesDetectionCondition(
series_key={"city": "Osaka", "category": "Cell Phones"},
series_key={"region": "Osaka", "category": "Cell Phones"},
smart_detection_condition=smart_detection_condition
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def sample_list_metric_enriched_series_data_async():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
series_identity = {"city": "Los Angeles"}
series_identity = {"region": "Los Angeles"}

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand All @@ -69,7 +69,7 @@ async def sample_list_anomaly_dimension_values_async():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
dimension_name = "city"
dimension_name = "region"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand All @@ -95,7 +95,7 @@ async def sample_list_metric_dimension_values_async():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")
dimension_name = "city"
dimension_name = "region"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand Down Expand Up @@ -130,7 +130,7 @@ async def sample_list_metric_series_data_async():
start_time=datetime.datetime(2020, 1, 1),
end_time=datetime.datetime(2020, 10, 21),
series_keys=[
{"city": "Los Angeles", "category": "Homemade"}
{"region": "Los Angeles", "category": "Homemade"}
]
)
async for result in results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def sample_list_alerts(alert_config_id):

results = client.list_alerts(
alert_configuration_id=alert_config_id,
start_time=datetime.datetime(2020, 1, 1),
end_time=datetime.datetime(2020, 9, 9),
start_time=datetime.datetime(2021, 1, 1),
end_time=datetime.datetime(2021, 9, 9),
time_mode="AnomalyTime",
)

Expand Down Expand Up @@ -243,7 +243,7 @@ def sample_update_alert_config(alert_config):
detection_configuration_id=detection_configuration_id,
alert_scope=MetricAnomalyAlertScope(
scope_type="SeriesGroup",
series_group_in_scope={'city': 'Shenzhen'}
series_group_in_scope={'region': 'Shenzhen'}
),
alert_conditions=MetricAnomalyAlertConditions(
metric_boundary_condition=MetricBoundaryCondition(
Expand Down Expand Up @@ -293,19 +293,20 @@ def sample_delete_alert_config(alert_config_id):

if __name__ == '__main__':
print("---Creating anomaly alert configuration...")
alert_config = sample_create_alert_config()
# alert_config = sample_create_alert_config()
print("Anomaly alert configuration successfully created...")
print("\n---Get an anomaly alert configuration...")
sample_get_alert_config(alert_config.id)
# sample_get_alert_config(alert_config.id)
print("\n---List anomaly alert configurations...")
sample_list_alert_configs()
# sample_list_alert_configs()
print("\n---Query anomaly detection results...")
alerts = sample_list_alerts(alert_config.id)
alerts = sample_list_alerts("1c1575d8-b09e-40c3-a3c0-d459c64d8382")
if len(alerts) > 0:
print("\n---Query anomalies using alert id...")
alert_id = alerts[0].id
sample_list_anomalies_for_alert(alert_config.id, alert_id)
print("alert_id: " + alert_id)
sample_list_anomalies_for_alert("1c1575d8-b09e-40c3-a3c0-d459c64d8382", alert_id)
print("\n---Update an anomaly alert configuration...")
sample_update_alert_config(alert_config)
# sample_update_alert_config(alert_config)
print("\n---Delete an anomaly alert configuration...")
sample_delete_alert_config(alert_config.id)
# sample_delete_alert_config(alert_config.id)
xiangyan99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def sample_create_data_feed():
],
dimensions=[
DataFeedDimension(name="category", display_name="Category"),
DataFeedDimension(name="city", display_name="City")
DataFeedDimension(name="region", display_name="region")
],
timestamp_column="Timestamp"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ def sample_update_detection_config(detection_config):
detection_config,
series_group_detection_conditions=[
MetricSeriesGroupDetectionCondition(
series_group_key={"city": "Seoul"},
series_group_key={"region": "Seoul"},
smart_detection_condition=smart_detection_condition
)
],
series_detection_conditions=[
MetricSingleSeriesDetectionCondition(
series_key={"city": "Osaka", "category": "Cell Phones"},
series_key={"region": "Osaka", "category": "Cell Phones"},
smart_detection_condition=smart_detection_condition
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ def sample_add_feedback():
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")

# metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")
metric_id = "390d1139-98fb-45af-b831-8d5ad61b150a"
client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))

anomaly_feedback = AnomalyFeedback(metric_id=metric_id,
dimension_key={"Dim1": "Common Lime"},
start_time=datetime.datetime(2020, 8, 5),
end_time=datetime.datetime(2020, 8, 7),
dimension_key={"category": "Shoes Handbags & Sunglasses"},
start_time=datetime.datetime(2021, 8, 5),
end_time=datetime.datetime(2021, 8, 7),
value="NotAnomaly")
client.add_feedback(anomaly_feedback)

change_point_feedback = ChangePointFeedback(metric_id=metric_id,
dimension_key={"Dim1": "Common Lime"},
start_time=datetime.datetime(2020, 8, 5),
end_time=datetime.datetime(2020, 8, 7),
value="NotChangePoint")
client.add_feedback(change_point_feedback)

comment_feedback = CommentFeedback(metric_id=metric_id,
dimension_key={"Dim1": "Common Lime"},
start_time=datetime.datetime(2020, 8, 5),
end_time=datetime.datetime(2020, 8, 7),
value="comment")
client.add_feedback(comment_feedback)

period_feedback = PeriodFeedback(metric_id=metric_id,
dimension_key={"Dim1": "Common Lime"},
start_time=datetime.datetime(2020, 8, 5),
end_time=datetime.datetime(2020, 8, 7),
period_type="AssignValue",
value=2)
client.add_feedback(period_feedback)
# change_point_feedback = ChangePointFeedback(metric_id=metric_id,
# dimension_key={"category": "Shoes Handbags & Sunglasses"},
# start_time=datetime.datetime(2021, 8, 5),
# end_time=datetime.datetime(2021, 8, 7),
# value="NotChangePoint")
# client.add_feedback(change_point_feedback)
#
# comment_feedback = CommentFeedback(metric_id=metric_id,
# dimension_key={"category": "Shoes Handbags & Sunglasses"},
# start_time=datetime.datetime(2021, 8, 5),
# end_time=datetime.datetime(2021, 8, 7),
# value="comment")
# client.add_feedback(comment_feedback)
#
# period_feedback = PeriodFeedback(metric_id=metric_id,
# dimension_key={"category": "Shoes Handbags & Sunglasses"},
# start_time=datetime.datetime(2021, 8, 5),
# end_time=datetime.datetime(2021, 8, 7),
# period_type="AssignValue",
# value=2)
# client.add_feedback(period_feedback)
# [END add_feedback]


Expand Down Expand Up @@ -93,7 +93,8 @@ def sample_list_feedback():
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")
# metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")
metric_id = "390d1139-98fb-45af-b831-8d5ad61b150a"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand All @@ -109,6 +110,6 @@ def sample_list_feedback():
sample_add_feedback()
print("Feedback successfully created...")
print("\n---Get a feedback...")
sample_get_feedback()
# sample_get_feedback()
print("\n---List feedbacks...")
sample_list_feedback()
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ def sample_delete_hook(hook_id):
print("\n---List hooks...")
sample_list_hooks()
print("\n---Update a hook...")
sample_update_hook(hook)
# sample_update_hook(hook)
print("\n---Delete a hook...")
sample_delete_hook(hook.id)
# sample_delete_hook(hook.id)
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def sample_list_incidents_for_detection_configuration():
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
# detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
detection_configuration_id = "efaee305-f049-43ec-9f9b-76026d55c14a"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
results = client.list_incidents(
detection_configuration_id=detection_configuration_id,
start_time=datetime.datetime(2020, 1, 1),
end_time=datetime.datetime(2020, 9, 9),
start_time=datetime.datetime(2021, 1, 1),
end_time=datetime.datetime(2021, 9, 9),
)
for result in results:
print("Metric id: {}".format(result.metric_id))
Expand All @@ -60,8 +61,8 @@ def sample_list_incident_root_cause():
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
incident_id = os.getenv("METRICS_ADVISOR_INCIDENT_ID")
detection_configuration_id = "efaee305-f049-43ec-9f9b-76026d55c14a"
incident_id = "aee0225fd93cfe42ec4acd365613c857-17bb8679000"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand Down Expand Up @@ -101,9 +102,9 @@ def sample_list_incidents_for_alert():

if __name__ == '__main__':
print("---List incidents for detection configuration...")
sample_list_incidents_for_detection_configuration()
# sample_list_incidents_for_detection_configuration()
print("---List root causes...")
sample_list_incident_root_cause()
print("---List incidents for alert configuration...")
sample_list_incidents_for_alert()
# sample_list_incidents_for_alert()

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def sample_list_metric_enriched_series_data():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
series_identity = {"city": "Los Angeles"}
series_identity = {"region": "Los Angeles"}

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand All @@ -65,7 +65,7 @@ def sample_list_anomaly_dimension_values():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
dimension_name = "city"
dimension_name = "region"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand All @@ -89,7 +89,7 @@ def sample_list_metric_dimension_values():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")
dimension_name = "city"
dimension_name = "region"

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
Expand Down Expand Up @@ -121,7 +121,7 @@ def sample_list_metric_series_data():
start_time=datetime.datetime(2020, 1, 1),
end_time=datetime.datetime(2020, 10, 21),
series_keys=[
{"city": "Los Angeles", "category": "Homemade"}
{"region": "Los Angeles", "category": "Homemade"}
]
)
for result in results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def _create_data_feed(self, name):
],
dimensions=[
DataFeedDimension(name="category"),
DataFeedDimension(name="city")
DataFeedDimension(name="region")
],
),
ingestion_settings="2019-10-01T00:00:00Z",
Expand Down Expand Up @@ -222,7 +222,7 @@ async def _create_data_feed_for_update(self, name):
],
dimensions=[
DataFeedDimension(name="category", display_name="display category"),
DataFeedDimension(name="city", display_name="display city")
DataFeedDimension(name="region", display_name="display city")
],
timestamp_column="Timestamp"
),
Expand Down Expand Up @@ -278,7 +278,7 @@ async def _create_alert_config_for_update(self, name):
detection_configuration_id=detection_config.id,
alert_scope=MetricAnomalyAlertScope(
scope_type="SeriesGroup",
series_group_in_scope={'city': 'Shenzhen'}
series_group_in_scope={'region': 'Shenzhen'}
),
alert_conditions=MetricAnomalyAlertConditions(
severity_condition=SeverityCondition(
Expand Down Expand Up @@ -346,7 +346,7 @@ async def _create_detection_config_for_update(self, name):
)
),
series_detection_conditions=[MetricSingleSeriesDetectionCondition(
series_key={"city": "Shenzhen", "category": "Jewelry"},
series_key={"region": "Shenzhen", "category": "Jewelry"},
smart_detection_condition=SmartDetectionCondition(
anomaly_detector_direction="Both",
sensitivity=63,
Expand All @@ -357,7 +357,7 @@ async def _create_detection_config_for_update(self, name):
)
)],
series_group_detection_conditions=[MetricSeriesGroupDetectionCondition(
series_group_key={"city": "Sao Paulo"},
series_group_key={"region": "Sao Paulo"},
smart_detection_condition=SmartDetectionCondition(
anomaly_detector_direction="Both",
sensitivity=63,
Expand Down
Loading