feat: add service discovery, OTel instrumentation, and k6 load tests (#1)

This commit was merged in pull request #1.
This commit is contained in:
2026-08-11 16:36:49 +00:00
parent 38c63058df
commit fd1e3a476e
5 changed files with 261 additions and 0 deletions

137
k6/load-test.js Normal file
View File

@@ -0,0 +1,137 @@
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', () => {
let res = http.get(`${targetUrl}/`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/oups`, { responseCallback: http.expectedStatuses(500) });
check(res, {
'status is 500': (r) => r.status === 500,
});
});
sleep(0.5);
group('Owner API', () => {
let res = http.get(`${targetUrl}/owners/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/new`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890');
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${targetUrl}/owners/find`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/edit`, 'firstName=Jane&lastName=Doe&address=456+Elm+St&city=Metropolis&telephone=9876543210');
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${targetUrl}/owners/1`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/pets/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/new`, 'name=Buddy&birthDate=2023-01-01&type=Dog');
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${targetUrl}/owners/1/pets/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/1/edit`, 'name=Max&birthDate=2022-12-01&type=Cat');
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${targetUrl}/owners/1/pets/1/visits/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/1/visits/new`, 'date=2023-12-01&description=Routine+checkup');
check(res, {
'status is 302': (r) => r.status === 302,
});
});
sleep(0.5);
group('Vet API', () => {
let res = http.get(`${targetUrl}/vets.html`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/vets`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains vets': (r) => JSON.parse(r.body).vets.length > 0,
});
});
sleep(0.5);
}

24
k6/testrun.yaml Normal file
View File

@@ -0,0 +1,24 @@
apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
name: k6-demo-cyprus-1
namespace: demo-apps
labels:
app: demo-cyprus-1
backstage.io/component: demo-cyprus-1
app.kubernetes.io/managed-by: backstage
app.kubernetes.io/component: load-testing
spec:
parallelism: 1
script:
configMap:
name: k6-test-demo-cyprus-1
file: load-test.js
runner:
image: grafana/k6:latest
envFrom:
- configMapRef:
name: k6-test-demo-cyprus-1
env:
- name: K6_OTEL_SERVICE_NAME
value: k6-demo-cyprus-1