Define fail criteria for load tests by using Azure Load Testing

In this article, you learn how to define fail criteria or auto stop criteria for your load tests with Azure Load Testing. Fail criteria let you define performance and quality expectations for your application under load. Azure Load Testing supports various client and server metrics for defining fail criteria, such as error rate or CPU percentage for an Azure resource. Auto stop criteria enable you to automatically stop your load test when the error rate surpasses a given threshold.

Prerequisites

  • An Azure account with an active subscription. If you don't have an Azure subscription, create a free account before you begin.
  • An Azure load testing resource. If you need to create an Azure Load Testing resource, see the quickstart Create and run a load test.

Load test fail criteria

Load test fail criteria are conditions for metrics, that your test should meet. You define test criteria at the load test level in Azure Load Testing. A load test can have one or more test criteria. When at least one of the test criteria evaluates to true, the load test gets the failed status.

You can define a maximum of 50 test criteria for a load test. If there are multiple criteria for the same metric, the criterion with the lowest threshold value is used.

Fail criteria structure for client metrics

The format of fail criteria in Azure Load Testing follows that of a conditional statement for a supported metric. For example, ensure that the average number of requests per second is greater than 500.

For client-side metrics, you can define test criteria at two levels. A load test can combine criteria at the different levels.

  • At the load test level. For example, to ensure that the total error percentage doesn't exceed a threshold. The structure for the criteria is: Aggregate_function (client_metric) condition threshold.
  • At the JMeter request level (JMeter sampler). For example, you could specify a response time threshold of the getProducts request, but disregard the response time of the sign in request. The structure for the criteria is: Request: Aggregate_function (client_metric) condition threshold.

The following table describes the different components:

Parameter Description
Client metric Required. The client metric on which the condition should be applied.
Aggregate function Required. The aggregate function to be applied on the client metric.
Condition Required. The comparison operator, such as greater than, or less than.
Threshold Required. The numeric value to compare with the client metric.
Request Optional. Name of the sampler in the JMeter script to which the criterion applies. If you don't specify a request name, the criterion applies to the aggregate of all the requests in the script.
Don't include any personal data in the sampler name in your JMeter script. The sampler names appear in the Azure Load Testing results dashboard.

Supported client metrics for fail criteria

Azure Load Testing supports the following client metrics:

Metric Aggregate function Threshold Condition Description
response_time_ms avg (average)
min (minimum)
max (maximum)
pxx (percentile), xx can be 50, 75, 90, 95, 96, 97, 98, 99, 999 and 9999
Integer value, representing number of milliseconds (ms). > (greater than)
< (less than)
Response time or elapsed time, in milliseconds. Learn more about elapsed time in the Apache JMeter documentation.
latency avg (average)
min (minimum)
max (maximum)
pxx (percentile), xx can be 50, 90, 95, 99
Integer value, representing number of milliseconds (ms). > (greater than)
< (less than)
Latency, in milliseconds. Learn more about latency in the Apache JMeter documentation.
error percentage Numerical value in the range 0-100, representing a percentage. > (greater than) Percentage of failed requests.
requests_per_sec avg (average) Numerical value with up to two decimal places. > (greater than)
< (less than)
Number of requests per second.
requests count Integer value. > (greater than)
< (less than)
Total number of requests.

Define load test fail criteria for client metrics

In this section, you configure test criteria for client metric for a load test in the Azure portal.

  1. In the Azure portal, go to your Azure Load Testing resource.

  2. On the left pane, select Tests to view the list of load tests.

  3. Select your load test from the list, and then select Edit.

    Screenshot of the list of tests for an Azure load testing resource in the Azure portal, highlighting the 'Edit' button.

  4. On the Test criteria pane, fill the Metric, Aggregate function, Condition, and Threshold values for your test.

    Screenshot of the 'Test criteria' pane for a load test in the Azure portal and highlights the fields for adding a test criterion.

    Optionally, enter the Request name information to add a test criterion for a specific JMeter request. The value should match the name of the JMeter sampler in the JMX file.

    Screenshot of the JMeter user interface, highlighting the request name.

  5. Select Apply to save the changes.

    When you now run the load test, Azure Load Testing uses the test criteria to determine the status of the load test run.

  6. Run the test and view the status in the load test dashboard.

    The dashboard shows each of the test criteria and their status. The overall test status is failed if at least one criterion was met.

    Screenshot that shows the test criteria on the load test dashboard.

