All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 4m49s
53 lines
3.6 KiB
YAML
53 lines
3.6 KiB
YAML
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: k6-test-sonar-test-nest3
|
|
namespace: dev
|
|
labels:
|
|
app: sonar-test-nest3
|
|
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-sonar-test-nest3
|
|
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://sonar-test-nest3.dev.svc.cluster.local:3000';\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('Health API',\
|
|
\ () => {\n const res = http.get(`${targetUrl}/health`);\n check(res, {\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\n group('Items\
|
|
\ API', () => {\n const res1 = http.get(`${targetUrl}/api/items`);\n check(res1,\
|
|
\ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
|
\ (r) => r.timings.duration < 500,\n 'response contains items': (r) => Array.isArray(JSON.parse(r.body)),\n\
|
|
\ });\n\n const createBody = { name: 'Test Item', description: 'A test description'\
|
|
\ };\n const res2 = http.post(`${targetUrl}/api/items`, JSON.stringify(createBody),\
|
|
\ {\n headers: { 'Content-Type': 'application/json' },\n });\n check(res2,\
|
|
\ {\n 'status is 201': (r) => r.status === 201,\n 'response time < 500ms':\
|
|
\ (r) => r.timings.duration < 500,\n 'response contains created item': (r)\
|
|
\ => JSON.parse(r.body).name === createBody.name,\n });\n\n const itemId\
|
|
\ = JSON.parse(res2.body).id;\n\n const res3 = http.get(`${targetUrl}/api/items/${itemId}`);\n\
|
|
\ check(res3, {\n 'status is 200': (r) => r.status === 200,\n 'response\
|
|
\ time < 500ms': (r) => r.timings.duration < 500,\n 'response contains item':\
|
|
\ (r) => JSON.parse(r.body).id === itemId,\n });\n\n const updateBody =\
|
|
\ { name: 'Updated Item', description: 'Updated description' };\n const res4\
|
|
\ = http.put(`${targetUrl}/api/items/${itemId}`, JSON.stringify(updateBody), {\n\
|
|
\ headers: { 'Content-Type': 'application/json' },\n });\n check(res4,\
|
|
\ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\
|
|
\ (r) => r.timings.duration < 500,\n 'response contains updated item': (r)\
|
|
\ => JSON.parse(r.body).name === updateBody.name,\n });\n\n const res5 =\
|
|
\ http.del(`${targetUrl}/api/items/${itemId}`);\n check(res5, {\n 'status\
|
|
\ is 200': (r) => r.status === 200,\n 'response time < 500ms': (r) => r.timings.duration\
|
|
\ < 500,\n 'response confirms deletion': (r) => JSON.parse(r.body).deleted\
|
|
\ === itemId,\n });\n });\n\n sleep(0.5);\n}"
|