Files
ShieldAI/scripts/load-test/lib/common.js
Michael Freno 4a2f6cf0fd Fix 4 Code Review findings on FRE-4928: dead heredoc, token warmup, summary path, .gitignore
- P2: Remove dead heredoc from run.sh mixed scenario
- P2: Add setup() warmup to seed real tokens for standalone scenarios
- P3: Replace handleSummary file output with --summary-export in run.sh
- P3: Add .gitignore for k6 results and .env
- Fix stray closing brace in scripts/load-test/lib/common.js

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-10 11:44:56 -04:00

49 lines
1.1 KiB
JavaScript

import { Trend, Rate } from 'k6/metrics';
export const errorRate = new Rate('error_rate');
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 {
thresholds: {
http_req_duration: [`p(99)<${p99ms}`],
error_rate: ['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,
});
errorRate.add(!pass);
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;
}
export const autoscaleMetric = new Trend('autoscale_vu_count');
export function recordAutoscaleMetric(vuCount) {
autoscaleMetric.add(vuCount);
}