From f501786e9939e34f5347f3e9798e5c8101e998be Mon Sep 17 00:00:00 2001 From: jurabek Date: Sun, 7 Apr 2024 00:34:08 +0200 Subject: [PATCH] load testing using docker --- .../docker/docker-compose.grafana.yaml | 11 ++- .../docker/docker-compose.override.yml | 1 + src/backend/docker/docker-compose.yml | 2 - src/backend/load-tests/Dockerfile | 3 + src/backend/load-tests/checkout.js | 2 +- .../services/checkout-api/package-lock.json | 74 +++++++++++++++++++ .../services/checkout-api/package.json | 2 + .../services/checkout-api/src/index.ts | 6 ++ .../checkout-api/src/routes/routes.ts | 2 + 9 files changed, 99 insertions(+), 4 deletions(-) diff --git a/src/backend/docker/docker-compose.grafana.yaml b/src/backend/docker/docker-compose.grafana.yaml index 58159782d..e9f3cfc6f 100644 --- a/src/backend/docker/docker-compose.grafana.yaml +++ b/src/backend/docker/docker-compose.grafana.yaml @@ -46,4 +46,13 @@ services: retries: 5 networks: - loki - - default \ No newline at end of file + - default + + influxdb: + image: influxdb:1.8 + networks: + - default + ports: + - "8086:8086" + environment: + - INFLUXDB_DB=k6 diff --git a/src/backend/docker/docker-compose.override.yml b/src/backend/docker/docker-compose.override.yml index 3032b3548..d5beaf29e 100755 --- a/src/backend/docker/docker-compose.override.yml +++ b/src/backend/docker/docker-compose.override.yml @@ -40,6 +40,7 @@ services: - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 - OTEL_EXPORTER_OTLP_ENDPOINT_HTTP=http://otel-collector:4318/v1/metrics - BASE_URL=/checkout + - LOG_LEVEL=debug catalog-api: environment: diff --git a/src/backend/docker/docker-compose.yml b/src/backend/docker/docker-compose.yml index 2ae526a22..80575272f 100644 --- a/src/backend/docker/docker-compose.yml +++ b/src/backend/docker/docker-compose.yml @@ -21,7 +21,6 @@ services: catalog-api: image: catalog-api - container_name: catalog build: ./services/catalog-api depends_on: - catalog-db @@ -40,7 +39,6 @@ services: order-api: image: restaurant/order-api - container_name: order build: platforms: - "linux/arm64" diff --git a/src/backend/load-tests/Dockerfile b/src/backend/load-tests/Dockerfile index cd1ee1331..420c86a8e 100644 --- a/src/backend/load-tests/Dockerfile +++ b/src/backend/load-tests/Dockerfile @@ -2,3 +2,6 @@ FROM grafana/xk6 RUN xk6 build --with github.com/szkiba/xk6-faker@latest # Copy checkout +COPY ./checkout.js ./ + +ENTRYPOINT [ "/bin/sh" ] \ No newline at end of file diff --git a/src/backend/load-tests/checkout.js b/src/backend/load-tests/checkout.js index 385a89c1c..16cb57e11 100644 --- a/src/backend/load-tests/checkout.js +++ b/src/backend/load-tests/checkout.js @@ -11,7 +11,7 @@ export const options = { }, }; -const baseUrl = "http://localhost:8080"; +const baseUrl = "http://traefik:8080"; const cartUrl = baseUrl + "/shoppingcart"; const catalogUrl = baseUrl + "/catalog"; const checkoutUrl = baseUrl + "/checkout"; diff --git a/src/backend/services/checkout-api/package-lock.json b/src/backend/services/checkout-api/package-lock.json index e7a1145be..079883e87 100644 --- a/src/backend/services/checkout-api/package-lock.json +++ b/src/backend/services/checkout-api/package-lock.json @@ -20,6 +20,7 @@ "kafkajs": "^2.2.4", "opentelemetry-instrumentation-kafkajs": "^0.40.0", "pino": "^8.11.0", + "pino-http": "^9.0.0", "zod": "^3.22.4" }, "devDependencies": { @@ -33,6 +34,7 @@ "mocha": "^10.2.0", "nodemon": "^3.0.1", "prettier": "^3.1.0", + "prisma": "^5.12.0", "sinon": "^17.0.1", "ts-node": "^10.9.1", "typescript": "^5.0.2" @@ -1323,6 +1325,51 @@ "@opentelemetry/api": "^1.1.0" } }, + "node_modules/@prisma/debug": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.12.0.tgz", + "integrity": "sha512-wK3fQLxPLMqf5riT5ZIhl8NffPSzFUwtzFX5CH7z/oI9Swmo9UhQlUgZABIVgdXSJ5OAlmRcDZtDKaMApIl8sg==", + "dev": true + }, + "node_modules/@prisma/engines": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.12.0.tgz", + "integrity": "sha512-rFNRul9JGu0d3tf8etBgmDQ4NVoDwgGrRguvQOc8i+c6g7xPjRuu4aKzMMvHWUuccvRx5+fs1KMBxQ0x2THt+Q==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/debug": "5.12.0", + "@prisma/engines-version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "@prisma/fetch-engine": "5.12.0", + "@prisma/get-platform": "5.12.0" + } + }, + "node_modules/@prisma/engines-version": { + "version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab.tgz", + "integrity": "sha512-6yvO8s80Tym61aB4QNtYZfWVmE3pwqe807jEtzm8C5VDe7nw8O1FGX3TXUaXmWV0fQTIAfRbeL2Gwrndabp/0g==", + "dev": true + }, + "node_modules/@prisma/fetch-engine": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.12.0.tgz", + "integrity": "sha512-qkHQbZ1hspvOwcImvqY4yj7+FUlw0+uP+6tu3g24V4ULHOXLLkvr5ZZc6vy26OF0hkbD3kcDJCeutFis3poKgg==", + "dev": true, + "dependencies": { + "@prisma/debug": "5.12.0", + "@prisma/engines-version": "5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab", + "@prisma/get-platform": "5.12.0" + } + }, + "node_modules/@prisma/get-platform": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.12.0.tgz", + "integrity": "sha512-81Ptv9YJnwTArEBPQ2Lvu58sZPxy4OixKxVVgysFan6A3bFP7q8gIg15WTjsRuH4WXh6B667EM9sqoMTNu0fLQ==", + "dev": true, + "dependencies": { + "@prisma/debug": "5.12.0" + } + }, "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -3696,6 +3743,17 @@ "split2": "^4.0.0" } }, + "node_modules/pino-http": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/pino-http/-/pino-http-9.0.0.tgz", + "integrity": "sha512-Q9QDNEz0vQmbJtMFjOVr2c9yL92vHudjmr3s3m6J1hbw3DBGFZJm3TIj9TWyynZ4GEsEA9SOtni4heRUr6lNOg==", + "dependencies": { + "get-caller-file": "^2.0.5", + "pino": "^8.17.1", + "pino-std-serializers": "^6.2.2", + "process-warning": "^3.0.0" + } + }, "node_modules/pino-std-serializers": { "version": "6.2.2", "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", @@ -3751,6 +3809,22 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prisma": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.12.0.tgz", + "integrity": "sha512-zxw4WSIvpsyNbpv8r7Fxgm7nwTFVmD6wbN6VuH13lClOceSANDOMl4jO3oxE6VzhjxmnEJqOGZjON2T2UpmLag==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/engines": "5.12.0" + }, + "bin": { + "prisma": "build/index.js" + }, + "engines": { + "node": ">=16.13" + } + }, "node_modules/process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", diff --git a/src/backend/services/checkout-api/package.json b/src/backend/services/checkout-api/package.json index 4b2f17084..276d5b74b 100644 --- a/src/backend/services/checkout-api/package.json +++ b/src/backend/services/checkout-api/package.json @@ -20,6 +20,7 @@ "mocha": "^10.2.0", "nodemon": "^3.0.1", "prettier": "^3.1.0", + "prisma": "^5.12.0", "sinon": "^17.0.1", "ts-node": "^10.9.1", "typescript": "^5.0.2" @@ -37,6 +38,7 @@ "kafkajs": "^2.2.4", "opentelemetry-instrumentation-kafkajs": "^0.40.0", "pino": "^8.11.0", + "pino-http": "^9.0.0", "zod": "^3.22.4" } } diff --git a/src/backend/services/checkout-api/src/index.ts b/src/backend/services/checkout-api/src/index.ts index f7e132910..f0a37e840 100644 --- a/src/backend/services/checkout-api/src/index.ts +++ b/src/backend/services/checkout-api/src/index.ts @@ -6,9 +6,15 @@ import router from './routes/routes'; import { logger } from './utils/logger'; import { config } from './config/config'; import express from 'express'; +import pinoHTTP from 'pino-http'; const app = express(); app.use(express.json()); +app.use( + pinoHTTP({ + logger, + }) +); app.use(config.baseUrl, router) diff --git a/src/backend/services/checkout-api/src/routes/routes.ts b/src/backend/services/checkout-api/src/routes/routes.ts index 7b482e591..a9022c1f5 100644 --- a/src/backend/services/checkout-api/src/routes/routes.ts +++ b/src/backend/services/checkout-api/src/routes/routes.ts @@ -1,6 +1,7 @@ import express, { Request, Response } from "express"; import { UserCheckoutReq, UserCheckoutSchema } from "../models/model"; import Checkout from "../checkout/checkout"; +import { logger } from "../utils/logger"; const router = express.Router(); @@ -15,6 +16,7 @@ router.post('/api/v1/checkout', async (req: Request, res: Response) => { transaction_id: checkout.transaction_id, }); } catch (error) { + logger.error(error); res.status(500).send({ error_message: error }) } });