k6

command module
v0.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

README

Grafana k6

Grafana Labs

Like unit testing, for performance

Modern load testing for developers and testers in the DevOps era.

Github release Build status Go Report Card Codecov branch

Download · Documentation · Community Forum · Public Roadmap


---

k6 is a modern load-testing tool, built on our years of experience in the performance and testing industries. It's built to be powerful, extensible, and full-featured. The key design goal is to provide the best developer experience.

Its core features are:

  • Configurable load generation. Even lower-end machines can simulate lots of traffic.
  • Tests as code. Reuse scripts, modularize logic, version control, and integrate tests with your CI.
  • A full-featured API. The scripting API is packed with features that help you simulate real application traffic.
  • An embedded JavaScript engine. The performance of Go, the scripting familiarity of JavaScript.
  • Multiple Protocol support. HTTP, WebSockets, gRPC, Browser, and more.
  • Large extension ecosystem. You can extend k6 to support your needs. And many people have already shared their extensions with the community!
  • Flexible metrics storage and visualization. Summary statistics or granular metrics, exported to the service of your choice.
  • Native integration with Grafana cloud. SaaS solution for test execution, metrics correlation, data analysis, and more.

This is what load testing looks like in the 21st century.

Example script

import http from "k6/http";
import { check, sleep } from "k6";

// Test configuration
export const options = {
  thresholds: {
    // Assert that 99% of requests finish within 3000ms.
    http_req_duration: ["p(99) < 3000"],
  },
  // Ramp the number of virtual users up and down
  stages: [
    { duration: "30s", target: 15 },
    { duration: "1m", target: 15 },
    { duration: "20s", target: 0 },
  ],
};

// Simulated user behavior
export default function () {
  let res = http.get("https://quickpizza.grafana.com");
  // Validate response status
  check(res, { "status was 200": (r) => r.status == 200 });
  sleep(1);
}

You can run scripts like this on the CLI, or in your CI, or across a Kubernetes cluster.

Documentation

The docs cover all aspects of using k6. Some highlights include:

  • Get Started. Install, run a test, inspect results.
  • HTTP requests. Have your virtual users use HTTP methods. Or, check the other Protocols.
  • Thresholds. Set goals for your test, and codify your SLOs.
  • Options. Configure your load, duration, TLS certificates, and much, much more.
  • Scenarios. Choose how to model your workload: open models, closed models, constant RPS, fixed iterations, and more.
  • Results output. Study, filter, and export your test results.
  • JavaScript API. Reference and examples of all k6 modules.
  • Extensions. Extend k6 for new protocols and use cases.

These links barely scratch the surface! If you're looking for conceptual information, you can read about Test types, Test strategies, or one of the many informative Blog posts.

Roadmap

Our team is dedicated to continuously improving and providing the best user experience possible. The public roadmap covers user-oriented features, UX improvements and JavaScript support that our team will focus on. Remember that timeframes and priorities may shift, but we believe it's important to share our vision.

We hope it provides a clear overview of our plans for future development. We welcome feedback, corrections, and suggestions via GitHub to make it more comprehensive, accessible, and valuable for the community.

It's worth mentioning that we consider upvotes (thumbs-up) to be one of the essential metrics for determining community needs. If you want to show us the importance of a feature, please give it a thumbs-up.

Contribute

If you want to contribute or help with the development of k6, start by reading CONTRIBUTING.md. Before you start coding, it might be a good idea to first discuss your plans and implementation details with the k6 maintainers—especially when it comes to big changes and features. You can do this in the GitHub issue for the problem you're solving (create one if it doesn't exist).

Note: To disclose security issues, refer to SECURITY.md.

Support

To get help, report bugs, suggest features, and discuss k6 with others, refer to SUPPORT.md.

License

k6 is distributed under the AGPL-3.0 license.

Documentation

Overview

Package main is the entry point for the k6 CLI application. It assembles all the crucial components for the running.

Directories

