{"id":13342908,"url":"https://github.com/elastic/xk6-output-elasticsearch","last_synced_at":"2025-10-19T20:31:40.895Z","repository":{"id":64300404,"uuid":"485689598","full_name":"elastic/xk6-output-elasticsearch","owner":"elastic","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-09T05:13:07.000Z","size":892,"stargazers_count":19,"open_issues_count":6,"forks_count":9,"subscribers_count":203,"default_branch":"main","last_synced_at":"2024-09-27T01:53:42.105Z","etag":null,"topics":["xk6"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elastic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-26T08:01:25.000Z","updated_at":"2024-09-17T20:31:58.000Z","dependencies_parsed_at":"2023-11-23T14:30:28.798Z","dependency_job_id":"dc4805b2-d5e1-42ac-9fcc-7636360db23d","html_url":"https://github.com/elastic/xk6-output-elasticsearch","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fxk6-output-elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fxk6-output-elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fxk6-output-elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elastic%2Fxk6-output-elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elastic","download_url":"https://codeload.github.com/elastic/xk6-output-elasticsearch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219869272,"owners_count":16555575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["xk6"],"created_at":"2024-07-29T19:30:06.863Z","updated_at":"2025-10-19T20:31:35.584Z","avatar_url":"https://github.com/elastic.png","language":"Go","funding_links":[],"categories":["Extensions"],"sub_categories":["Community"],"readme":"# xk6-output-elasticsearch\n\n[k6 extension](https://k6.io/docs/extensions/) for publishing test-run metrics to Elasticsearch.\n\n## Prerequisites\n\n[Go](https://golang.org/) 1.20 or better (verify with `go version`).\n\n## Install\n\nInstall [xk6](https://k6.io/docs/extensions/guides/build-a-k6-binary-using-go/):\n\n```shell\n# Install xk6\ngo install go.k6.io/xk6/cmd/xk6@latest\n\n# Build the xk6 binary locally\ngit clone git@github.com:elastic/xk6-output-elasticsearch.git\n# Build k6 locally with the Elasticsearch output extension\nmake\n```\n\nYou will have a `k6` binary in the current directory.\n\n### Using Docker\n\nThis [Dockerfile](./Dockerfile) builds a docker image with the k6 binary.\n\n## Configuration\n\n### Running in Production\n\n\u003e [!NOTE]\n\u003e The examples below use Elastic Cloud, which allows to connect via `K6_ELASTICSEARCH_CLOUD_ID`. Alternatively you can also specify the connection URL with `K6_ELASTICSEARCH_URL`.\n\nYou can run the new k6 binary against a Cloud cluster with:\n```shell\nexport K6_ELASTICSEARCH_CLOUD_ID=your-cloud-id-here\nexport K6_ELASTICSEARCH_USER=elastic\nexport K6_ELASTICSEARCH_PASSWORD=your-password-here\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\nor alternatively via an [API key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html) (see also how to [create an API key in Kibana](https://www.elastic.co/guide/en/kibana/current/api-keys.html)):\n```shell\nexport K6_ELASTICSEARCH_CLOUD_ID=your-cloud-id-here\nexport K6_ELASTICSEARCH_API_KEY=your-base64-encoded-api-key-here\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\nor a [service account token](https://www.elastic.co/guide/en/elasticsearch/reference/current/service-accounts.html#service-accounts-tokens):\n```shell\nexport K6_ELASTICSEARCH_CLOUD_ID=your-cloud-id-here\nexport K6_ELASTICSEARCH_SERVICE_ACCOUNT_TOKEN=your-service-account-token-here\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\nor with [client certificate authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/pki-realm.html)\n```shell\nexport K6_ELASTICSEARCH_CLIENT_CERT_FILE=cert.pem\nexport K6_ELASTICSEARCH_CLIENT_KEY_FILE=key.pem\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\n### Running a local cluster\n\nAlternatively, you can send metrics to a local (unsecured) cluster:\n\n```shell\nexport K6_ELASTICSEARCH_URL=http://localhost:9200\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\nIf running locally with TLS (with a self-signed certificate), set `K6_ELASTICSEARCH_INSECURE_SKIP_VERIFY` to `true` (defaults to `false`):\n\n```shell\nexport K6_ELASTICSEARCH_URL=https://localhost:9200\nexport K6_ELASTICSEARCH_INSECURE_SKIP_VERIFY=true\n\n./k6 run ./examples/script.js -o output-elasticsearch\n```\n\nThe metrics are stored in the index `k6-metrics` by default which will be automatically created by this extension. See the [mapping](pkg/esoutput/mapping.json) for details. The index name can be customized with the environment variable `K6_ELASTICSEARCH_INDEX_NAME`.\n\n## Docker Compose\n\nThis repo includes a [docker-compose.yml](./docker-compose.yml) file based on the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-file), 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.\n\nNote that some variables (Stack version, elastic and Kibana users' passwords) are defined in the [`.env`](.env) file, where you can change them.\n\nClone the repo to get started and follow these steps: \n\n1. Put your `k6` scripts in the `examples` directory or use the [`script.js`](examples/script.js) example.\n\n3. Start the `docker-compose` environment.\n\n\t```shell\n\tdocker-compose up -d\n\t```\n\n4. Use the k6 Docker image to run the k6 script and send metrics to the Elasticsearch cluster started in the previous step.\n\n    ```shell\n    docker-compose run --rm -T k6 run -\u003cexamples/script.js --tag testid=\u003cSOME-ID\u003e\n    ```\n\n\t\u003e Note that the [docker-compose command to run k6 tests](https://k6.io/docs/getting-started/running-k6/) might differ depending your OS.\n\n5. Visit http://localhost:5601/ to view results in Kibana (default credentials are `elastic` / `changeme`).\n\n    - Create a [Data View](https://www.elastic.co/guide/en/kibana/current/data-views.html) for the index `k6-metrics` or the index name in `K6_ELASTICSEARCH_INDEX_NAME` if it is set.\n        ![Kibana Data View](./images/kibana-data-view.png)\n    - Go to [Discover](https://www.elastic.co/guide/en/kibana/current/discover.html) to start exploring the metrics.\n        ![Kibana Discover](./images/kibana-discover.png)\n\nWhen done, to clean up run `docker-compose down -v`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Fxk6-output-elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felastic%2Fxk6-output-elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felastic%2Fxk6-output-elasticsearch/lists"}