Performance gates

k6: Turn Performance Expectations Into a Test Result

Grafana k6 thresholds can turn latency and failure-rate targets into a failed exit status. A bounded script is a starting point for a repeatable release gate.

Conceptual performance test sequence defines expectations, runs a bounded workload and reviews a pass-or-fail gate.

A dashboard of response times can show what happened during a test. A release gate needs one more step: an explicit rule for what result is acceptable. Grafana k6 lets a team write that rule alongside a JavaScript load-test script.

As of October 28, 2026, k6 v2.3.0, published September 21, is the latest listed release. k6 is an established open-source tool, and thresholds are an existing capability, not a feature introduced by that release. Its local execution path makes a small experiment possible without building a larger testing platform first.

The k6 documentation distinguishes checks from thresholds. Checks record whether individual responses meet conditions such as a status code or expected content. A failed check alone does not cause the test process to exit with a failed status. Thresholds evaluate aggregate metrics against criteria and return a non-zero exit code when those criteria are breached. A threshold on the checks metric can make response correctness part of the gate.

Our engineering assessment is to begin with one bounded workload and a written expectation. The following illustrative script requests a local test service:

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  vus: 2,
  duration: '20s',
  thresholds: {
    http_req_failed: ['rate<0.01'],
    http_req_duration: ['p(95)<500'],
  },
};

export default function () {
  http.get('http://localhost:8080/api/items');
  sleep(1);
}

Save it as test.js and run k6 run test.js where the HTTP service is reachable. The endpoint is an example; it must exist in your test environment. If k6 runs inside a container, localhost refers to that container, so use an address reachable from the load generator instead.

Two virtual users run for 20 seconds. The illustrative criteria require an HTTP failure rate below 1% and a 95th-percentile request duration below 500 milliseconds. They are not recommended universal targets. Replace them with requirements for the specific service, workload and environment. Because the script is short and low-concurrency, a pass establishes only a small baseline under those conditions, not system capacity.

Make the request meaningful

A lightweight health endpoint may respond quickly even when a user-facing operation that queries a database or assembles a larger response is slow. Select a representative path, data set and request pattern. Document the service version, configuration, data state and location of the load generator. Otherwise a difference between runs may come from the test environment rather than the application change.

HTTP success is not necessarily application correctness. Add a check() for the expected status or response content, and a checks threshold if a failed check should fail the run. The checks guide shows both response and body assertions. Define the permitted error rate, latency and correctness criteria before seeing the result, rather than adjusting a gate until it passes.

For release comparisons, keep the script, test data, service configuration and load-generator placement stable, and record the application version alongside the result. Increase duration and concurrency only when the question requires them. Watch whether the generator itself can sustain the planned rate; otherwise its limits may be mistaken for the service’s limits.

The practical benefit is a performance expectation that reviewers can see in code and evaluate consistently. Its credibility comes from a representative workload and controlled comparison, not from the mere presence of a green threshold.

Which request would best represent a performance promise your team actually makes to users?

Sources