- 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>
43 lines
984 B
JavaScript
43 lines
984 B
JavaScript
import { Rate, Trend } from 'k6/metrics';
|
|
|
|
export const errorRate = new Rate('errors');
|
|
|
|
export function getBaseUrl() {
|
|
return __ENV.BASE_URL || 'http://localhost:3000';
|
|
}
|
|
|
|
export function getTargetRps() {
|
|
return parseInt(__ENV.TARGET_RPS || '500', 10);
|
|
}
|
|
|
|
export function getDuration() {
|
|
return __ENV.DURATION || '300s';
|
|
}
|
|
|
|
export function defaultThresholds(p99ms) {
|
|
return {
|
|
http_req_duration: [`p(99)<${p99ms}`],
|
|
errors: ['rate<0.01'],
|
|
};
|
|
}
|
|
|
|
export function checkResponse(res, expectedStatus = 200) {
|
|
const pass = check(res, {
|
|
'status is expected': (r) => r.status === expectedStatus,
|
|
'response time OK': (r) => r.timings.duration < 5000,
|
|
});
|
|
if (!pass) {
|
|
errorRate.add(1);
|
|
}
|
|
return pass;
|
|
}
|
|
|
|
export function randomString(length = 10) {
|
|
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
for (let i = 0; i < length; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return result;
|
|
}
|