Path Synopsis
api
v1
Package v1 implements the v1 of the k6's REST API
Package v1 implements the v1 of the k6's REST API
v1/client
Package client provides a simple go-client for the k6's REST API.
Package client provides a simple go-client for the k6's REST API.
Package cloudapi contains several things related to the k6 cloud - various data and config structures, a REST API client, log streaming logic, etc.
Package cloudapi contains several things related to the k6 cloud - various data and config structures, a REST API client, log streaming logic, etc.
cmd
Package cmd is here to provide a way for xk6 to build a binary with added extensions
Package cmd is here to provide a way for xk6 to build a binary with added extensions
state
Package state contains the types and functionality used for keeping track of cmd-related values that are used globally throughout k6.
Package state contains the types and functionality used for keeping track of cmd-related values that are used globally throughout k6.
tests
Package tests contains types needed for running integration tests that run k6 commands.
Package tests contains types needed for running integration tests that run k6 commands.
Package errext contains extensions for normal Go errors that are used in k6.
Package errext contains extensions for normal Go errors that are used in k6.
exitcodes
Package exitcodes contains the constants representing possible k6 exit error codes.
Package exitcodes contains the constants representing possible k6 exit error codes.
Package ext contains the extension registry and all generic functionality for k6 extensions.
Package ext contains the extension registry and all generic functionality for k6 extensions.
internal
api
Package api contains the REST API implementation for k6.
Package api contains the REST API implementation for k6.
build
Package build handles information and processes about the k6 binary's build.
Package build handles information and processes about the k6 binary's build.
cloudapi/insights
Package insights contains the domain data structures and client logic for the k6 cloud Insights API.
Package insights contains the domain data structures and client logic for the k6 cloud Insights API.
cloudapi/insights/proto
Package proto contains the Protobuf definitions used by the k6 Insights.
Package proto contains the Protobuf definitions used by the k6 Insights.
cmd
Package cmd implements the command-line interface of k6.
Package cmd implements the command-line interface of k6.
cmd/templates
Package templates provides the templates used by the `k6 new` command
Package templates provides the templates used by the `k6 new` command
cmd/tests
Package tests contains integration tests that run k6 commands, and interact with standard I/O streams.
Package tests contains integration tests that run k6 commands, and interact with standard I/O streams.
cmd/tests/events
Package events is used for testing the event functionality.
Package events is used for testing the event functionality.
ds/histogram
Package histogram provides histogram implementations that are used to track the distribution of metrics.
Package histogram provides histogram implementations that are used to track the distribution of metrics.
event
Package event contains the event system used to notify external components of various internal events during test execution.
Package event contains the event system used to notify external components of various internal events during test execution.
execution
Package execution contains most of the components that schedule, execute and control individual k6 tests.
Package execution contains most of the components that schedule, execute and control individual k6 tests.
execution/local
Package local implements the execution.Controller interface for local (single-machine) k6 execution.
Package local implements the execution.Controller interface for local (single-machine) k6 execution.
js
Package js is the JavaScript implementation of the lib.Runner and relative concepts for executing concurrent-safe JavaScript code.
Package js is the JavaScript implementation of the lib.Runner and relative concepts for executing concurrent-safe JavaScript code.
js/compiler
Package compiler implements additional functionality for k6 to compile js code.
Package compiler implements additional functionality for k6 to compile js code.
js/eventloop
Package eventloop implements an event loop to be used thought js and it's subpackages
Package eventloop implements an event loop to be used thought js and it's subpackages
js/modules/k6/browser/browser
Package browser is the browser module's entry point, and initializer of various global types, and a translation layer between sobek and the internal business logic.
Package browser is the browser module's entry point, and initializer of various global types, and a translation layer between sobek and the internal business logic.
js/modules/k6/browser/chromium
Package chromium is responsible for launching a Chrome browser process and managing its lifetime.
Package chromium is responsible for launching a Chrome browser process and managing its lifetime.
js/modules/k6/browser/common
Package common provides the main logic of the browser module.
Package common provides the main logic of the browser module.
js/modules/k6/browser/common/js
Package js provides JavaScript code that the browser module evaluates on the browser.
Package js provides JavaScript code that the browser module evaluates on the browser.
js/modules/k6/browser/env
Package env provides types to interact with environment setup.
Package env provides types to interact with environment setup.
js/modules/k6/browser/k6error
Package k6error contains ErrFatal.
Package k6error contains ErrFatal.
js/modules/k6/browser/k6ext
Package k6ext acts as an encapsulation layer between the k6 core and xk6-browser.
Package k6ext acts as an encapsulation layer between the k6 core and xk6-browser.
js/modules/k6/browser/k6ext/k6test
Package k6test provides mock implementations of k6 elements for testing purposes.
Package k6test provides mock implementations of k6 elements for testing purposes.
js/modules/k6/browser/keyboardlayout
Package keyboardlayout provides keyboard key interpretation and layout validation.
Package keyboardlayout provides keyboard key interpretation and layout validation.
js/modules/k6/browser/log
Package log provides logging for the browser module.
Package log provides logging for the browser module.
js/modules/k6/browser/storage
Package storage provides data storage for the extension and user specific data.
Package storage provides data storage for the extension and user specific data.
js/modules/k6/browser/tests
Package tests provides integration tests.
Package tests provides integration tests.
js/modules/k6/browser/tests/ws
Package ws provides a test WebSocket server.
Package ws provides a test WebSocket server.
js/modules/k6/browser/trace
Package trace provides tracing instrumentation tailored for k6 browser needs.
Package trace provides tracing instrumentation tailored for k6 browser needs.
js/modules/k6/crypto
Package crypto provides common hashing function for the k6
Package crypto provides common hashing function for the k6
js/modules/k6/crypto/x509
Package x509 provides X.509 certificate parsing for the k6
Package x509 provides X.509 certificate parsing for the k6
js/modules/k6/data
Package data implements `k6/data` js module for k6.
Package data implements `k6/data` js module for k6.
js/modules/k6/encoding
Package encoding provides encoding/decoding functionality for the k6
Package encoding provides encoding/decoding functionality for the k6
js/modules/k6/execution
Package execution implements k6/execution which lets script find out more about it is execution.
Package execution implements k6/execution which lets script find out more about it is execution.
js/modules/k6/experimental
Package experimental includes experimental module features
Package experimental includes experimental module features
js/modules/k6/experimental/csv
Package csv provides a CSV parser for k6.
Package csv provides a CSV parser for k6.
js/modules/k6/experimental/fs
Package fs provides a k6 module that allows users to interact with files from the local filesystem as per the [File API design document].
Package fs provides a k6 module that allows users to interact with files from the local filesystem as per the [File API design document].
js/modules/k6/experimental/streams
Package streams provides support for the Web Streams API.
Package streams provides support for the Web Streams API.
js/modules/k6/experimental/websockets
Package websockets implements to some extend WebSockets API https://websockets.spec.whatwg.org
Package websockets implements to some extend WebSockets API https://websockets.spec.whatwg.org
js/modules/k6/experimental/websockets/events
Package events represent the events that can be sent to the client https://dom.spec.whatwg.org/#event
Package events represent the events that can be sent to the client https://dom.spec.whatwg.org/#event
js/modules/k6/grpc
Package grpc is the root module of the k6-grpc extension.
Package grpc is the root module of the k6-grpc extension.
js/modules/k6/html/gen
Package main - this package generates some of the code for k6/html
Package main - this package generates some of the code for k6/html
js/modules/k6/metrics
Package metrics implements k6/metrics and let script work with custom metrics.
Package metrics implements k6/metrics and let script work with custom metrics.
js/modules/k6/secrets
Package secrets implements `k6/secrets` giving access to secrets from secret sources to js code.
Package secrets implements `k6/secrets` giving access to secrets from secret sources to js code.
js/modules/k6/timers
Package timers exposes setInterval setTimeout and co.
Package timers exposes setInterval setTimeout and co.
js/modules/k6/webcrypto
Package webcrypto exports the webcrypto API.
Package webcrypto exports the webcrypto API.
js/modules/k6/ws
Package ws implements a k6/ws for k6.
Package ws implements a k6/ws for k6.
js/tc55/timers
Package timers is implementing setInterval setTimeout and co.
Package timers is implementing setInterval setTimeout and co.
lib/netext/grpcext
Package grpcext allows gRPC requests collecting stats info.
Package grpcext allows gRPC requests collecting stats info.
lib/strvals
Package strvals provides parsing utilities for strval lines, which follow the format: name=value,topname.subname=value.
Package strvals provides parsing utilities for strval lines, which follow the format: name=value,topname.subname=value.
lib/summary
Package summary provides types and utility methods for the end-of-test summary.
Package summary provides types and utility methods for the end-of-test summary.
lib/testutils
Package testutils contains the test utilities and helpers inside the k6 project.
Package testutils contains the test utilities and helpers inside the k6 project.
lib/testutils/grpcservice
Package grpcservice contains the implementation of the test GRPC service.
Package grpcservice contains the implementation of the test GRPC service.
lib/testutils/httpmultibin
Package httpmultibin is intended only for use in tests, do not import in production code!
Package httpmultibin is intended only for use in tests, do not import in production code!
lib/testutils/httpmultibin/grpc_wrappers_testing
Package grpc_wrappers_testing provides a test service that could be used for the testing gRPC wrappers
Package grpc_wrappers_testing provides a test service that could be used for the testing gRPC wrappers
lib/testutils/minirunner
Package minirunner provides a mock implementation of the lib.Runner We use it in tests
Package minirunner provides a mock implementation of the lib.Runner We use it in tests
lib/testutils/mockoutput
Package mockoutput implements a mock output for testing purposes.
Package mockoutput implements a mock output for testing purposes.
lib/testutils/mockresolver
Package mockresolver provides a mock implementation of netext.Resolver.
Package mockresolver provides a mock implementation of netext.Resolver.
lib/trace
Package trace provides functionalities for tracing instrumentation.
Package trace provides functionalities for tracing instrumentation.
loader
Package loader is about loading files from either the filesystem or through https requests.
Package loader is about loading files from either the filesystem or through https requests.
log
Package log implements various logrus hooks.
Package log implements various logrus hooks.
metrics/engine
Package engine contains the internal metrics engine responsible for aggregating metrics during the test and evaluating thresholds against them.
Package engine contains the internal metrics engine responsible for aggregating metrics during the test and evaluating thresholds against them.
output/cloud
Package cloud implements an Output that flushes to the k6 Cloud platform.
Package cloud implements an Output that flushes to the k6 Cloud platform.
output/cloud/expv2/pbcloud
Package pbcloud contains the Protobuf definitions used for the metrics flush RPCs.
Package pbcloud contains the Protobuf definitions used for the metrics flush RPCs.
output/cloud/insights
Package insights contains the logic for the k6 cloud insights output.
Package insights contains the logic for the k6 cloud insights output.
output/influxdb
Package influxdb provides an output plugin for sending results directly to InfluxDB v1.
Package influxdb provides an output plugin for sending results directly to InfluxDB v1.
output/json
Package json is implements an output to put metrics in a json file.
Package json is implements an output to put metrics in a json file.
output/opentelemetry
Package opentelemetry performs output operations for the opentelemetry extension
Package opentelemetry performs output operations for the opentelemetry extension
output/prometheusrw/remote
Package remote implements the Prometheus remote write protocol.
Package remote implements the Prometheus remote write protocol.
output/prometheusrw/remotewrite
Package remotewrite is a k6 output that sends metrics to a Prometheus remote write endpoint.
Package remotewrite is a k6 output that sends metrics to a Prometheus remote write endpoint.
output/prometheusrw/sigv4
Package sigv4 is responsible to for aws sigv4 signing of requests
Package sigv4 is responsible to for aws sigv4 signing of requests
output/prometheusrw/stale
Package stale handles the staleness process.
Package stale handles the staleness process.
output/summary
Package summary implements an output that collects metrics to be displayed in the end-of-test summary
Package summary implements an output that collects metrics to be displayed in the end-of-test summary
secretsource
Package secretsource registers all the internal secret sources when imported
Package secretsource registers all the internal secret sources when imported
secretsource/file
Package file implements secret source that reads the secrets from a file as key=value pairs one per line
Package file implements secret source that reads the secrets from a file as key=value pairs one per line
secretsource/mock
Package mock implements a secret source that is just taking secrets on the cli
Package mock implements a secret source that is just taking secrets on the cli
ui
Package ui contains some generic UI k6 components.
Package ui contains some generic UI k6 components.
ui/console
Package console implements the command-line UI for k6.
Package console implements the command-line UI for k6.
ui/pb
Package pb implements a progressbar component for CLI user interfaces
Package pb implements a progressbar component for CLI user interfaces
usage
Package usage implements usage tracking for k6 in order to figure what is being used within a given execution
Package usage implements usage tracking for k6 in order to figure what is being used within a given execution
js
common
Package common contains helpers for interacting with the JavaScript runtime.
Package common contains helpers for interacting with the JavaScript runtime.
modules
Package modules defines interfaces used for developing k6's JavaScript modules.
Package modules defines interfaces used for developing k6's JavaScript modules.
modules/k6
Package k6 implements the module imported as 'k6' from inside k6.
Package k6 implements the module imported as 'k6' from inside k6.
modules/k6/html
generated by js/modules/k6/html/gen/gen_elements.go; DO NOT EDIT
generated by js/modules/k6/html/gen/gen_elements.go; DO NOT EDIT
modules/k6/http
Package http implements the k6/http js module for k6.
Package http implements the k6/http js module for k6.
modulestest
Package modulestest contains helpers to test js modules
Package modulestest contains helpers to test js modules
promises
Package promises provides helpers for working with promises in k6.
Package promises provides helpers for working with promises in k6.
lib
Package lib is a kitchen sink of...
Package lib is a kitchen sink of...
consts
Package consts houses some constants needed across k6
Package consts houses some constants needed across k6
executor
Package executor defines the executors k6 can use.
Package executor defines the executors k6 can use.
fsext
Package fsext provides extended file system functions
Package fsext provides extended file system functions
netext
Package netext provides extensions to the standard net package
Package netext provides extensions to the standard net package
netext/httpext
Package httpext provides extensions to the standard net/http package
Package httpext provides extensions to the standard net/http package
types
Package types contains types used in the codebase Most of the types have a Null prefix like gopkg.in/guregu/null.v3 and UnmarshalJSON and MarshalJSON methods.
Package types contains types used in the codebase Most of the types have a Null prefix like gopkg.in/guregu/null.v3 and UnmarshalJSON and MarshalJSON methods.
Package metrics contains various k6 components that deal with metrics and thresholds.
Package metrics contains various k6 components that deal with metrics and thresholds.
Package output contains the interfaces that k6 outputs (and output extensions) have to implement, as well as some helpers to make their implementation and management easier.
Package output contains the interfaces that k6 outputs (and output extensions) have to implement, as well as some helpers to make their implementation and management easier.
cloud/expv2
Package expv2 contains a Cloud output using a Protobuf binary format for encoding payloads.
Package expv2 contains a Cloud output using a Protobuf binary format for encoding payloads.
csv
Package csv implements an output writing metrics in csv format
Package csv implements an output writing metrics in csv format
Package secretsource is a package to provide secret source interface and common functionality This functionality is to be used to provide k6 with a way to get secrets and help it handle them correctly.
Package secretsource is a package to provide secret source interface and common functionality This functionality is to be used to provide k6 with a way to get secrets and help it handle them correctly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL