Skip to content
Latchkey

How to Configure k6 Thresholds as a CI Gate

A k6 threshold pins a metric to a pass condition; if the run ends outside it, k6 exits non-zero and CI fails.

Thresholds live under options.thresholds, keyed by metric name. Use abortOnFail to stop the test the moment a threshold is crossed instead of waiting for the full duration.

Steps

  • Pick the metrics that define acceptable performance (http_req_duration, http_req_failed).
  • Express each as a condition string such as p(95)<800 or rate<0.02.
  • Add abortOnFail: true to fail fast on a bad build.

Threshold config

k6-script.js
export const options = {
  thresholds: {
    http_req_duration: [
      { threshold: 'p(95)<800', abortOnFail: true },
      { threshold: 'p(99)<1500' },
    ],
    http_req_failed: ['rate<0.02'],
    checks: ['rate>0.99'],
  },
};

Gotchas

  • Thresholds evaluate over the whole run by default; scope them with tags for per-endpoint gates.
  • abortOnFail has a delayAbortEval so early noisy samples do not trip the gate prematurely.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →