From 38dbfeae55e73a7cd3d8834a09cce02dffc88db6 Mon Sep 17 00:00:00 2001 From: Paulius Date: Wed, 18 Dec 2024 16:41:34 +0000 Subject: [PATCH] Feature/sqnc 54 (#544) * SQNC-534: addingh express-prom-bundle package along with middleware. * SQNC-54: rebase and version increase. * SQNC-54: linting. * SQNC-54: remove function from promBundle. * SQNC-54: downgrade prom-bundle to v7. * SQNC-54: version bump. * SQNC-54: moving promBundle to the variable. --- package-lock.json | 63 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/server.ts | 11 +++++++++ 3 files changed, 75 insertions(+) diff --git a/package-lock.json b/package-lock.json index b6c144fd..008c8adf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "dotenv": "^16.4.7", "envalid": "^8.0.0", "express": "^4.21.2", + "express-prom-bundle": "^7.0.0", "knex": "^3.1.0", "moment": "^2.30.1", "multer": "^1.4.5-lts.1", @@ -974,6 +975,15 @@ "node": ">= 8" } }, + "node_modules/@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", + "peer": true, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -2652,6 +2662,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bintrees": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.2.tgz", + "integrity": "sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw==", + "peer": true + }, "node_modules/bn.js": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", @@ -4179,6 +4195,23 @@ "url": "https://opencollective.com/express" } }, + "node_modules/express-prom-bundle": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/express-prom-bundle/-/express-prom-bundle-7.0.2.tgz", + "integrity": "sha512-ffFV4HGHvCKnkNJFqm42sYztRJE5mLgOj8MpGey1HOatuFhtcwXoBD2m5gca7ZbcyjkIf7lOH5ZdrhlrBf0sGw==", + "dependencies": { + "@types/express": "^4.17.21", + "express": "^4.18.2", + "on-finished": "^2.3.0", + "url-value-parser": "^2.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "prom-client": ">=15.0.0" + } + }, "node_modules/express/node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -6886,6 +6919,19 @@ "integrity": "sha512-/MyYDxttz7DfGMMHiysAsFE4qF+pQYAA8ziO/3NcRVrQ5fSk+Mns4QZA/oRPFzvcqNoVJXQNWNAsdwBXLUkQKw==", "license": "MIT" }, + "node_modules/prom-client": { + "version": "15.1.3", + "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-15.1.3.tgz", + "integrity": "sha512-6ZiOBfCywsD4k1BN9IX0uZhF+tJkV8q8llP64G5Hajs4JOeVLPCwpPVcpXy3BwYiUGgyJzsJJQeOIv7+hDSq8g==", + "peer": true, + "dependencies": { + "@opentelemetry/api": "^1.4.0", + "tdigest": "^0.1.1" + }, + "engines": { + "node": "^16 || ^18 || >=20" + } + }, "node_modules/propagate": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", @@ -7850,6 +7896,15 @@ "node": ">=8.0.0" } }, + "node_modules/tdigest": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.2.tgz", + "integrity": "sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA==", + "peer": true, + "dependencies": { + "bintrees": "1.0.2" + } + }, "node_modules/test-exclude": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.1.tgz", @@ -8187,6 +8242,14 @@ "punycode": "^2.1.0" } }, + "node_modules/url-value-parser": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/url-value-parser/-/url-value-parser-2.2.0.tgz", + "integrity": "sha512-yIQdxJpgkPamPPAPuGdS7Q548rLhny42tg8d4vyTNzFqvOnwqrgHXvgehT09U7fwrzxi3RxCiXjoNUNnNOlQ8A==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 1df6a542..65f0669c 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "dotenv": "^16.4.7", "envalid": "^8.0.0", "express": "^4.21.2", + "express-prom-bundle": "^7.0.0", "knex": "^3.1.0", "moment": "^2.30.1", "multer": "^1.4.5-lts.1", diff --git a/src/server.ts b/src/server.ts index a515a568..746688fb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -2,6 +2,7 @@ import express, { Express } from 'express' import { setup, serve, SwaggerUiOptions } from 'swagger-ui-express' import cors from 'cors' import bodyParser from 'body-parser' +import promBundle from 'express-prom-bundle' import { errorHandler } from './lib/error-handler/index.js' import { RegisterRoutes } from './routes.js' @@ -24,6 +25,14 @@ const customCssToInject: string = ` .swagger-ui section.models { background-color: #f7f7f7; } ` +const promClient = promBundle({ + includePath: true, + promClient: { + collectDefaultMetrics: { + prefix: 'sqnc_matchmaker_api_', + }, + }, +}) export default async (): Promise => { const app: Express = express() @@ -37,6 +46,8 @@ export default async (): Promise => { app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.json()) app.use(cors()) + app.use(promClient) + app.use((req, _, next) => { // make sure we always have a file object on req even if this is not a multipart // body this is so that the attachment route can handle both JSON and multipart bodies