k6 extension for publishing test-run metrics to Elasticsearch.
Go 1.17 or better (verify with go version
).
Install xk6:
# Install xk6
go install go.k6.io/xk6/cmd/xk6@latest
# Build the xk6 binary locally
git clone [email protected]:elastic/xk6-output-elasticsearch.git
# Build k6 locally with the Elasticsearch output extension
make
You will have a k6
binary in the current directory.
This Dockerfile builds a docker image with the k6 binary.
You can run the new k6 binary against a Cloud cluster with:
export K6_ELASTICSEARCH_CLOUD_ID=your-cloud-id-here
export K6_ELASTICSEARCH_USER=elastic
export K6_ELASTICSEARCH_PASSWORD=your-password-here
./k6 run script.js -o output-elasticsearch
Alternatively, you can send metrics to a local (unsecured) cluster:
export K6_ELASTICSEARCH_URL=http://localhost:9200
./k6 run ./samples/script.js -o output-elasticsearch
If running locally with TLS (with a self-signed certificate), set K6_ELASTICSEARCH_INSECURE_SKIP_VERIFY
to true
(defaults to false
):
export K6_ELASTICSEARCH_URL=https://localhost:9200
export K6_ELASTICSEARCH_INSECURE_SKIP_VERIFY=true
./k6 run ./samples/script.js -o output-elasticsearch
The metrics are stored in the index k6-metrics
which will be automatically created by this extension. See the mapping for details.
This repo includes a docker-compose.yml file based on the documentation, that starts Elasticsearch and Kibana. It also adds a custom build of k6 having the xk6-output-elasticsearch
extension. This is just a quick way to showcase the usage, not meant for production usage.
Note that some variables (Stack version, elastic and Kibana users' passwords) are defined in the .env
file, where you can change them.
Clone the repo to get started and follow these steps:
-
Put your
k6
scripts in thesamples
directory or use thescript.js
example. -
Start the
docker-compose
environment.docker-compose up -d
-
Use the k6 Docker image to run the k6 script and send metrics to the Elasticsearch cluster started in the previous step.
docker-compose run --rm -T k6 run -<samples/script.js --tag testid=<SOME-ID>
Note that the docker-compose command to run k6 tests might differ depending your OS.
-
Visit http://localhost:5601/ to view results in Kibana.
When done, to clean up run docker-compose down -v
.