Use k6 extensions
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 subset of these 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 two categories of extensions: Official and Community.
Official extensions
These are extensions owned and maintained by Grafana Labs, with support for a wide range of versions.
Grafana guarantees regular maintenance, such as security patches and new versions that add or improve functionality.
Extension | Description | Versions |
---|---|---|
k6 | A modern load testing tool, using Go and JavaScript | v1.3.0, v1.2.3, v1.2.2, v1.2.1, v1.2.0, v1.1.0, v1.0.0 |
xk6-faker | Generate fake data in your tests | v0.4.4, v0.4.3, v0.4.2, v0.4.1, v0.4.0 |
xk6-loki | Test Grafana Loki log ingestion endpoints | v1.0.1, v1.0.0 |
xk6-client-prometheus-remote | Test Prometheus Remote Write-compatible endpoints | v0.3.2 |
xk6-sql | Load-test SQL Servers | v1.0.5, v1.0.4, v1.0.3, v1.0.2, v1.0.1, v1.0.0 |
xk6-sql-driver-mysql | xk6-sql driver extension for MySQL database support | v0.2.1, v0.2.0, v0.1.0 |
xk6-sql-driver-postgres | xk6-sql driver extension for Postgres database support | v0.1.1, v0.1.0 |
xk6-ssh | Use SSH connections in your tests | v0.1.3, v0.1.2, v0.1.1, v0.1.0 |
Community extensions
These are extensions developed by the community, with support for specific versions.
Grafana doesn’t guarantee support for community extensions beyond allowing the use of vetted versions.
Extension | Description | Versions |
---|---|---|
xk6-kafka | Load test Apache Kafka. Includes support for Avro messages. | v1.0.0 |
xk6-sql-driver-azuresql | xk6-sql driver extension for Microsoft Azure SQL database support | v0.1.1, v0.1.0 |
xk6-sql-driver-clickhouse | xk6-sql driver extension for ClickHouse database support | v0.1.1, v0.1.0 |
xk6-sql-driver-sqlserver | xk6-sql driver extension for Microsoft SQL Server database support | v0.1.1, v0.1.0 |
xk6-sse | Server Sent Event | v0.1.11, v0.1.10 |
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, use k6 v1.2 or later, which includes native support for extension loading.
- 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:
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:
import faker from 'k6/x/faker';
export default function () {
console.log(faker.person.firstName());
}
If you are interested in specifying the version of k6 or the extensions, refer to Override versions.
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
Make sure you have k6 v1.2 or later installed by running the following command:
k6 version
Then, follow these steps to run your test script with extensions:
Authenticate with Grafana Cloud:
k6 cloud login --token <API_TOKEN>
Run your test.
In the cloud:
k6 cloud run test.js
Locally (with cloud-provisioned binary):
k6 cloud run --local-execution test.js
If your script uses supported extensions, k6 automatically detects them and provisions a compatible binary, either in Grafana Cloud or locally.
Example output
INFO[0287] A new k6 binary has been provisioned with version(s): k6:v1.1.0 k6/x/faker:v0.4.4
Disable extensions
You can disable this feature by setting the environment variable K6_AUTO_EXTENSION_RESOLUTION
to false
. If provided, the previous example
fails because k6 can’t load the extension dynamically.
For example:
K6_AUTO_EXTENSION_RESOLUTION=false k6 cloud run test.js
And an example output for a test failure:
ERRO[0000] GoError: unknown module: k6/x/faker hint="script exception"