Microsoft Azure Developer LoadTesting Client Library for Python
Project description
Azure Developer LoadTesting client library for Python
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.
Getting started
Installating the package
python -m pip install azure-developer-loadtesting
Prequisites
- Python 3.7 or later is required to use this package.
- You need an Azure subscription to use this package.
- An existing Azure Developer LoadTesting instance.
Create with an Azure Active Directory Credential
To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the azure-identity library.
To authenticate with AAD, you must first pip install azure-identity
After setup, you can choose which type of credential from azure.identity to use. As an example, DefaultAzureCredential can be used to authenticate the client:
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID
, AZURE_TENANT_ID
, AZURE_CLIENT_SECRET
Use the returned token credential to authenticate the client:
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
Examples
Creating a load test
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError
TEST_ID = "some-test-id"
DISPLAY_NAME = "new_namespace-new-namespace"
SUBSCRIPTION_ID = os.environ["SUBSCRIPTION_ID"]
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
try:
result = client.load_test_administration.create_or_update_test(
TEST_ID,
{
"resourceId": f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/yashika-rg/providers/Microsoft.LoadTestService/loadtests/loadtestsdk",
"description": "",
"displayName": DISPLAY_NAME,
"loadTestConfig": {
"engineSize": "m",
"engineInstances": 1,
"splitAllCSVs": False,
},
"secrets": {},
"environmentVariables": {},
"passFailCriteria": {"passFailMetrics": {}},
"keyvaultReferenceIdentityType": "SystemAssigned",
"keyvaultReferenceIdentityId": None,
},
)
print(result)
except HttpResponseError as e:
print('service responds error: {}'.format(e.response.json()))
Uploading .jmx file to a Test
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError
TEST_ID = "some-test-id"
FILE_ID = "some-file-id"
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
try:
result = client.load_test_administration.upload_test_file(TEST_ID, FILE_ID, open("sample.jmx", "rb"))
print(result)
except HttpResponseError as e:
print("Failed to send JSON message: {}".format(e.response.json()))
Running a Test
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError
TEST_ID = "some-test-id"
TEST_RUN_ID = "some-testrun-id"
DISPLAY_NAME = "new_namespace-new-namespace"
client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
try:
result = client.load_test_runs.create_and_update_test(
TEST_RUN_ID,
{
"testId": TEST_ID,
"displayName": DISPLAY_NAME,
"requestSamplers": [],
"errors": [],
"percentiles": ["90"],
"groupByInterval": "5s",
},
)
print(result)
except HttpResponseError as e:
print("Failed to send JSON message: {}".format(e.response.json()))
Key concepts
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.
Load testing resource
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.
Test
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.
Test Engine
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.
Test Run
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.
App Component
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.
Metrics
During a load test, Azure Load Testing collects metrics about the test execution. There are two types of metrics:
-
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.
-
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.
Troubleshooting
More about it is coming soon...
Next steps
More examples are coming soon...
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file azure-developer-loadtesting-1.0.0b1.zip
.
File metadata
- Download URL: azure-developer-loadtesting-1.0.0b1.zip
- Upload date:
- Size: 91.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.28.1 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d06514593fca203bfb898f41055836980af2b7b1a6140f7b8b4002610d71dee |
|
MD5 | a587a046bd9bb5e73c279ad859442b44 |
|
BLAKE2b-256 | d789f2acaba64d8f74110eae4655448b97874caeb185df89937eddfca5eae738 |
File details
Details for the file azure_developer_loadtesting-1.0.0b1-py3-none-any.whl
.
File metadata
- Download URL: azure_developer_loadtesting-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 73.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.28.1 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53ed5ec72d29f29f0cc462ad11bd85be7c467a3b6697ce4c96a419c74372e042 |
|
MD5 | 2f74f6045b75921cbd9a218a042b2633 |
|
BLAKE2b-256 | a7aaf74e56d89b42e8cfffdecfdc2dda6a051f7069a4dfdbf84a7255bffb685d |