From bf0e0f5f38e79c3d9cbc3b7cd27f1305fa93f1fb Mon Sep 17 00:00:00 2001 From: demo-bot Date: Tue, 5 May 2026 10:01:35 +0000 Subject: [PATCH] feat: add service discovery, OTel instrumentation, and k6 load tests (#1) --- catalog-info.yaml | 158 ++++++++++++++++++++++++++ k6/load-test.js | 133 ++++++++++++++++++++++ k6/testrun.yaml | 24 ++++ overlays/deploy/k6-configmap.yaml | 68 +++++++++++ overlays/otel/kustomization.yaml | 14 +++ overlays/otel/patches/otel-patch.yaml | 19 ++++ 6 files changed, 416 insertions(+) create mode 100644 k6/load-test.js create mode 100644 k6/testrun.yaml create mode 100644 overlays/deploy/k6-configmap.yaml create mode 100644 overlays/otel/kustomization.yaml create mode 100644 overlays/otel/patches/otel-patch.yaml diff --git a/catalog-info.yaml b/catalog-info.yaml index 83588ba..b3326eb 100644 --- a/catalog-info.yaml +++ b/catalog-info.yaml @@ -139,3 +139,161 @@ spec: # ─── Per-service Components (from Watcher discovery) ───────────────── + +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: demo-db + description: "demo-db service — part of petclinic-demo-jonathan-scaf-2" + labels: + backstage.io/environment: "dev" + app.kubernetes.io/managed-by: "backstage" + tags: + - deployment + - argocd + + - opentelemetry + + - load-testing + - k6 + + - chaos-engineering + - chaos-mesh + + + annotations: + argocd/app-name: "petclinic-demo-jonathan-scaf-2" + argocd/app-namespace: "argocd" + argocd/instance-name: "argocd" + backstage.io/source-location: "url:https://gitea.kyndemo.live/validate/petclinic-demo-jonathan-scaf-2/src/branch/main" + backstage.io/kubernetes-namespace: "demo-apps" + backstage.io/kubernetes-label-selector: "app=demo-db" + backstage.io/techdocs-ref: dir:. + gitea.kyndemo.live/repo-slug: "validate/petclinic-demo-jonathan-scaf-2" + sonarqube.org/project-key: petclinic-demo-jonathan-scaf-2 + + grafana/grafana-instance: "default" + grafana/alert-label-selector: "app=demo-db" + grafana/dashboard-selector: "uid == 'otel-app-observability-v2'" + grafana.com/alert-label-selector: "app=demo-db" + grafana.com/dashboard-url: "https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-service=demo-db" + + k6/enabled: "true" + k6/test-configmap: "k6-test-petclinic-demo-jonathan-scaf-2" + k6/test-namespace: "demo-apps" + k6/target-service: "demo-db" + + chaos-mesh/enabled: "true" + + links: + - url: https://petclinic-demo-jonathan-scaf-2.kyndemo.live + title: Live Application + icon: web + - url: https://gitea.kyndemo.live/validate/petclinic-demo-jonathan-scaf-2 + title: Repository + icon: github + - url: https://argocd.kyndemo.live/applications/petclinic-demo-jonathan-scaf-2 + title: ArgoCD App + icon: dashboard + + - url: https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-service=demo-db + title: Grafana Dashboard + icon: dashboard + +spec: + type: service + owner: "platform-engineering" + lifecycle: experimental + + system: petclinic-demo-jonathan-scaf-2 + dependsOn: + - component:default/argocd-service + + - resource:default/veterinary-platform + + + - resource:default/otel-collector + + - resource:default/k6-operator + +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: petclinic + description: "petclinic service — part of petclinic-demo-jonathan-scaf-2" + labels: + backstage.io/environment: "dev" + app.kubernetes.io/managed-by: "backstage" + tags: + - deployment + - argocd + + - opentelemetry + + - load-testing + - k6 + + - chaos-engineering + - chaos-mesh + + + - java + + annotations: + argocd/app-name: "petclinic-demo-jonathan-scaf-2" + argocd/app-namespace: "argocd" + argocd/instance-name: "argocd" + backstage.io/source-location: "url:https://gitea.kyndemo.live/validate/petclinic-demo-jonathan-scaf-2/src/branch/main" + backstage.io/kubernetes-namespace: "demo-apps" + backstage.io/kubernetes-label-selector: "app=petclinic" + backstage.io/techdocs-ref: dir:. + gitea.kyndemo.live/repo-slug: "validate/petclinic-demo-jonathan-scaf-2" + sonarqube.org/project-key: petclinic-demo-jonathan-scaf-2 + + grafana/grafana-instance: "default" + grafana/alert-label-selector: "app=petclinic" + grafana/dashboard-selector: "uid == 'otel-app-observability-v2'" + grafana.com/alert-label-selector: "app=petclinic" + grafana.com/dashboard-url: "https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-service=petclinic" + + k6/enabled: "true" + k6/test-configmap: "k6-test-petclinic-demo-jonathan-scaf-2" + k6/test-namespace: "demo-apps" + k6/target-service: "petclinic" + + chaos-mesh/enabled: "true" + + links: + - url: https://petclinic-demo-jonathan-scaf-2.kyndemo.live + title: Live Application + icon: web + - url: https://gitea.kyndemo.live/validate/petclinic-demo-jonathan-scaf-2 + title: Repository + icon: github + - url: https://argocd.kyndemo.live/applications/petclinic-demo-jonathan-scaf-2 + title: ArgoCD App + icon: dashboard + + - url: https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-service=petclinic + title: Grafana Dashboard + icon: dashboard + +spec: + type: service + owner: "platform-engineering" + lifecycle: experimental + + system: petclinic-demo-jonathan-scaf-2 + dependsOn: + - component:default/argocd-service + + - resource:default/veterinary-platform + + + - resource:default/otel-collector + + - resource:default/k6-operator + + diff --git a/k6/load-test.js b/k6/load-test.js new file mode 100644 index 0000000..efbbd66 --- /dev/null +++ b/k6/load-test.js @@ -0,0 +1,133 @@ +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('Owner API', () => { + check(http.get(`${targetUrl}/owners/new`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.post(`${targetUrl}/owners/new`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890'), { + 'status is 302': (r) => r.status === 302, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/owners/find`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/owners`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/owners/1/edit`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.post(`${targetUrl}/owners/1/edit`, 'firstName=Jane&lastName=Doe&address=456+Elm+St&city=Springfield&telephone=9876543210'), { + 'status is 302': (r) => r.status === 302, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/owners/1`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + }); + + sleep(0.5); + + group('Pet API', () => { + check(http.get(`${targetUrl}/owners/1/pets/new`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.post(`${targetUrl}/owners/1/pets/new`, 'name=Buddy&birthDate=2020-01-01&type=Dog'), { + 'status is 302': (r) => r.status === 302, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/owners/1/pets/1/edit`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.post(`${targetUrl}/owners/1/pets/1/edit`, 'name=Buddy&birthDate=2019-01-01&type=Dog'), { + 'status is 302': (r) => r.status === 302, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + }); + + sleep(0.5); + + group('Visit API', () => { + check(http.get(`${targetUrl}/owners/1/pets/1/visits/new`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.post(`${targetUrl}/owners/1/pets/1/visits/new`, 'date=2023-10-01&description=Routine+checkup'), { + 'status is 302': (r) => r.status === 302, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + }); + + sleep(0.5); + + group('Vet API', () => { + check(http.get(`${targetUrl}/vets.html`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/vets`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + }); + + sleep(0.5); + + group('System API', () => { + check(http.get(`${targetUrl}/oups`, { responseCallback: http.expectedStatuses(500) }), { + 'status is 500': (r) => r.status === 500, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + + check(http.get(`${targetUrl}/`), { + 'status is 200': (r) => r.status === 200, + 'response time < 500ms': (r) => r.timings.duration < 500, + }); + }); + + sleep(0.5); +} \ No newline at end of file diff --git a/k6/testrun.yaml b/k6/testrun.yaml new file mode 100644 index 0000000..5139433 --- /dev/null +++ b/k6/testrun.yaml @@ -0,0 +1,24 @@ +apiVersion: k6.io/v1alpha1 +kind: TestRun +metadata: + name: k6-petclinic-demo-jonathan-scaf-2 + namespace: demo-apps + labels: + app: petclinic-demo-jonathan-scaf-2 + backstage.io/component: petclinic-demo-jonathan-scaf-2 + app.kubernetes.io/managed-by: backstage + app.kubernetes.io/component: load-testing +spec: + parallelism: 1 + script: + configMap: + name: k6-test-petclinic-demo-jonathan-scaf-2 + file: load-test.js + runner: + image: grafana/k6:latest + envFrom: + - configMapRef: + name: k6-test-petclinic-demo-jonathan-scaf-2 + env: + - name: K6_OTEL_SERVICE_NAME + value: k6-petclinic-demo-jonathan-scaf-2 diff --git a/overlays/deploy/k6-configmap.yaml b/overlays/deploy/k6-configmap.yaml new file mode 100644 index 0000000..f9c3367 --- /dev/null +++ b/overlays/deploy/k6-configmap.yaml @@ -0,0 +1,68 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: k6-test-petclinic-demo-jonathan-scaf-2 + namespace: demo-apps + labels: + app: petclinic-demo-jonathan-scaf-2 + 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-petclinic-demo-jonathan-scaf-2 + 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://frontend.demo-apps.svc.cluster.local:80';\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('Owner API',\ + \ () => {\n check(http.get(`${targetUrl}/owners/new`), {\n 'status is\ + \ 200': (r) => r.status === 200,\n 'response time < 500ms': (r) => r.timings.duration\ + \ < 500,\n });\n\n check(http.post(`${targetUrl}/owners/new`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890'),\ + \ {\n 'status is 302': (r) => r.status === 302,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/owners/find`),\ + \ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/owners`),\ + \ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/owners/1/edit`),\ + \ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.post(`${targetUrl}/owners/1/edit`,\ + \ 'firstName=Jane&lastName=Doe&address=456+Elm+St&city=Springfield&telephone=9876543210'),\ + \ {\n 'status is 302': (r) => r.status === 302,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/owners/1`),\ + \ {\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('Pet\ + \ API', () => {\n check(http.get(`${targetUrl}/owners/1/pets/new`), {\n \ + \ 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.post(`${targetUrl}/owners/1/pets/new`,\ + \ 'name=Buddy&birthDate=2020-01-01&type=Dog'), {\n 'status is 302': (r) =>\ + \ r.status === 302,\n 'response time < 500ms': (r) => r.timings.duration\ + \ < 500,\n });\n\n check(http.get(`${targetUrl}/owners/1/pets/1/edit`),\ + \ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.post(`${targetUrl}/owners/1/pets/1/edit`,\ + \ 'name=Buddy&birthDate=2019-01-01&type=Dog'), {\n 'status is 302': (r) =>\ + \ r.status === 302,\n 'response time < 500ms': (r) => r.timings.duration\ + \ < 500,\n });\n });\n\n sleep(0.5);\n\n group('Visit API', () => {\n \ + \ check(http.get(`${targetUrl}/owners/1/pets/1/visits/new`), {\n 'status\ + \ is 200': (r) => r.status === 200,\n 'response time < 500ms': (r) => r.timings.duration\ + \ < 500,\n });\n\n check(http.post(`${targetUrl}/owners/1/pets/1/visits/new`,\ + \ 'date=2023-10-01&description=Routine+checkup'), {\n 'status is 302': (r)\ + \ => r.status === 302,\n 'response time < 500ms': (r) => r.timings.duration\ + \ < 500,\n });\n });\n\n sleep(0.5);\n\n group('Vet API', () => {\n check(http.get(`${targetUrl}/vets.html`),\ + \ {\n 'status is 200': (r) => r.status === 200,\n 'response time < 500ms':\ + \ (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/vets`),\ + \ {\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('System\ + \ API', () => {\n check(http.get(`${targetUrl}/oups`, { responseCallback: http.expectedStatuses(500)\ + \ }), {\n 'status is 500': (r) => r.status === 500,\n 'response time\ + \ < 500ms': (r) => r.timings.duration < 500,\n });\n\n check(http.get(`${targetUrl}/`),\ + \ {\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}" diff --git a/overlays/otel/kustomization.yaml b/overlays/otel/kustomization.yaml new file mode 100644 index 0000000..c465c4c --- /dev/null +++ b/overlays/otel/kustomization.yaml @@ -0,0 +1,14 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../deploy +patches: +- target: + kind: Deployment + name: petclinic + patch: "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: petclinic\nspec:\n\ + \ template:\n metadata:\n annotations:\n instrumentation.opentelemetry.io/inject-java:\ + \ monitoring/otel-instrumentation\n spec:\n containers:\n - name:\ + \ workload\n env:\n - name: OTEL_SERVICE_NAME\n value:\ + \ petclinic\n - name: OTEL_EXPORTER_OTLP_ENDPOINT\n value: http://otel-collector.monitoring.svc.cluster.local:4318\n\ + \ - name: OTEL_RESOURCE_ATTRIBUTES\n value: app=petclinic-demo-jonathan-scaf-2\n" diff --git a/overlays/otel/patches/otel-patch.yaml b/overlays/otel/patches/otel-patch.yaml new file mode 100644 index 0000000..4e66014 --- /dev/null +++ b/overlays/otel/patches/otel-patch.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: petclinic +spec: + template: + metadata: + annotations: + instrumentation.opentelemetry.io/inject-java: monitoring/otel-instrumentation + spec: + containers: + - name: workload + env: + - name: OTEL_SERVICE_NAME + value: petclinic + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://otel-collector.monitoring.svc.cluster.local:4318 + - name: OTEL_RESOURCE_ATTRIBUTES + value: app=petclinic-demo-jonathan-scaf-2