SoftwareTestPilot
All discussions
Aiko TanakaJul 12

k6 thresholds — how do I fail a build on p95 latency?

I want the CI job to fail if p95 > 500ms or error rate > 1%. What does the threshold syntax look like?

k6thresholdsci
Related learningExplore Academy skill paths

1 answer

Accepted solution

Aiko TanakaJul 13

Thresholds are k6's pass/fail gate. You declare them in `options.thresholds` against any metric, and if a threshold is breached k6 exits with a non-zero code so CI fails the build.

js
export const options = {
  thresholds: {
    http_req_failed: ['rate<0.01'],
    http_req_duration: ['p(95)<500', 'p(99)<1200'],
    'http_req_duration{endpoint:checkout}': ['p(95)<800'],
  },
};

Practical rules: always assert on percentiles (p95/p99), never the average — averages hide the tail your users actually feel. Tag critical endpoints and set per-tag thresholds so a slow search endpoint does not mask a fast-but-broken checkout. Add `abortOnFail: true` when you want a smoke test to stop the moment the SLO is broken instead of burning ten minutes of load.