azure-developer-loadtesting


Nameazure-developer-loadtesting JSON
Version 1.0.0b3 PyPI version JSON
download
home_pagehttps://github.com/Azure/azure-sdk-for-python/tree/main/sdk
SummaryMicrosoft Azure Developer LoadTesting Client Library for Python
upload_time2023-01-21 14:30:33
maintainer
docs_urlNone
authorMicrosoft Corporation
requires_python>=3.7
licenseMIT License
keywords azure azure sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Azure Load Testing client library for Python
Azure Load Testing provides client library in python to the user by which they can interact natively with Azure Load Testing service. Azure Load Testing is a fully managed load-testing service that enables you to generate high-scale load. The service simulates traffic for your applications, regardless of where they're hosted. Developers, testers, and quality assurance (QA) engineers can use it to optimize application performance, scalability, or capacity.

## Documentation
Various documentation is available to help you get started

<!-- - [Source code][source_code] -->
- [API reference documentation][api_reference_doc]
- [Product Documentation][product_documentation]

## Getting started

### Installing the package

```bash
python -m pip install azure-developer-loadtesting
```

#### Prequisites

- Python 3.7 or later is required to use this package.
- You need an [Azure subscription][azure_sub] 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][authenticate_with_token],
provide an instance of the desired credential type obtained from the
[azure-identity][azure_identity_credentials] library.

To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]

After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.

As an example, sign in via the Azure CLI `az login` command and [DefaultAzureCredential](https://learn.microsoft.com/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) will authenticate as that user.

Use the returned token credential to authenticate the client.

#### Create the client

Azure Developer LoadTesting SDK has 2 sub-clients of the main client (`LoadTestingClient`) to interact with the service, 'administration' and 'test_run'.

```python
from azure.developer.loadtesting import LoadTestingClient

# for managing authentication and authorization
# can be installed from pypi, follow: https://pypi.org/project/azure-identity/
# using DefaultAzureCredentials, read more at: https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python
from azure.identity import DefaultAzureCredential

client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())
```

`<endpoint>` refers to the data-plane endpoint/URL of the resource.

## 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 clients. There are two top-level clients which are the main entry points for the library

- `LoadTestingClient.administration` (`azure.developer.loadtesting.LoadTestingClient.administration`)
- `LoadTestingClient.test_run` (`azure.developer.loadtesting.LoadTestingClient.test_run`)

These two clients also have there asynchronous counterparts, which are 
- `LoadTestingClient.administration` (`azure.developer.loadtesting.aio.LoadTestingClient.administration`)
- `LoadTestingClient.test_run` (`azure.developer.loadtesting.aio.LoadTestingClient.test_run`)

### Load Test Administration Client

The `LoadTestingClient.administration` is used to administer and configure the load tests, app components and metrics.

#### 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.

#### 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:

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.

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.

### Test Run Client

The `LoadTestingClient.test_run`  is used to start and stop test runs corresponding to a load test. 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.

### Data-Plane Endpoint

Data-plane of Azure Load Testing resources is addressable using the following URL format:

`00000000-0000-0000-0000-000000000000.aaa.cnt-prod.loadtesting.azure.com`

The first GUID `00000000-0000-0000-0000-000000000000` is the unique identifier used for accessing the Azure Load Testing resource. This is followed by  `aaa` which is the Azure region of the resource.

The data-plane endpoint is obtained from Control Plane APIs.

**Example:** `1234abcd-12ab-12ab-12ab-123456abcdef.eus.cnt-prod.loadtesting.azure.com`

In the above example, `eus` represents the Azure region `East US`.

## Examples

### Creating a load test 
```python
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError
import os

TEST_ID = "some-test-id"  
DISPLAY_NAME = "my-load-test"  

# set SUBSCRIPTION_ID as an environment variable
SUBSCRIPTION_ID = os.environ["SUBSCRIPTION_ID"]  

client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:
    result = client.administration.create_or_update_test(
        TEST_ID,
        {
            "description": "",
            "displayName": DISPLAY_NAME,
            "loadTestConfig": {
                "engineInstances": 1,
                "splitAllCSVs": False,
            },
            "secrets": {},
            "environmentVariables": {},
            "passFailCriteria": {"passFailMetrics": {}}
        },
    )
    print(result)
except HttpResponseError as e:
     print('Service responded with error: {}'.format(e.response.json()))

```

### Uploading .jmx file to a Test
```python
from azure.developer.loadtesting import LoadTestingClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import HttpResponseError

TEST_ID = "some-test-id"  
FILE_NAME = "some-file-name.jmx"  

client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:

    result = client.administration.upload_test_file(TEST_ID, FILE_NAME, open("sample.jmx", "rb"))
    print(result)
except HttpResponseError as e:
    print("Failed with error: {}".format(e.response.json()))
```

### Running a Test
```python
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 = "my-load-test-run"  

client = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())

try:
    testRunPoller = client.test_run.begin_test_run(
    TEST_RUN_ID,
    {
        "testId": TEST_ID,
        "displayName": "My New Load Test Run",
    },
    poll_for_test_run_status=True
    )

    #waiting for test run status to be completed with timeout = 3600 seconds
    result = testRunPoller.result(3600)
    
    print(result)
except HttpResponseError as e:
    print("Failed with error: {}".format(e.response.json()))
```

## Next steps

More samples can be found [here](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/loadtestservice/azure-developer-loadtesting/samples).

## 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][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
additional questions or comments.

## Troubleshooting
More about it is coming soon...

<!-- LINKS -->
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
[azure_identity_pip]: https://pypi.org/project/azure-identity/
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[pip]: https://pypi.org/project/pip/
[azure_sub]: https://azure.microsoft.com/free/
[api_reference_doc]: https://docs.microsoft.com/rest/api/loadtesting/
[product_documentation]: https://azure.microsoft.com/services/load-testing/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk",
    "name": "azure-developer-loadtesting",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "azure,azure sdk",
    "author": "Microsoft Corporation",
    "author_email": "azpysdkhelp@microsoft.com",
    "download_url": "https://files.pythonhosted.org/packages/96/d1/00d38cc5228e9710fca50c4c0feeb0731d240d313a9a7faf32f5b634e522/azure-developer-loadtesting-1.0.0b3.zip",
    "platform": null,
    "description": "\n# Azure Load Testing client library for Python\nAzure Load Testing provides client library in python to the user by which they can interact natively with Azure Load Testing service. Azure Load Testing is a fully managed load-testing service that enables you to generate high-scale load. The service simulates traffic for your applications, regardless of where they're hosted. Developers, testers, and quality assurance (QA) engineers can use it to optimize application performance, scalability, or capacity.\n\n## Documentation\nVarious documentation is available to help you get started\n\n<!-- - [Source code][source_code] -->\n- [API reference documentation][api_reference_doc]\n- [Product Documentation][product_documentation]\n\n## Getting started\n\n### Installing the package\n\n```bash\npython -m pip install azure-developer-loadtesting\n```\n\n#### Prequisites\n\n- Python 3.7 or later is required to use this package.\n- You need an [Azure subscription][azure_sub] to use this package.\n- An existing Azure Developer LoadTesting instance.\n\n#### Create with an Azure Active Directory Credential\n\nTo use an [Azure Active Directory (AAD) token credential][authenticate_with_token],\nprovide an instance of the desired credential type obtained from the\n[azure-identity][azure_identity_credentials] library.\n\nTo authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]\n\nAfter setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.\n\nAs an example, sign in via the Azure CLI `az login` command and [DefaultAzureCredential](https://learn.microsoft.com/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) will authenticate as that user.\n\nUse the returned token credential to authenticate the client.\n\n#### Create the client\n\nAzure Developer LoadTesting SDK has 2 sub-clients of the main client (`LoadTestingClient`) to interact with the service, 'administration' and 'test_run'.\n\n```python\nfrom azure.developer.loadtesting import LoadTestingClient\n\n# for managing authentication and authorization\n# can be installed from pypi, follow: https://pypi.org/project/azure-identity/\n# using DefaultAzureCredentials, read more at: https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python\nfrom azure.identity import DefaultAzureCredential\n\nclient = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())\n```\n\n`<endpoint>` refers to the data-plane endpoint/URL of the resource.\n\n## Key concepts\n\nThe 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 clients. There are two top-level clients which are the main entry points for the library\n\n- `LoadTestingClient.administration` (`azure.developer.loadtesting.LoadTestingClient.administration`)\n- `LoadTestingClient.test_run` (`azure.developer.loadtesting.LoadTestingClient.test_run`)\n\nThese two clients also have there asynchronous counterparts, which are \n- `LoadTestingClient.administration` (`azure.developer.loadtesting.aio.LoadTestingClient.administration`)\n- `LoadTestingClient.test_run` (`azure.developer.loadtesting.aio.LoadTestingClient.test_run`)\n\n### Load Test Administration Client\n\nThe `LoadTestingClient.administration` is used to administer and configure the load tests, app components and metrics.\n\n#### Test\n\nA 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.\n\n#### App Component\n\nWhen 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.\n\n#### Metrics\n\nDuring a load test, Azure Load Testing collects metrics about the test execution. There are two types of metrics:\n\n1. 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.\n\n2. 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.\n\n### Test Run Client\n\nThe `LoadTestingClient.test_run`  is used to start and stop test runs corresponding to a load test. 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.\n\n### Data-Plane Endpoint\n\nData-plane of Azure Load Testing resources is addressable using the following URL format:\n\n`00000000-0000-0000-0000-000000000000.aaa.cnt-prod.loadtesting.azure.com`\n\nThe first GUID `00000000-0000-0000-0000-000000000000` is the unique identifier used for accessing the Azure Load Testing resource. This is followed by  `aaa` which is the Azure region of the resource.\n\nThe data-plane endpoint is obtained from Control Plane APIs.\n\n**Example:** `1234abcd-12ab-12ab-12ab-123456abcdef.eus.cnt-prod.loadtesting.azure.com`\n\nIn the above example, `eus` represents the Azure region `East US`.\n\n## Examples\n\n### Creating a load test \n```python\nfrom azure.developer.loadtesting import LoadTestingClient\nfrom azure.identity import DefaultAzureCredential\nfrom azure.core.exceptions import HttpResponseError\nimport os\n\nTEST_ID = \"some-test-id\"  \nDISPLAY_NAME = \"my-load-test\"  \n\n# set SUBSCRIPTION_ID as an environment variable\nSUBSCRIPTION_ID = os.environ[\"SUBSCRIPTION_ID\"]  \n\nclient = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())\n\ntry:\n    result = client.administration.create_or_update_test(\n        TEST_ID,\n        {\n            \"description\": \"\",\n            \"displayName\": DISPLAY_NAME,\n            \"loadTestConfig\": {\n                \"engineInstances\": 1,\n                \"splitAllCSVs\": False,\n            },\n            \"secrets\": {},\n            \"environmentVariables\": {},\n            \"passFailCriteria\": {\"passFailMetrics\": {}}\n        },\n    )\n    print(result)\nexcept HttpResponseError as e:\n     print('Service responded with error: {}'.format(e.response.json()))\n\n```\n\n### Uploading .jmx file to a Test\n```python\nfrom azure.developer.loadtesting import LoadTestingClient\nfrom azure.identity import DefaultAzureCredential\nfrom azure.core.exceptions import HttpResponseError\n\nTEST_ID = \"some-test-id\"  \nFILE_NAME = \"some-file-name.jmx\"  \n\nclient = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())\n\ntry:\n\n    result = client.administration.upload_test_file(TEST_ID, FILE_NAME, open(\"sample.jmx\", \"rb\"))\n    print(result)\nexcept HttpResponseError as e:\n    print(\"Failed with error: {}\".format(e.response.json()))\n```\n\n### Running a Test\n```python\nfrom azure.developer.loadtesting import LoadTestingClient\nfrom azure.identity import DefaultAzureCredential\nfrom azure.core.exceptions import HttpResponseError\n\nTEST_ID = \"some-test-id\"  \nTEST_RUN_ID = \"some-testrun-id\" \nDISPLAY_NAME = \"my-load-test-run\"  \n\nclient = LoadTestingClient(endpoint='<endpoint>', credential=DefaultAzureCredential())\n\ntry:\n    testRunPoller = client.test_run.begin_test_run(\n    TEST_RUN_ID,\n    {\n        \"testId\": TEST_ID,\n        \"displayName\": \"My New Load Test Run\",\n    },\n    poll_for_test_run_status=True\n    )\n\n    #waiting for test run status to be completed with timeout = 3600 seconds\n    result = testRunPoller.result(3600)\n    \n    print(result)\nexcept HttpResponseError as e:\n    print(\"Failed with error: {}\".format(e.response.json()))\n```\n\n## Next steps\n\nMore samples can be found [here](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/loadtestservice/azure-developer-loadtesting/samples).\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require\nyou to agree to a Contributor License Agreement (CLA) declaring that you have\nthe right to, and actually do, grant us the rights to use your contribution.\nFor details, visit https://cla.microsoft.com.\n\nWhen you submit a pull request, a CLA-bot will automatically determine whether\nyou need to provide a CLA and decorate the PR appropriately (e.g., label,\ncomment). Simply follow the instructions provided by the bot. You will only\nneed to do this once across all repos using our CLA.\n\nThis project has adopted the\n[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,\nsee the Code of Conduct FAQ or contact opencode@microsoft.com with any\nadditional questions or comments.\n\n## Troubleshooting\nMore about it is coming soon...\n\n<!-- LINKS -->\n[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/\n[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token\n[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials\n[azure_identity_pip]: https://pypi.org/project/azure-identity/\n[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential\n[pip]: https://pypi.org/project/pip/\n[azure_sub]: https://azure.microsoft.com/free/\n[api_reference_doc]: https://docs.microsoft.com/rest/api/loadtesting/\n[product_documentation]: https://azure.microsoft.com/services/load-testing/\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Microsoft Azure Developer LoadTesting Client Library for Python",
    "version": "1.0.0b3",
    "split_keywords": [
        "azure",
        "azure sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2f9d5c15ab1bdb4c1fb14c41527851f2bf2f5f8658f758dd837b8bf2aea1945",
                "md5": "98e4c4b3e600d4596c203d306a542b99",
                "sha256": "c7651e4e99f06b650ee9456fa70982f77e06687fb404e25aa6f59358e6e8a96a"
            },
            "downloads": -1,
            "filename": "azure_developer_loadtesting-1.0.0b3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "98e4c4b3e600d4596c203d306a542b99",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 77391,
            "upload_time": "2023-01-21T14:30:31",
            "upload_time_iso_8601": "2023-01-21T14:30:31.114439Z",
            "url": "https://files.pythonhosted.org/packages/a2/f9/d5c15ab1bdb4c1fb14c41527851f2bf2f5f8658f758dd837b8bf2aea1945/azure_developer_loadtesting-1.0.0b3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96d100d38cc5228e9710fca50c4c0feeb0731d240d313a9a7faf32f5b634e522",
                "md5": "b0f841a7c871b539337fd0443105dfd2",
                "sha256": "70985cce16267bedeabe230c1fb51698a823066cff71b76476c460ddd2921c48"
            },
            "downloads": -1,
            "filename": "azure-developer-loadtesting-1.0.0b3.zip",
            "has_sig": false,
            "md5_digest": "b0f841a7c871b539337fd0443105dfd2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 107862,
            "upload_time": "2023-01-21T14:30:33",
            "upload_time_iso_8601": "2023-01-21T14:30:33.519845Z",
            "url": "https://files.pythonhosted.org/packages/96/d1/00d38cc5228e9710fca50c4c0feeb0731d240d313a9a7faf32f5b634e522/azure-developer-loadtesting-1.0.0b3.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-21 14:30:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "azure-developer-loadtesting"
}
        
Elapsed time: 0.06942s