Write a minimal k6 test with SLO thresholds.
IntermediateConceptCapacity, Load Testing & Chaos Engineering
Answer
import http from 'k6/http';
import { check } from 'k6';
export const options = {
vus: 50,
duration: '5m',
thresholds: {
http_req_failed: ['rate<0.001'], // 99.9% availability
http_req_duration: ['p(95)<200', 'p(99)<300'], // latency in ms
},
};
export default function () {
const res = http.get(`${__ENV.BASE_URL}/api/checkout`);
check(res, { 'status is 200': (r) => r.status === 200 });
}
Run with k6 run -e BASE_URL=https://staging.example.com test.js. If any threshold fails, k6 exits with code 99, which fails the CI job.
More on Capacity, Load Testing & Chaos Engineering
What is capacity planning in SRE?BeginnerWhat is N+1 and N+2 redundancy for capacity?BeginnerHow do you calculate how many instances you need?IntermediateWhat is the difference between load, stress, spike, soak and breakpoint testing?BeginnerWhat is k6 and why do SRE teams use it?BeginnerWhat is the difference between open and closed workload models in load testing?Advanced