Files
sonar-test-go/k6/configmap.yaml
demo-bot d2e27c64c0
Some checks failed
Build and Push to ACR / Build and Push (push) Successful in 1m59s
Integration Test / Platform Conformance (pull_request) Successful in 4s
Integration Test / Unit Tests + Container Smoke (workflow_dispatch) All checks passed
Integration Test / Unit Tests + Container Smoke (pull_request) Successful in 1m25s
SonarQube Analysis / Build, Test & Analyse (pull_request) Failing after 2m46s
feat(k6): add bespoke load test files
2026-05-06 13:06:43 +00:00

56 lines
3.7 KiB
YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: k6-test-sonar-test-go
namespace: dev
labels:
app: sonar-test-go
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-go
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-go.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('Health Check',\
\ () => {\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 'body contains status UP': (r) => r.json().status\
\ === 'UP',\n });\n });\n\n sleep(0.5);\n\n group('Items API', () => {\n\
\ // List all items\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 'body is an\
\ array': (r) => Array.isArray(r.json()),\n });\n\n // Create a new item\n\
\ const createRes = http.post(\n `${targetUrl}/api/items`,\n JSON.stringify({\
\ name: 'Test Item', description: 'This is a test item.' }),\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 'body contains id': (r) => r.json().id\
\ !== undefined,\n });\n\n const itemId = createRes.json().id;\n\n //\
\ Get item by ID\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 'body contains correct\
\ id': (r) => r.json().id === itemId,\n });\n\n // Update item by ID\n \
\ const updateRes = http.put(\n `${targetUrl}/api/items/${itemId}`,\n \
\ 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 'body contains updated\
\ name': (r) => r.json().name === 'Updated Item',\n });\n\n // Delete item\
\ by ID\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 'body contains\
\ deleted id': (r) => r.json().deleted === itemId,\n });\n });\n\n sleep(0.5);\n\
}"