Files
ShieldAI/scripts/load-test/services/darkwatch.js
Michael Freno a804cab431 Add load testing job to GitHub Actions CI pipeline (FRE-4931)
- Add load-test job to ci.yml that runs after docker-build on push to main
- Create combined load test runner (scripts/load-test/run-all.sh) for all services
- Create k6 load test scripts for api, darkwatch, spamshield, and voiceprint
- Add shared k6 utilities (lib/common.js)
- Update load-test.yml to support all services and report artifacts
- Configure k6 cloud output and P99 threshold validation
- Generate load test report as CI artifact

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-09 09:16:36 -04:00

56 lines
1.6 KiB
JavaScript

import http from 'k6/http';
import { check, group } from 'k6';
import { Rate, Trend } from 'k6/metrics';
import { getBaseUrl, getTargetRps, getDuration, defaultThresholds, checkResponse, randomString } from '../lib/common.js';
const errorRate = new Rate('errors');
const scanLatency = new Trend('scan_p99');
const watchlistLatency = new Trend('watchlist_p99');
const alertLatency = new Trend('alert_p99');
export const options = {
thresholds: {
...defaultThresholds(200).thresholds,
scan_p99: ['p(99)<300'],
watchlist_p99: ['p(99)<200'],
alert_p99: ['p(99)<250'],
},
};
const BASE_URL = getBaseUrl();
const AUTH_TOKEN = __ENV.API_TOKEN || 'test-token';
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${AUTH_TOKEN}`,
};
export default function () {
group('Darkwatch Scan', function () {
const payload = JSON.stringify({
type: 'email',
value: `loadtest-${randomString()}@example.com`,
});
const res = http.post(`${BASE_URL}/darkwatch/scan`, payload, { headers });
checkResponse(res, 200);
scanLatency.add(res.timings.duration);
});
group('Watchlist', function () {
const res = http.get(`${BASE_URL}/watchlist?page=1&limit=20`, { headers });
checkResponse(res, 200);
watchlistLatency.add(res.timings.duration);
});
group('Alerts', function () {
const res = http.get(`${BASE_URL}/alerts?status=open&limit=10`, { headers });
checkResponse(res, 200);
alertLatency.add(res.timings.duration);
});
group('Exposure Check', function () {
const res = http.get(`${BASE_URL}/exposure/summary`, { headers });
checkResponse(res, 200);
});
}