Access app component for test criteria on server metrics

When you set failure criteria on a metric in your app component, your load testing resource uses a managed identity for accessing that component. After you configure the managed identity, you need to grant the managed identity of your load testing resource permissions to read these values from the app component.

To grant your Azure load testing resource permissions to read the metrics from your app component:

  1. In the Azure portal, go to your app component.

  2. On the left pane, select Access Control (IAM), then select + Add, and then select Add role assignment.

    Screenshot of the Access Control(IAM) in the application component on which failure criteria is to be set.

  3. On the Role tab, under Job functions roles, search for Monitoring Reader or Monitoring Contributor.

  4. On the Members tab, under Assign access to, select Managed Identity.

  5. Click on Select members, search and select the managed identity for the load testing resource, and then select Next. If you're using a system-assigned managed identity, the managed identity name matches that of your Azure load testing resource.

  6. Select Review + assign to assign the identity the permission.

    Screenshot of assigning the permissions to read metrics to the load testing resource.

When your test runs, the managed identity that's associated with your load testing resource can now read the metrics for your load test from your app component.

Define load test fail criteria for server metrics

Important

Azure Load Testing doesn't support configuring failure criteria on server-side metrics from Azure Pipelines/GitHub Actions.

In this section, you configure test failure criteria on server-side metrics for a load test in the Azure portal.

  1. In the Azure portal, go to your Azure Load Testing resource.

  2. Select Create Test.

  3. Under the Monitoring Tab, configure the app components you want to monitor during the test.

  4. Configure the Metrics reference identity. The identity can be the system-assigned identity of the load testing resource, or one of the user-assigned identities. Make sure you use the same identity you've granted access previously.

    Screenshot of configuring metrics reference identity.

  5. On the Test criteria pane, fill the Resource ID, Namespace, Metric, Aggregation, Condition, Threshold values for your test. You can set failure criteria only for those resources/app components that you are monitoring during the test.

    Screenshot of configuring failure criteria on server metrics.

  6. Select Apply to save the changes. When you now run the load test, Azure Load Testing uses the test criteria to determine the status of the load test run.

  7. Run the test and view the status in the load test dashboard. The dashboard shows each of the test criteria and their status. The overall test status is failed if at least one criterion was met.

    Screenshot of the dashboard displaying test results.

Auto stop configuration

Azure Load Testing automatically stops a load test if the error percentage exceeds a given threshold for a certain time window. Automatically stopping safeguards you against failing tests further incurring costs, for example, because of an incorrectly configured endpoint URL.

In the load test configuration, you can enable or disable the auto stop functionality and configure the error percentage threshold and time window. By default, Azure Load Testing automatically stops a load test that has an error percentage that is at least 90% during any 60-second time window.

You can use the Azure Load Testing auto stop functionality in combination with an AutoStop listener in your JMeter script. The load test automatically stops when one of the criteria in either the auto stop configuration or the JMeter AutoStop listener is met.

Caution

If you disable auto stop for your load test, you may incur costs even when your load test is configured incorrectly.

To configure auto stop for your load test in the Azure portal:

  1. In the Azure portal, go to your Azure Load Testing resource.

  2. On the left pane, select Tests to view the list of load tests.

  3. Select your load test from the list, and then select Edit. Alternately, select Create > Upload a JMeter script to create a new test.

  4. Go to the Test criteria tab to configure the auto stop functionality.

    • Enable or disable automatically stopping of the load test by using the Auto-stop test control.

    • If you enable auto stop, you can fill the Error percentage and Time window fields. Specify the time window in seconds.

      Screenshot of the 'Test criteria' pane for a load test in the Azure portal, highlighting the auto stop functionality.

  5. Select Apply, or Review + create if you're creating a new load test, to save the changes.

Next steps