Skip to content

Commit

Permalink
Ma test fixes (Azure#20946)
Browse files Browse the repository at this point in the history
* fix dimension filter

* update tests

* updates

* update
  • Loading branch information
xiangyan99 authored Sep 29, 2021
1 parent a6e0d12 commit 5aadfb2
Show file tree
Hide file tree
Showing 382 changed files with 15,861 additions and 57,703 deletions.
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 @@ -304,6 +304,7 @@ def sample_delete_alert_config(alert_config_id):
if len(alerts) > 0:
print("\n---Query anomalies using alert id...")
alert_id = alerts[0].id
print("alert_id: " + alert_id)
sample_list_anomalies_for_alert(alert_config.id, alert_id)
print("\n---Update an anomaly alert configuration...")
sample_update_alert_config(alert_config)
Expand Down
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 @@ -34,35 +34,34 @@ def sample_add_feedback():
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
metric_id = os.getenv("METRICS_ADVISOR_METRIC_ID")

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),
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={"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="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),
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)
Expand Down
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 Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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 @@ -220,7 +220,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 @@ -276,7 +276,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 @@ -344,7 +344,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 @@ -355,7 +355,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

0 comments on commit 5aadfb2

Please sign in to comment.