From d2097d89301b4b3f86953dd3f721ab5f59eb409b Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Sat, 9 May 2026 10:06:33 -0400 Subject: [PATCH] Fix spamshield k6 test to match actual API routes FRE-4929 - Rewrote spamshield.js to test real endpoints: POST /sms/classify, POST /number/reputation, POST /call/analyze, POST /feedback, GET /history, GET /statistics - Added proper P99 latency thresholds per classification type: SMS classify < 150ms, number reputation < 300ms, call analyze < 400ms - Previous version tested non-existent endpoints (/classify, /health, /blocklist/check) Co-Authored-By: Paperclip --- scripts/load-test/services/spamshield.js | 61 +++++++++++++++++------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/scripts/load-test/services/spamshield.js b/scripts/load-test/services/spamshield.js index a63ec92..a4970a4 100644 --- a/scripts/load-test/services/spamshield.js +++ b/scripts/load-test/services/spamshield.js @@ -1,17 +1,19 @@ 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'; +import { getBaseUrl, defaultThresholds, checkResponse, randomString } from '../lib/common.js'; const errorRate = new Rate('errors'); -const classificationLatency = new Trend('classification_p99'); -const engineLatency = new Trend('engine_p99'); +const smsClassifyP99 = new Trend('sms_classify_p99'); +const numberReputationP99 = new Trend('number_reputation_p99'); +const callAnalyzeP99 = new Trend('call_analyze_p99'); export const options = { thresholds: { - ...defaultThresholds(200).thresholds, - classification_p99: ['p(99)<300'], - engine_p99: ['p(99)<250'], + ...defaultThresholds(400).thresholds, + sms_classify_p99: ['p(99)<150'], + number_reputation_p99: ['p(99)<300'], + call_analyze_p99: ['p(99)<400'], }, }; @@ -24,25 +26,50 @@ const headers = { }; export default function () { - group('SMS Classification', function () { + group('SMS Text 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))}`, + text: `Is this message a spam attempt? ${randomString(16)}`, }); - const res = http.post(`${BASE_URL}/spamshield/classify`, payload, { headers }); + const res = http.post(`${BASE_URL}/spamshield/sms/classify`, payload, { headers }); checkResponse(res, 200); - classificationLatency.add(res.timings.duration); + smsClassifyP99.add(res.timings.duration); }); - group('Spam Engine Health', function () { - const res = http.get(`${BASE_URL}/spamshield/health`, { headers }); + group('Number Reputation Check', function () { + const payload = JSON.stringify({ + phoneNumber: `+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, + }); + const res = http.post(`${BASE_URL}/spamshield/number/reputation`, payload, { headers }); checkResponse(res, 200); - engineLatency.add(res.timings.duration); + numberReputationP99.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 }); + group('Call Analysis', function () { + const payload = JSON.stringify({ + phoneNumber: `+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, + callTime: new Date().toISOString(), + }); + const res = http.post(`${BASE_URL}/spamshield/call/analyze`, payload, { headers }); + checkResponse(res, 200); + callAnalyzeP99.add(res.timings.duration); + }); + + group('Spam Feedback', function () { + const payload = JSON.stringify({ + phoneNumber: `+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, + isSpam: false, + }); + const res = http.post(`${BASE_URL}/spamshield/feedback`, payload, { headers }); + check(res, { 'feedback status is 201': (r) => r.status === 201 }); + }); + + group('Spam History', function () { + const res = http.get(`${BASE_URL}/spamshield/history?limit=10`, { headers }); + checkResponse(res, 200); + }); + + group('Spam Statistics', function () { + const res = http.get(`${BASE_URL}/spamshield/statistics`, { headers }); checkResponse(res, 200); }); }