Menu
Grafana Cloud

Create a MultiHTTP check

This tutorial shows how to create your first MultiHTTP check. MultiHTTP checks provide a form-based approach for defining multi-step tests. They’re great for testing workflows, and give you the flexibility to pass data from one request to the next. For example, if you have an e-commerce application, you can create a MultiHTTP check to test a user workflow that would log in to your application, add an item to the shopping cart, check out, and then log out of your application.

In this tutorial you will:

  • Create a MultiHTTP check using the test-api.k6.io service. The check will have three requests:
    • Log in using a pre-defined synthetics_multihttp_example.
    • Add a crocodile object to the user’s list, then delete it.
    • Log out.
  • Set up assertions for each request to ensure they’re working as expected.

Before you begin

Note

This tutorial uses the test-api.k6.io service, which is a public shared environment. You can use it and follow along this tutorial, but it’s recommended to avoid high-load tests. The service is also open source if you’d like to deploy a private instance.

Create a MultiHTTP check

To create a MultiHTTP check:

  1. Open your Grafana instance.
  2. On the left-hand menu, select Testing & Synthetics.
  3. Click Synthetics.
  4. Click Add new check.
  5. Select Create Multi Step check.

After that, you will see the New Multi Step check page where you can configure your new check. The first step is to define the check:

  1. Fill out Job name.

Log in to an application

The Requests section is where you can configure the specific endpoints you want the MultiHTTP check to test.

For this tutorial, the first step is to make a log in request to the test-api.k6.io application:

  1. Under Request target, select POST in the methods list.

  2. Under Request target, enter https://test-api.k6.io/auth/cookie/login/ in the input field.

  3. Click Request options

  4. Select the Request Body tab and fill out the following fields:

    1. Under Content type, enter application/json.
    2. Under Request body payload, copy and paste the following payload:
    json
    {
      "username": "synthetics_multihttp_example",
      "password": "synthetics_multihttp_example"
    }

Note that this login call will create a session cookie, which is needed to authenticate subsequent calls. k6 handles the session cookie just as a browser would. It transparently manages the receipt, storage, and transmission of cookies.

Create an object and extract a variable

The next step is to configure a POST call to create a crocodile in the test application, and then grab the newly created crocodile ID to use in the next request and delete it.

To create a crocodile in the test application:

  1. Click + Add request below the first request you created in the last step.

  2. Under Request target set the method to POST.

  3. Under Request target enter https://test-api.k6.io/my/crocodiles/ in the input field.

  4. Click Request options.

  5. Select the Request Body tab and:

    • Set Content type to applicaton/json.
    • Set Request body payload to:
    json
    {
      "name": "synthetics test object",
      "sex": "F",
      "date_of_birth": "2024-05-01"
    }

Before adding the next request, you need to create a variable to store the crocodile object ID:

  1. Click Set variables.
  2. Click + Add variable.
  3. Set Variable name to objectId.
  4. Set Variable type to JSON path.
  5. Set Variable expression to id.

Delete an object using previously set variables

To delete the crocodile you just created in the test application:

  1. Click + Add request below the second request you created in the last step.
  2. Under Request target set the method to DELETE.
  3. Under Request target enter https://test-api.k6.io/my/crocodiles/${objectId}/ in the input field.
    • ${objectId} is the variable that you created in the previous request. When the check runs, that will get replaced with the value for that variable.

Log out of an application

The final step is to log out of the application. To do that:

  1. Click + Add request below the request you created in the last step.
  2. Under Request target set the method to POST.
  3. Under Request target in the input field enter https://test-api.k6.io/auth/cookie/logout/.

Define uptime with assertions

It’s also important to set up Request Assertions for each request you create. That way you can have Synthetic Monitoring automatically validate things such as the response code from your request, or that the response body includes a specific property and value.

To set up these assertions you have to go to the Define uptime section:

  1. Click the Define uptime option in the sidebar.

Here you can see the three requests you created in the previous section, and you will set up assertions for each one.

For the login request you will add three assertions. Under the First request titled POST https://test-api.k6.io/auth/cookie/login/:

  1. Click + Add assertion below the first request.

  2. For the first assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 200.
  3. Click + Add assertion.

  4. For the second assertion, set:

    • Assertion type to JSON path value.
    • Expression to first_name.
    • Condition to Equals.
    • Value to synthetics_multihttp_example.
  5. Click + Add assertion.

  6. For the third assertion, set:

    • Assertion type to JSON path value.
    • Expression to email.
    • Condition to Equals.
    • Value to synthetics_multihttp_example@test.com.

For the creation request you will add two assertions. Under the Second request titled POST https://test-api.k6.io/my/crocodiles/:

  1. Click + Add assertion.

  2. For the first assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 201.
  3. Click + Add assertion.

  4. For the second assertion, set:

    • Assertion type to JSON path value.
    • Expression to name.
    • Condition to Equals.
    • Value to synthetics test object.

For the delete request you will add one assertion. Under the third request title DELETE https://test-api.k6.io/my/crocodiles/${objectId}/:

  1. Click + Add assertion.

  2. For this assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 204.

For the logout request you will add one assertion. Under the third request title POST https://test-api.k6.io/auth/cookie/logout/:

  1. Click the + Add Assertion tab.

  2. For this assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 200.

Now, for every check run, Synthetic Monitoring will validate those assertions.

Set probe locations and frequency

Next, you have to configure the Probes, which represent the locations where you want to run your test from, and how frequent you want your check to run:

  1. Click Execution in the sidebar.
  2. Select at least one probe from the Probe locations drop-down.
  3. You can leave the Frequency fields with the default value.

Test and save your check

You can click Test at the end of the screen to have Synthetic Monitoring run your check, and make sure you get a 200 OK response that shows your check is working correctly. It will test your requests and assertions and show you the results.

When you are happy your check is working correctly click Submit.

Your check will now run from the probe locations that you selected, and with the default frequency value. Your check will make sure that the endpoints you configured are working correctly, and if you have any issues, you will be able to see them in your check dashboard.

Next steps

Now that you have a MultiHTTP check configured, you can:

  • Refer to Create a k6 scripted check to see how you can create a similar check that uses the test-api.k6.io application, but using JavaScript to make your check even more flexible.
  • Refer to Check types to get more information about the metrics and options available for the MultiHTTP check type.
  • Refer to Analyze results to learn more about how you can visualize and analyze the data collected by your check
  • Refer to Synthetic Monitoring alerting to learn how to create and configure alerts in case your check fails.