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 classificationLatency = new Trend('classification_p99'); const engineLatency = new Trend('engine_p99'); export const options = { thresholds: { ...defaultThresholds(200).thresholds, classification_p99: ['p(99)<300'], engine_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('SMS Classification', function () { const payload = JSON.stringify({ message: `Load test message ${randomString(8)} - please check if this is spam`, from: `+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, to: `+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, }); const res = http.post(`${BASE_URL}/spamshield/classify`, payload, { headers }); checkResponse(res, 200); classificationLatency.add(res.timings.duration); }); group('Spam Engine Health', function () { const res = http.get(`${BASE_URL}/spamshield/health`, { headers }); checkResponse(res, 200); engineLatency.add(res.timings.duration); }); group('Blocklist Check', function () { const res = http.get(`${BASE_URL}/spamshield/blocklist/check?phone=+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, { headers }); checkResponse(res, 200); }); }