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

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

  1. Fill out Job name.
  2. Click Probes.

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. Select at least one probe from the Probe locations drop-down.
  2. You can leave the Frequency and Timeout fields with the default values.
  3. Click Requests.

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, enter https://test-api.k6.io/auth/cookie/login/.

  2. Under Request method, select POST.

  3. Select the 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"
    }

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’s also important to set up Assertions for each request you create. That way, similar to using the Test button, 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.

For this request, you can set up three assertions:

  • Check for a 200 HTTP response code.
  • Check that the expected username synthetics_multihttp_example is in the response body
  • Check that the expected email address synthetics_multihttp_example@test.com is in the response body

To set up these assertions:

  1. Click the Assertions tab.

  2. Click + Add assertions.

  3. For the first assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 200.
  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. For the third assertion, set:

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

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

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 and delete an object

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. Set Request target to https://test-api.k6.io/my/crocodiles/.

  3. Set Request method to POST.

  4. Select the 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"
    }

Similarly to the previous step, you can also set up assertions for this request:

  1. Click the Assertions tab.

  2. Click + Add assertions.

  3. For the first assertion, set:

    • Assertion type to Text.
    • Subject to HTTP status code.
    • Condition to Equals.
    • Value to 201.
  4. For the second assertion, set:

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

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

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

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

  1. Click + Add request below the first request you created in the last step.
  2. Set Request target to https://test-api.k6.io/my/crocodiles/${objectId}/.
    • ${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.
  3. Set Request method to DELETE.

Similarly to the previous step, you can also set up assertions for this request:

  1. Click the Assertions tab.

  2. Click + Add assertions.

  3. For this assertion, set:

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

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. Set Request target to https://test-api.k6.io/auth/cookie/logout/.
  3. Set Request method to POST.

Similarly to the previous step, you can set up assertions for this request:

  1. Click the Assertions tab.

  2. For this assertion, set:

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

Next, click Test at the end of the screen to make sure your check is working correctly, and then click Save.

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.