feat(k6): add bespoke load test files
All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 1m22s
All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 1m22s
This commit is contained in:
54
k6/configmap.yaml
Normal file
54
k6/configmap.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: k6-test-test-for-310--005
|
||||
namespace: dev
|
||||
labels:
|
||||
app: test-for-310--005
|
||||
app.kubernetes.io/managed-by: backstage
|
||||
app.kubernetes.io/component: load-testing
|
||||
data:
|
||||
K6_OUT: opentelemetry
|
||||
K6_OTEL_GRPC_EXPORTER_INSECURE: 'true'
|
||||
K6_OTEL_GRPC_EXPORTER_ENDPOINT: otel-collector.monitoring.svc.cluster.local:4317
|
||||
K6_OTEL_METRIC_PREFIX: k6_
|
||||
K6_OTEL_FLUSH_INTERVAL: '1000'
|
||||
K6_OTEL_EXPORT_INTERVAL: '5000'
|
||||
K6_OTEL_SERVICE_NAME: k6-test-for-310--005
|
||||
load-test.js: "import http from 'k6/http';\nimport { check, sleep, group } from\
|
||||
\ 'k6';\n\nconst vus = parseInt(__ENV.TEST_VUS || '10');\nconst duration = __ENV.TEST_DURATION\
|
||||
\ || '30s';\nconst targetUrl = __ENV.TARGET_URL || 'http://test-for-310--005.dev.svc.cluster.local:8080';\n\
|
||||
\nexport const options = {\n scenarios: {\n load_test: {\n executor:\
|
||||
\ 'ramping-vus',\n startVUs: 0,\n stages: [\n { duration: '10s',\
|
||||
\ target: vus },\n { duration: duration, target: vus },\n { duration:\
|
||||
\ '5s', target: 0 },\n ],\n },\n },\n thresholds: {\n http_req_duration:\
|
||||
\ ['p(95)<500'],\n http_req_failed: ['rate<0.01'],\n },\n};\n\nhttp.setResponseCallback(http.expectedStatuses({\
|
||||
\ min: 200, max: 399 }));\n\nexport default function () {\n group('Items API',\
|
||||
\ () => {\n const listRes = http.get(`${targetUrl}/api/items`);\n check(listRes,\
|
||||
\ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
||||
\ (r) => r.timings.duration < 500,\n 'response contains items': (r) => Array.isArray(r.json()),\n\
|
||||
\ });\n\n const createRes = http.post(`${targetUrl}/api/items`, JSON.stringify({\
|
||||
\ name: 'Test Item', description: 'A test item description' }), {\n headers:\
|
||||
\ { 'Content-Type': 'application/json' },\n });\n check(createRes, {\n \
|
||||
\ 'status is 201': (r) => r.status === 201,\n 'response time < 500ms':\
|
||||
\ (r) => r.timings.duration < 500,\n 'response contains id': (r) => r.json().id\
|
||||
\ !== undefined,\n });\n\n const itemId = createRes.json().id;\n\n const\
|
||||
\ getRes = http.get(`${targetUrl}/api/items/${itemId}`);\n check(getRes, {\n\
|
||||
\ 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
||||
\ (r) => r.timings.duration < 500,\n 'response contains correct id': (r)\
|
||||
\ => r.json().id === itemId,\n });\n\n const updateRes = http.put(`${targetUrl}/api/items/${itemId}`,\
|
||||
\ JSON.stringify({ name: 'Updated Item', description: 'Updated description' }),\
|
||||
\ {\n headers: { 'Content-Type': 'application/json' },\n });\n check(updateRes,\
|
||||
\ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
||||
\ (r) => r.timings.duration < 500,\n 'response contains updated name': (r)\
|
||||
\ => r.json().name === 'Updated Item',\n });\n\n const deleteRes = http.del(`${targetUrl}/api/items/${itemId}`);\n\
|
||||
\ check(deleteRes, {\n 'status is 200': (r) => r.status === 200,\n \
|
||||
\ 'response time < 500ms': (r) => r.timings.duration < 500,\n 'response\
|
||||
\ confirms deletion': (r) => r.json().deleted === itemId,\n });\n });\n\n\
|
||||
\ sleep(0.5);\n\n group('Actuator API', () => {\n const healthRes = http.get(`${targetUrl}/actuator/health`);\n\
|
||||
\ check(healthRes, {\n 'status is 200': (r) => r.status === 200,\n \
|
||||
\ 'response time < 500ms': (r) => r.timings.duration < 500,\n 'response\
|
||||
\ contains UP status': (r) => r.json().status === 'UP',\n });\n\n const\
|
||||
\ prometheusRes = http.get(`${targetUrl}/actuator/prometheus`);\n check(prometheusRes,\
|
||||
\ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
||||
\ (r) => r.timings.duration < 500,\n });\n });\n\n sleep(0.5);\n}"
|
||||
90
k6/load-test.js
Normal file
90
k6/load-test.js
Normal file
@@ -0,0 +1,90 @@
|
||||
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://test-for-310--005.dev.svc.cluster.local:8080';
|
||||
|
||||
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('Items API', () => {
|
||||
const listRes = http.get(`${targetUrl}/api/items`);
|
||||
check(listRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response contains items': (r) => Array.isArray(r.json()),
|
||||
});
|
||||
|
||||
const createRes = http.post(`${targetUrl}/api/items`, JSON.stringify({ name: 'Test Item', description: 'A test item description' }), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
check(createRes, {
|
||||
'status is 201': (r) => r.status === 201,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response contains id': (r) => r.json().id !== undefined,
|
||||
});
|
||||
|
||||
const itemId = createRes.json().id;
|
||||
|
||||
const getRes = http.get(`${targetUrl}/api/items/${itemId}`);
|
||||
check(getRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response contains correct id': (r) => r.json().id === itemId,
|
||||
});
|
||||
|
||||
const updateRes = http.put(`${targetUrl}/api/items/${itemId}`, JSON.stringify({ name: 'Updated Item', description: 'Updated description' }), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
check(updateRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response contains updated name': (r) => r.json().name === 'Updated Item',
|
||||
});
|
||||
|
||||
const deleteRes = http.del(`${targetUrl}/api/items/${itemId}`);
|
||||
check(deleteRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response confirms deletion': (r) => r.json().deleted === itemId,
|
||||
});
|
||||
});
|
||||
|
||||
sleep(0.5);
|
||||
|
||||
group('Actuator API', () => {
|
||||
const healthRes = http.get(`${targetUrl}/actuator/health`);
|
||||
check(healthRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response contains UP status': (r) => r.json().status === 'UP',
|
||||
});
|
||||
|
||||
const prometheusRes = http.get(`${targetUrl}/actuator/prometheus`);
|
||||
check(prometheusRes, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
});
|
||||
});
|
||||
|
||||
sleep(0.5);
|
||||
}
|
||||
24
k6/testrun.yaml
Normal file
24
k6/testrun.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: k6.io/v1alpha1
|
||||
kind: TestRun
|
||||
metadata:
|
||||
name: k6-test-for-310--005
|
||||
namespace: dev
|
||||
labels:
|
||||
app: test-for-310--005
|
||||
backstage.io/component: test-for-310--005
|
||||
app.kubernetes.io/managed-by: backstage
|
||||
app.kubernetes.io/component: load-testing
|
||||
spec:
|
||||
parallelism: 1
|
||||
script:
|
||||
configMap:
|
||||
name: k6-test-test-for-310--005
|
||||
file: load-test.js
|
||||
runner:
|
||||
image: grafana/k6:latest
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: k6-test-test-for-310--005
|
||||
env:
|
||||
- name: K6_OTEL_SERVICE_NAME
|
||||
value: k6-test-for-310--005
|
||||
Reference in New Issue
Block a user