Menu
Grafana Cloud

Use k6 extensions

Note

Extensions is currently in public preview. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.

k6 has a set of core functionalities that you can use via its own set of JavaScript APIs. As a user, you might want to test a service or a protocol that’s not supported by the existing k6 APIs. That’s where extensions come in.

k6 extensions are a way to extend the core functionality of k6. For k6 open source users, they can write custom extensions and then build a new k6 binary to use them locally. For Grafana Cloud k6 users, you can use a set of built-in extensions when running your test scripts, without having to build a custom k6 binary.

Supported extensions in Grafana Cloud

Grafana Cloud k6 has built-in support for the following extensions:

ExtensionDescription
xk6-client-prometheus-remoteTest Prometheus Remote Write-compatible endpoints
xk6-fakerGenerate fake data in your tests
xk6-lokiTest Grafana Loki log ingestion endpoints
xk6-sshUse SSH connections in your tests

Use extensions in Grafana Cloud

There are different requirements for using extensions in Grafana Cloud depending on how you execute your test script.

Before you begin

  • Extensions are only supported when running your test scripts using the Script editor or the CLI.
  • When running your tests via the CLI, you must use k6 v1.0.0 or greater.
  • Using extensions via the Test builder isn’t supported.

Import an extension in your test script

The first step to using a cloud extension is to import it into your test script. For example, if you want to use the xk6-faker extension, you can add the following import statement:

JavaScript
import faker from 'k6/x/faker';

You can then use any functionality available from the extension. For example, you can create a random name using the faker.person class:

JavaScript
import faker from 'k6/x/faker';

export default function () {
  console.log(faker.person.firstName());
}

Run a test with an extension in Grafana Cloud

To run a test script that uses an extension, you have to use the Script editor or the CLI.

Run a test via the script editor

The script editor supports built-in extensions by default. You can import and use any extensions, and run your test without any additional steps.

Run a test via the CLI

To run test scripts with extensions via the CLI, you have to use a special feature flag determined by the environment variable K6_BINARY_PROVISIONING=true (The feature is still considered experimental).

  1. First, you can authenticate with k6 as usual:

    bash
    k6 cloud login --token <API_TOKEN>
  2. Then, you can run the test with the aforementioned feature flag:

    bash
    K6_BINARY_PROVISIONING=true k6 cloud run test.js