From fc4669f4e2337c6c5365a2cb75882e61bd552da4 Mon Sep 17 00:00:00 2001 From: Dhawal Sanghvi Date: Mon, 24 Jun 2024 12:12:19 +0530 Subject: [PATCH] add worker id to metrics --- package-lock.json | 19 +++++-------------- package.json | 2 +- src/middleware.js | 5 +++++ src/util/prometheus.js | 7 ++++++- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 44ce95996f..7fa0d6d3d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,7 +58,7 @@ "oauth-1.0a": "^2.2.6", "object-hash": "^3.0.0", "parse-static-imports": "^1.1.0", - "prom-client": "15.1.2", + "prom-client": "^14.2.0", "qs": "^6.11.1", "rudder-transformer-cdk": "^1.4.11", "set-value": "^4.1.0", @@ -4334,14 +4334,6 @@ "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==", - "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", @@ -17944,15 +17936,14 @@ } }, "node_modules/prom-client": { - "version": "15.1.2", - "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-15.1.2.tgz", - "integrity": "sha512-on3h1iXb04QFLLThrmVYg1SChBQ9N1c+nKAjebBjokBqipddH3uxmOUcEkTnzmJ8Jh/5TSUnUqS40i2QB2dJHQ==", + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-14.2.0.tgz", + "integrity": "sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA==", "dependencies": { - "@opentelemetry/api": "^1.4.0", "tdigest": "^0.1.1" }, "engines": { - "node": "^16 || ^18 || >=20" + "node": ">=10" } }, "node_modules/prompts": { diff --git a/package.json b/package.json index 9a78d682fa..2c7c6711e0 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "oauth-1.0a": "^2.2.6", "object-hash": "^3.0.0", "parse-static-imports": "^1.1.0", - "prom-client": "^15.1.2", + "prom-client": "^14.2.0", "qs": "^6.11.1", "rudder-transformer-cdk": "^1.4.11", "set-value": "^4.1.0", diff --git a/src/middleware.js b/src/middleware.js index e1a1550219..2d7eb1f18e 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -14,6 +14,11 @@ function initPyroscope() { }); Pyroscope.start(); Pyroscope.startHeapCollecting(); + process.on('SIGINT', () => { + Pyroscope.stop(); + Pyroscope.stopHeapCollecting(); + }); + } function getCPUProfile(seconds) { diff --git a/src/util/prometheus.js b/src/util/prometheus.js index 3776951f59..4cc8ab5135 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -1,12 +1,17 @@ const prometheusClient = require('prom-client'); const logger = require('../logger'); const { MetricsAggregator } = require('./metricsAggregator'); +const cluster = require('cluster'); const clusterEnabled = process.env.CLUSTER_ENABLED !== 'false'; const useMetricsAggregator = process.env.USE_METRICS_AGGREGATOR === 'true'; const instanceID = process.env.INSTANCE_ID || 'localhost'; const prefix = 'transformer'; -const defaultLabels = { instanceName: instanceID }; +const defaultLabels = { + instanceName: instanceID, + workerId: cluster.worker ? cluster.worker.id : 0, + isMaster: cluster.isMaster +}; function appendPrefix(name) { return `${prefix}_${name}`;