feat: add service discovery, OTel instrumentation, and k6 load tests #1
87
k6/load-test.js
Normal file
87
k6/load-test.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import http from 'k6/http';
|
||||||
|
import { check, sleep, group } from 'k6';
|
||||||
|
|
||||||
|
const vus = parseInt(__ENV.TEST_VUS || '10');
|
||||||
|
const duration = __ENV.TEST_DURATION || '30s';
|
||||||
|
const targetUrl = __ENV.TARGET_URL || 'http://frontend.demo-apps.svc.cluster.local:80';
|
||||||
|
|
||||||
|
export const options = {
|
||||||
|
scenarios: {
|
||||||
|
load_test: {
|
||||||
|
executor: 'ramping-vus',
|
||||||
|
startVUs: 0,
|
||||||
|
stages: [
|
||||||
|
{ duration: '10s', target: vus },
|
||||||
|
{ duration: duration, target: vus },
|
||||||
|
{ duration: '5s', target: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
thresholds: {
|
||||||
|
http_req_duration: ['p(95)<500'],
|
||||||
|
http_req_failed: ['rate<0.01'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
http.setResponseCallback(http.expectedStatuses({ min: 200, max: 399 }));
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
group('System API', () => {
|
||||||
|
const resWelcome = http.get(`${targetUrl}/`);
|
||||||
|
check(resWelcome, {
|
||||||
|
'status is 200': (r) => r.status === 200,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
|
||||||
|
group('Owner API', () => {
|
||||||
|
const resFindOwners = http.get(`${targetUrl}/owners/find`);
|
||||||
|
check(resFindOwners, {
|
||||||
|
'status is 200': (r) => r.status === 200,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
|
||||||
|
const resCreateOwner = http.post(`${targetUrl}/owners/new`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890');
|
||||||
|
check(resCreateOwner, {
|
||||||
|
'status is 302': (r) => r.status === 302,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
|
||||||
|
const resOwnerDetails = http.get(`${targetUrl}/owners/1`);
|
||||||
|
check(resOwnerDetails, {
|
||||||
|
'status is 200': (r) => r.status === 200,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
|
||||||
|
group('Vet API', () => {
|
||||||
|
const resVetList = http.get(`${targetUrl}/vets.html`);
|
||||||
|
check(resVetList, {
|
||||||
|
'status is 200': (r) => r.status === 200,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
|
||||||
|
const resVetJson = http.get(`${targetUrl}/vets`);
|
||||||
|
check(resVetJson, {
|
||||||
|
'status is 200': (r) => r.status === 200,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
'response contains vet list': (r) => JSON.parse(r.body).vets.length > 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
|
||||||
|
group('Error Handling', () => {
|
||||||
|
const resError = http.get(`${targetUrl}/oups`, { responseCallback: http.expectedStatuses(500) });
|
||||||
|
check(resError, {
|
||||||
|
'status is 500': (r) => r.status === 500,
|
||||||
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user