Files
git.stella-ops.org/devops/vuln/k6-vuln-explorer.js
2025-12-26 18:11:06 +02:00

48 lines
1.5 KiB
JavaScript

import http from 'k6/http';
import { check, sleep } from 'k6';
import { Trend, Rate } from 'k6/metrics';
const latency = new Trend('vuln_api_latency');
const errors = new Rate('vuln_api_errors');
const BASE = __ENV.VULN_BASE || 'http://localhost:8449';
const TENANT = __ENV.VULN_TENANT || 'alpha';
const TOKEN = __ENV.VULN_TOKEN || '';
const HEADERS = TOKEN ? { 'Authorization': `Bearer ${TOKEN}`, 'X-StellaOps-Tenant': TENANT } : { 'X-StellaOps-Tenant': TENANT };
export const options = {
scenarios: {
ramp: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '5m', target: 200 },
{ duration: '10m', target: 200 },
{ duration: '2m', target: 0 },
],
gracefulRampDown: '30s',
},
},
thresholds: {
vuln_api_latency: ['p(95)<250'],
vuln_api_errors: ['rate<0.005'],
},
};
function req(path, params = {}) {
const res = http.get(`${BASE}${path}`, { headers: HEADERS, tags: params.tags });
latency.add(res.timings.duration, params.tags);
errors.add(res.status >= 400, params.tags);
check(res, {
'status is 2xx': (r) => r.status >= 200 && r.status < 300,
});
return res;
}
export default function () {
req(`/findings?tenant=${TENANT}&page=1&pageSize=50`, { tags: { endpoint: 'list' } });
req(`/findings?tenant=${TENANT}&status=open&page=1&pageSize=50`, { tags: { endpoint: 'filter_open' } });
req(`/findings/stats?tenant=${TENANT}`, { tags: { endpoint: 'stats' } });
sleep(1);
}