Skip to content

Commit 3b2d3ca

Browse files
Nivedit JainYashikaj14msyycBigCat20196Nivedit Jain
authored
Loadtestservice - SDK initial review (#25264)
* SDK generated autorest * upload function added * patch.py changed * upload updated * whl file removed * whls deleted * aio updated * spell check added * spell check * Update shared_requirements.txt * Update MANIFEST.in Co-authored-by: Yuchao Yan <[email protected]> * Update setup.py Co-authored-by: Yuchao Yan <[email protected]> * spell added * patch.py updated * linting corrected * Update allowed_pylint_failures.py * readme updated * patch.py updation * Update _patch.py * tests added * async naming * test and result * push the test result * fix * fix * tests added and async built * yaml added * yaml updated * sample and readme updated * fix ci.yml * more tests and samples addded and readme updated * tests * fix * fix2 * type added * type added * Update CHANGELOG.md * chnaged to developer * renamed package * chnaged ci files * linting fixes * changed namespace from analytics to developer * app_component naming cleaned * folded get_app_component * various name changes and added type hinting * lint changes * added wrapper for LoadTestClient * removed msrest dependencies * corrected Serializer method * test_smoke fixed * fixes in aio class * updates samples * namespace chg AppComponent, serverMetrics, test * updated samples * namespace changes done * LoadTestClient -> LoadTestingClient * apnd load_test to test_run & adminstration * added Readme Descirption * few changes in tests * moved SUBSCRIPTION_ID to .env * resloved readme issues by @iscai-msft in #24744 * resolved #discussion_r925248158 * resolving other issue by @iscai-msft #24744 * #25264#discussion_r925284462 * cleaned tests * namechanges * resolved folding issues * fixing dependencies verison * added tests for _patch(es) * removed subs id from recordings * fixing isodate requirements * removed SaaS key from smoke test * folder name chnage + setup.py cleaned * Readme changes suggested by @msyyc * added dependencies in shared_requirements.txt * removed os.environ from tests * liniting * removed async test * fixing tests * ci fix try * trying dev_tools * fix for azure-mgmt-loadtestservice dev_reqs * added async tests * some tests * cleaned setup * fixing async tests * added mgmt to loadtestservice to ci * changed fie mode from json to BinaryIO * reverting merge by @BigCat20196 * removed TEST_ID * solving issues by @lmazuel * update with autorest6.1.0 and update tests * update and format * fix playback failed * Update test_smoke.test_create_or_update_test_run.yaml * Update test_smoke.test_smoke_create_or_update_test.yaml * Update test_smoke_async.test_smoke_create_or_update_test.yaml * updated README Co-authored-by: Yashika Jain <[email protected]> Co-authored-by: Yuchao Yan <[email protected]> Co-authored-by: Yashika Jain <[email protected]> Co-authored-by: Jiefeng Chen (WICRESOFT NORTH AMERICA LTD) <[email protected]> Co-authored-by: Nivedit Jain <[email protected]> Co-authored-by: scbedd <[email protected]> Co-authored-by: BigCat20196 <[email protected]>
1 parent f7be268 commit 3b2d3ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+15176
-1
lines changed

.vscode/cspell.json

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/**",
106106
"sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/job_name_generator.py",
107107
"sdk/ml/azure-ai-ml/tests/**",
108+
"sdk/loadtestservice/azure-developer-loadtesting/**",
108109
"sdk/monitor/azure-monitor-ingestion/**",
109110
"eng/**/*.json",
110111
"eng/*.txt",
@@ -463,6 +464,12 @@
463464
"undoc"
464465
]
465466
},
467+
{
468+
"filename": "sdk/loadtestservice/azure-developer-loadtesting/azure/developer/loadtesting/**",
469+
"words":[
470+
"vusers"
471+
]
472+
},
466473
{
467474
"filename": "sdk/ml/azure-ai-ml/**",
468475
"words": [

eng/tox/allowed_pylint_failures.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
"azure-messaging-nspkg",
6060
"azure-agrifood-farming",
6161
"azure-ai-language-questionanswering",
62-
"azure-ai-language-conversations"
62+
"azure-ai-language-conversations",
63+
"azure-developer-loadtesting"
6364
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 1.0.0b1 (2022-07-28)
4+
5+
- Initial version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include *.md
2+
include LICENSE
3+
include azure/developer/loadtesting/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py
7+
include azure/developer/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
# Azure Developer LoadTesting client library for Python
3+
Azure Developer LoadTesting provides client library in python to the user by which they can interact natively with Load Test Service.The service is for performing the load test to optimize application performance, scalability or capacity. The user can get the client-side and server-side metrices to see the details reported by the test engine and information about your Azure application components.
4+
5+
6+
## Getting started
7+
8+
### Installating the package
9+
10+
```bash
11+
python -m pip install azure-developer-loadtesting
12+
```
13+
14+
#### Prequisites
15+
16+
- Python 3.7 or later is required to use this package.
17+
- You need an [Azure subscription][azure_sub] to use this package.
18+
- An existing Azure Developer LoadTesting instance.
19+
#### Create with an Azure Active Directory Credential
20+
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
21+
provide an instance of the desired credential type obtained from the
22+
[azure-identity][azure_identity_credentials] library.
23+
24+
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]
25+
26+
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
27+
As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:
28+
29+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
30+
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`
31+
32+
Use the returned token credential to authenticate the client:
33+
34+
```python
35+
from azure.developer.loadtesting import LoadTestingClient
36+
from azure.identity import DefaultAzureCredential
37+
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
38+
```
39+
40+
## Examples
41+
42+
### Creating a load test
43+
```python
44+
from azure.developer.loadtesting import LoadTestingClient
45+
from azure.identity import DefaultAzureCredential
46+
from azure.core.exceptions import HttpResponseError
47+
48+
TEST_ID = "some-test-id"
49+
DISPLAY_NAME = "new_namespace-new-namespace"
50+
SUBSCRIPTION_ID = os.environ["SUBSCRIPTION_ID"]
51+
52+
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
53+
54+
try:
55+
result = client.load_test_administration.create_or_update_test(
56+
TEST_ID,
57+
{
58+
"resourceId": f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/yashika-rg/providers/Microsoft.LoadTestService/loadtests/loadtestsdk",
59+
"description": "",
60+
"displayName": DISPLAY_NAME,
61+
"loadTestConfig": {
62+
"engineSize": "m",
63+
"engineInstances": 1,
64+
"splitAllCSVs": False,
65+
},
66+
"secrets": {},
67+
"environmentVariables": {},
68+
"passFailCriteria": {"passFailMetrics": {}},
69+
"keyvaultReferenceIdentityType": "SystemAssigned",
70+
"keyvaultReferenceIdentityId": None,
71+
},
72+
)
73+
print(result)
74+
except HttpResponseError as e:
75+
print('service responds error: {}'.format(e.response.json()))
76+
77+
```
78+
79+
### Uploading .jmx file to a Test
80+
```python
81+
from azure.developer.loadtesting import LoadTestingClient
82+
from azure.identity import DefaultAzureCredential
83+
from azure.core.exceptions import HttpResponseError
84+
85+
TEST_ID = "some-test-id"
86+
FILE_ID = "some-file-id"
87+
88+
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
89+
90+
try:
91+
92+
result = client.load_test_administration.upload_test_file(TEST_ID, FILE_ID, open("sample.jmx", "rb"))
93+
print(result)
94+
except HttpResponseError as e:
95+
print("Failed to send JSON message: {}".format(e.response.json()))
96+
```
97+
98+
### Running a Test
99+
```python
100+
from azure.developer.loadtesting import LoadTestingClient
101+
from azure.identity import DefaultAzureCredential
102+
from azure.core.exceptions import HttpResponseError
103+
104+
TEST_ID = "some-test-id"
105+
TEST_RUN_ID = "some-testrun-id"
106+
DISPLAY_NAME = "new_namespace-new-namespace"
107+
108+
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
109+
110+
try:
111+
result = client.load_test_runs.create_and_update_test(
112+
TEST_RUN_ID,
113+
{
114+
"testId": TEST_ID,
115+
"displayName": DISPLAY_NAME,
116+
"requestSamplers": [],
117+
"errors": [],
118+
"percentiles": ["90"],
119+
"groupByInterval": "5s",
120+
},
121+
)
122+
print(result)
123+
except HttpResponseError as e:
124+
print("Failed to send JSON message: {}".format(e.response.json()))
125+
```
126+
## Key concepts
127+
The following components make up the Azure Load Testing Service. The Azure Load Test client library for Python allows you to interact with each of these components through the use of a dedicated client object.
128+
129+
### Load testing resource
130+
The Load testing resource is the top-level resource for your load-testing activities. This resource provides a centralized place to view and manage load tests, test results, and related artifacts. A load testing resource contains zero or more load tests.
131+
132+
### Test
133+
A test specifies the test script, and configuration settings for running a load test. You can create one or more tests in an Azure Load Testing resource.
134+
135+
### Test Engine
136+
A test engine is computing infrastructure that runs the Apache JMeter test script. You can scale out your load test by configuring the number of test engines. The test script runs in parallel across the specified number of test engines.
137+
138+
### Test Run
139+
A test run represents one execution of a load test. It collects the logs associated with running the Apache JMeter script, the load test YAML configuration, the list of app components to monitor, and the results of the test.
140+
141+
### App Component
142+
When you run a load test for an Azure-hosted application, you can monitor resource metrics for the different Azure application components (server-side metrics). While the load test runs, and after completion of the test, you can monitor and analyze the resource metrics in the Azure Load Testing dashboard.
143+
144+
### Metrics
145+
During a load test, Azure Load Testing collects metrics about the test execution. There are two types of metrics:
146+
147+
1. Client-side metrics give you details reported by the test engine. These metrics include the number of virtual users, the request response time, the number of failed requests, or the number of requests per second.
148+
149+
2. Server-side metrics are available for Azure-hosted applications and provide information about your Azure application components. Metrics can be for the number of database reads, the type of HTTP responses, or container resource consumption.
150+
151+
## Troubleshooting
152+
More about it is coming soon...
153+
154+
## Next steps
155+
156+
More examples are coming soon...
157+
158+
## Contributing
159+
160+
This project welcomes contributions and suggestions. Most contributions require
161+
you to agree to a Contributor License Agreement (CLA) declaring that you have
162+
the right to, and actually do, grant us the rights to use your contribution.
163+
For details, visit https://cla.microsoft.com.
164+
165+
When you submit a pull request, a CLA-bot will automatically determine whether
166+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
167+
comment). Simply follow the instructions provided by the bot. You will only
168+
need to do this once across all repos using our CLA.
169+
170+
This project has adopted the
171+
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
172+
see the Code of Conduct FAQ or contact [email protected] with any
173+
additional questions or comments.
174+
175+
<!-- LINKS -->
176+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
177+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
178+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
179+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
180+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
181+
[pip]: https://pypi.org/project/pip/
182+
[azure_sub]: https://azure.microsoft.com/free/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._client import LoadTestingClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = ["LoadTestingClient"]
22+
__all__.extend([p for p in _patch_all if p not in __all__])
23+
24+
_patch_sdk()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any, TYPE_CHECKING
11+
12+
from azure.core import PipelineClient
13+
from azure.core.rest import HttpRequest, HttpResponse
14+
15+
from ._configuration import LoadTestingClientConfiguration
16+
from ._serialization import Deserializer, Serializer
17+
from .operations import AppComponentOperations, ServerMetricsOperations, TestOperations, TestRunOperations
18+
19+
if TYPE_CHECKING:
20+
# pylint: disable=unused-import,ungrouped-imports
21+
from typing import Dict
22+
23+
from azure.core.credentials import TokenCredential
24+
25+
26+
class LoadTestingClient: # pylint: disable=client-accepts-api-version-keyword
27+
"""These APIs allow end users to create, view and run load tests using Azure Load Test Service.
28+
29+
:ivar app_component: AppComponentOperations operations
30+
:vartype app_component: azure.developer.loadtesting.operations.AppComponentOperations
31+
:ivar server_metrics: ServerMetricsOperations operations
32+
:vartype server_metrics: azure.developer.loadtesting.operations.ServerMetricsOperations
33+
:ivar test: TestOperations operations
34+
:vartype test: azure.developer.loadtesting.operations.TestOperations
35+
:ivar test_run: TestRunOperations operations
36+
:vartype test_run: azure.developer.loadtesting.operations.TestRunOperations
37+
:param endpoint: URL to perform data plane API operations on the resource. Required.
38+
:type endpoint: str
39+
:param credential: Credential needed for the client to connect to Azure. Required.
40+
:type credential: ~azure.core.credentials.TokenCredential
41+
:keyword api_version: Api Version. Default value is "2022-06-01-preview". Note that overriding
42+
this default value may result in unsupported behavior.
43+
:paramtype api_version: str
44+
"""
45+
46+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
47+
_endpoint = "https://{Endpoint}"
48+
self._config = LoadTestingClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
49+
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
50+
51+
self._serialize = Serializer()
52+
self._deserialize = Deserializer()
53+
self._serialize.client_side_validation = False
54+
self.app_component = AppComponentOperations(self._client, self._config, self._serialize, self._deserialize)
55+
self.server_metrics = ServerMetricsOperations(self._client, self._config, self._serialize, self._deserialize)
56+
self.test = TestOperations( # type: ignore # pylint: disable=abstract-class-instantiated
57+
self._client, self._config, self._serialize, self._deserialize
58+
)
59+
self.test_run = TestRunOperations(self._client, self._config, self._serialize, self._deserialize)
60+
61+
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
62+
"""Runs the network request through the client's chained policies.
63+
64+
>>> from azure.core.rest import HttpRequest
65+
>>> request = HttpRequest("GET", "https://www.example.org/")
66+
<HttpRequest [GET], url: 'https://www.example.org/'>
67+
>>> response = client.send_request(request)
68+
<HttpResponse: 200 OK>
69+
70+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
71+
72+
:param request: The network request you want to make. Required.
73+
:type request: ~azure.core.rest.HttpRequest
74+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
75+
:return: The response of your network call. Does not do error handling on your response.
76+
:rtype: ~azure.core.rest.HttpResponse
77+
"""
78+
79+
request_copy = deepcopy(request)
80+
path_format_arguments = {
81+
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
82+
}
83+
84+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
85+
return self._client.send_request(request_copy, **kwargs)
86+
87+
def close(self):
88+
# type: () -> None
89+
self._client.close()
90+
91+
def __enter__(self):
92+
# type: () -> LoadTestingClient
93+
self._client.__enter__()
94+
return self
95+
96+
def __exit__(self, *exc_details):
97+
# type: (Any) -> None
98+
self._client.__exit__(*exc_details)

0 commit comments

Comments
 (0)