No results for

Powered byAlgolia

What are k6 extensions?

k6 extensions allow using functionality not supported natively in k6. They are standalone Go projects that can call internal Go APIs in k6 to provide new functionality.

Before k6 extensions, extending k6 with custom functionality that isn't available in the open-source tool has been possible in one of two ways:

  • By importing a JavaScript library.
  • By forking the k6 repository and doing the changes in Go.

Both methods have some drawbacks:

To address these issues and allow the community to adapt k6 to their needs, we released the xk6 framework and the concept of k6 extensions, providing the freedom to experiment with novel integrations with k6.

What is xk6?

xk6 is a command-line tool and framework inspired by xcaddy, designed for building custom k6 binaries that bundle one or more extensions written in Go.

Its main features are:

  • Ease of use: with a few commands even less technical users should be able to build their own k6 binaries, given that they have the Go toolchain installed and any dependencies required by a specific extension.
  • Simple API for Go programmers that handles the Go<->JS translation, with the ability to call any public k6 Go API. Extensions are first-class components along with other built-in modules.
  • Cross-platform like Go and runs great on macOS, Windows and Linux.

Extension types

The initial version of xk6 supported only JavaScript extensions, but since then we've added support for Output extensions, and are considering expanding this to other areas of k6 as well.

The currently supported extension types are:

JavaScript extension

These extensions enhance the k6 JavaScript API to add support for new network protocols, achieve better performance than equivalent JS libraries, or implement features that are unlikely to be made part of the k6 core.

Some examples include: xk6-sql, xk6-crypto and xk6-file.

import sql from 'k6/x/sql';
const db ='sqlite3', './test.db');
export default function () {
db.exec("INSERT INTO keyvalues (key, value) VALUES('lorem', 'ipsum');");

Output extension

While k6 has built-in support for many popular output backends, this list will undoubtedly not be exhaustive. Support for new systems and novel ways of handling the metric data generated by k6 can be easily added with Output extensions. These receive metric samples from k6 and can do any processing or further dispatching.

Some examples include: xk6-output-kafka and xk6-output-prometheus-remote.

K6_PROMETHEUS_REMOTE_URL=http://localhost:9090/api/v1/write ./k6 run script.js -o output-prometheus-remote

Supported k6 execution modes

k6 extensions work for local execution, i.e. running a script with a k6 binary built by xk6 on your own infrastructure. The k6 Kubernetes operator also supports custom k6 binaries with extensions.

In k6 Cloud, only supported k6 extensions are available for Enterprise customers.

For all k6 Cloud users, it is possible to run a binary built with xk6 and send metrics produced by extension code to the Cloud using the cloud output.