Skip to content

Commit 6cd1f37

Browse files
authored
add perf tests (Azure#17519)
* add perf tests * update * update * updates
1 parent f44d28b commit 6cd1f37

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Metrics advisor Performance Tests
2+
3+
In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the `dev_requirements`.
4+
Start be creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7.
5+
6+
### Setup for test resources
7+
8+
These tests will run against a pre-configured metrics advisor service(see [Setting up Resource for Perf test Guide](https://microsoft.sharepoint.com/teams/AzureDeveloperExperience/_layouts/15/Doc.aspx?sourcedoc={b489fb65-ef3e-410c-a69e-c23fccf5fcca}&action=edit&wd=target%28Untitled%20Section.one%7C93e23c77-5539-4c7a-9059-efa745a43f58%2FSetting%20up%20Resource%20for%20Perf%20test%20Guide%7C395ad307-9fd1-4971-bcd5-6d336dde77cd%2F%29&wdorigin=703) about how to setup the instance and ingest data). The following environment variable will need to be set for the tests to access the live resources:
9+
```
10+
AZURE_METRICS_ADVISOR_ENDPOINT=<service endpoint>
11+
AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY=<service subscription key>
12+
AZURE_METRICS_ADVISOR_API_KEY=<service api key>
13+
AZURE_METRICS_ADVISOR_ANOMALY_ALERT_CONFIGURATION_ID=<anomaly alert configuration id>
14+
AZURE_METRICS_ADVISOR_ALERT_ID=<alert id>
15+
AZURE_METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID=<anomaly detection configuration id>
16+
AZURE_METRICS_ADVISOR_INCIDENT_ID=<incident id>
17+
```
18+
19+
### Setup for perf test runs
20+
21+
```cmd
22+
(env) ~/azure-ai-metricsadvisor> pip install -r dev_requirements.txt
23+
(env) ~/azure-ai-metricsadvisor> pip install -e .
24+
```
25+
26+
## Test commands
27+
28+
When `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the current module for runable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature).
29+
30+
```cmd
31+
(env) ~/azure-ai-metricsadvisor> cd tests
32+
(env) ~/azure-ai-metricsadvisor/tests> perfstress
33+
```
34+
Using the `perfstress` command alone will list the available perf tests found.
35+
36+
### Common perf command line options
37+
These options are available for all perf tests:
38+
- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10.
39+
- `--iterations=1` Number of test iterations to run. Default is 1.
40+
- `--parallel=1` Number of tests to run in parallel. Default is 1.
41+
- `--warmup=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5.
42+
- `--sync` Whether to run the tests in sync or async. Default is False (async). This flag must be used for Storage legacy tests, which do not support async.
43+
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
44+
45+
## Example command
46+
```cmd
47+
(env) ~/azure-ai-metricsadvisor/tests> perfstress ListAnomaliesTest
48+
(env) ~/azure-ai-metricsadvisor/tests> perfstress ListIncidentsTest
49+
(env) ~/azure-ai-metricsadvisor/tests> perfstress ListRootCausesTest
50+
```

sdk/metricsadvisor/azure-ai-metricsadvisor/tests/perfstress_tests/__init__.py

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import os
7+
8+
from azure_devtools.perfstress_tests import PerfStressTest
9+
10+
from azure.ai.metricsadvisor import MetricsAdvisorClient as SyncClient, MetricsAdvisorKeyCredential
11+
from azure.ai.metricsadvisor.aio import MetricsAdvisorClient as AsyncClient
12+
13+
14+
class ListAnomaliesTest(PerfStressTest):
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
service_endpoint = os.getenv("AZURE_METRICS_ADVISOR_ENDPOINT")
18+
subscription_key = os.getenv("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY")
19+
api_key = os.getenv("AZURE_METRICS_ADVISOR_API_KEY")
20+
self.anomaly_alert_configuration_id = os.getenv("AZURE_METRICS_ADVISOR_ANOMALY_ALERT_CONFIGURATION_ID")
21+
self.alert_id = os.getenv("AZURE_METRICS_ADVISOR_ALERT_ID")
22+
self.service_client = SyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
23+
self.async_service_client = AsyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
24+
25+
async def close(self):
26+
await self.async_service_client.close()
27+
await super().close()
28+
29+
def run_sync(self):
30+
results = self.service_client.list_anomalies(
31+
alert_configuration_id=self.anomaly_alert_configuration_id,
32+
alert_id=self.alert_id,
33+
)
34+
for _ in results:
35+
pass
36+
37+
async def run_async(self):
38+
results = self.async_service_client.list_anomalies(
39+
alert_configuration_id=self.anomaly_alert_configuration_id,
40+
alert_id=self.alert_id,
41+
)
42+
async for _ in results:
43+
pass
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import os
7+
import datetime
8+
from azure_devtools.perfstress_tests import PerfStressTest
9+
10+
from azure.ai.metricsadvisor import MetricsAdvisorClient as SyncClient, MetricsAdvisorKeyCredential
11+
from azure.ai.metricsadvisor.aio import MetricsAdvisorClient as AsyncClient
12+
13+
14+
class ListIncidentsTest(PerfStressTest):
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
service_endpoint = os.getenv("AZURE_METRICS_ADVISOR_ENDPOINT")
18+
subscription_key = os.getenv("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY")
19+
api_key = os.getenv("AZURE_METRICS_ADVISOR_API_KEY")
20+
self.anomaly_detection_configuration_id = os.getenv("AZURE_METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID")
21+
self.service_client = SyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
22+
self.async_service_client = AsyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
23+
24+
async def close(self):
25+
await self.async_service_client.close()
26+
await super().close()
27+
28+
def run_sync(self):
29+
results = self.service_client.list_incidents(
30+
detection_configuration_id=self.anomaly_detection_configuration_id,
31+
start_time=datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc),
32+
end_time=datetime.datetime(2020, 10, 21, tzinfo=datetime.timezone.utc),
33+
)
34+
for _ in results:
35+
pass
36+
37+
async def run_async(self):
38+
results = self.async_service_client.list_incidents(
39+
detection_configuration_id=self.anomaly_detection_configuration_id,
40+
start_time=datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc),
41+
end_time=datetime.datetime(2020, 10, 21, tzinfo=datetime.timezone.utc),
42+
)
43+
async for _ in results:
44+
pass
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import os
7+
8+
from azure_devtools.perfstress_tests import PerfStressTest
9+
10+
from azure.ai.metricsadvisor import MetricsAdvisorClient as SyncClient, MetricsAdvisorKeyCredential
11+
from azure.ai.metricsadvisor.aio import MetricsAdvisorClient as AsyncClient
12+
13+
14+
class ListRootCausesTest(PerfStressTest):
15+
def __init__(self, arguments):
16+
super().__init__(arguments)
17+
service_endpoint = os.getenv("AZURE_METRICS_ADVISOR_ENDPOINT")
18+
subscription_key = os.getenv("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY")
19+
api_key = os.getenv("AZURE_METRICS_ADVISOR_API_KEY")
20+
self.anomaly_detection_configuration_id = os.getenv("AZURE_METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID")
21+
self.incident_id = os.getenv("AZURE_METRICS_ADVISOR_INCIDENT_ID")
22+
self.service_client = SyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
23+
self.async_service_client = AsyncClient(service_endpoint, MetricsAdvisorKeyCredential(subscription_key, api_key))
24+
25+
async def close(self):
26+
await self.async_service_client.close()
27+
await super().close()
28+
29+
def run_sync(self):
30+
results = self.service_client.list_incident_root_causes(
31+
detection_configuration_id=self.anomaly_detection_configuration_id,
32+
incident_id=self.incident_id,
33+
)
34+
for _ in results:
35+
pass
36+
37+
async def run_async(self):
38+
results = self.async_service_client.list_incident_root_causes(
39+
detection_configuration_id=self.anomaly_detection_configuration_id,
40+
incident_id=self.incident_id,
41+
)
42+
async for _ in results:
43+
pass

0 commit comments

Comments
 (0)