Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/k6-spike-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: k6 Spike Test

on:
workflow_dispatch:
pull_request:
paths:
- 'tests/k6/**'
- '.github/workflows/k6-spike-test.yml'

jobs:
spike:
name: Plans read-path spike (10 -> 2000 VUs)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Run k6 spike profile
uses: grafana/k6-action@v0.3.1
with:
filename: tests/k6/plans-spike.js
flags: --summary-export=results/k6-spike-summary.json
env:
BASE_URL: ${{ secrets.STAGING_URL }}
API_KEY: ${{ secrets.STAGING_API_KEY }}

- name: Publish JSON summary artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: k6-spike-summary
path: results/k6-spike-summary.json
if-no-files-found: warn
51 changes: 51 additions & 0 deletions tests/k6/plans-spike.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import http from 'k6/http';
import { check, sleep, group } from 'k6';
import { Counter, Trend } from 'k6/metrics';

const planErrors = new Counter('plan_errors');
const planLatency = new Trend('plan_latency');
const planP99 = new Trend('plan_p99_latency');

const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080';
const API_KEY = __ENV.API_KEY || 'test-key';
const PLANS_PATH = __ENV.PLANS_PATH || '/api/v1/plans';

export const options = {
vus: 10,
stages: [
{ duration: '5m', target: 2000 },
{ duration: '2m', target: 2000 },
{ duration: '1m', target: 0 },
],
thresholds: {
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(99)<1500'],
plan_p99_latency: ['p(99)<1500'],
plan_errors: ['count<1'],
},
};

export default function () {
group('Plans Read - Spike', () => {
const params = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`,
},
};

const res = http.get(`${BASE_URL}${PLANS_PATH}`, params);

const ok = check(res, {
'status is 200': (r) => r.status === 200,
'p99 < 1500ms': (r) => r.timings.duration < 1500,
'body is not empty': (r) => r.body && r.body.length > 0,
});

if (!ok) planErrors.add(1);
planLatency.add(res.timings.duration);
planP99.add(res.timings.duration);

sleep(1);
});
}
Loading