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 <noreply@paperclip.ing>
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
import http from 'k6/http';
|
import http from 'k6/http';
|
||||||
import { check, group } from 'k6';
|
import { check, group } from 'k6';
|
||||||
import { Rate, Trend } from 'k6/metrics';
|
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 errorRate = new Rate('errors');
|
||||||
const classificationLatency = new Trend('classification_p99');
|
const smsClassifyP99 = new Trend('sms_classify_p99');
|
||||||
const engineLatency = new Trend('engine_p99');
|
const numberReputationP99 = new Trend('number_reputation_p99');
|
||||||
|
const callAnalyzeP99 = new Trend('call_analyze_p99');
|
||||||
|
|
||||||
export const options = {
|
export const options = {
|
||||||
thresholds: {
|
thresholds: {
|
||||||
...defaultThresholds(200).thresholds,
|
...defaultThresholds(400).thresholds,
|
||||||
classification_p99: ['p(99)<300'],
|
sms_classify_p99: ['p(99)<150'],
|
||||||
engine_p99: ['p(99)<250'],
|
number_reputation_p99: ['p(99)<300'],
|
||||||
|
call_analyze_p99: ['p(99)<400'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,25 +26,50 @@ const headers = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
group('SMS Classification', function () {
|
group('SMS Text Classification', function () {
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
message: `Load test message ${randomString(8)} - please check if this is spam`,
|
text: `Is this message a spam attempt? ${randomString(16)}`,
|
||||||
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 });
|
const res = http.post(`${BASE_URL}/spamshield/sms/classify`, payload, { headers });
|
||||||
checkResponse(res, 200);
|
checkResponse(res, 200);
|
||||||
classificationLatency.add(res.timings.duration);
|
smsClassifyP99.add(res.timings.duration);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Spam Engine Health', function () {
|
group('Number Reputation Check', function () {
|
||||||
const res = http.get(`${BASE_URL}/spamshield/health`, { headers });
|
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);
|
checkResponse(res, 200);
|
||||||
engineLatency.add(res.timings.duration);
|
numberReputationP99.add(res.timings.duration);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Blocklist Check', function () {
|
group('Call Analysis', function () {
|
||||||
const res = http.get(`${BASE_URL}/spamshield/blocklist/check?phone=+1555${String(Math.floor(1000000 + Math.random() * 9000000))}`, { headers });
|
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);
|
checkResponse(res, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user