Added hashcode to metric names
MODIFY
package-lock.json
package-lock.json
"chalk": "4.1.2",
"cors": "^2.8.5",
"countries-list": "^2.6.1",
- "crypto": "^1.0.1",
"csvtojson": "^2.0.10",
"curvereduce": "^0.0.4",
"decimal.js": "^10.4.2",
"node": "*"
}
},
- "node_modules/crypto": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
- "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
- "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
- },
"node_modules/crypto-browserify": {
"version": "3.12.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow=="
},
- "crypto": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
- "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig=="
- },
"crypto-browserify": {
"version": "3.12.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",

MODIFY
package.json
package.json
"chalk": "4.1.2",
"cors": "^2.8.5",
"countries-list": "^2.6.1",
- "crypto": "^1.0.1",
"csvtojson": "^2.0.10",
"curvereduce": "^0.0.4",
"decimal.js": "^10.4.2",

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -2,9 +2,10 @@ import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Log, LogLevel } from '../types/Log';
import { NextFunction, Request, Response } from 'express';
import PerformanceRecord, { PerformanceRecordGroup, PerformanceTracingData } from '../types/Performance';
-import client, { Gauge } from 'prom-client';
+import client, { Counter, DefaultMetricsCollectorConfiguration, Gauge, Metric } from 'prom-client';
import global, { ActionsResponse } from '../types/GlobalType';
+import { Action } from '../types/Authorization';
import AppAuthError from '../exception/AppAuthError';
import AppError from '../exception/AppError';
import BackendError from '../exception/BackendError';
@@ -25,7 +26,6 @@ import User from '../types/User';
import UserToken from '../types/UserToken';
import Utils from './Utils';
import chalk from 'chalk';
-import crypto from 'crypto';
import sizeof from 'object-sizeof';
const MODULE_NAME = 'Logging';
@@ -99,26 +99,28 @@ export default class Logging {
Logging.logConsoleWarning('====================================');
}
}
-
if (global.monitoringServer) {
- const gaugeDurationMetricName = 'mongodb' + '_Duration_' + crypto.randomBytes(8).toString('hex');
+ const labels = { tenant: tenant.subdomain, module: module, method: method };
+ const values = Object.values(labels).toString();
+ const hashCode = Utils.positiveHashcode(values);
+ const gaugeDurationMetricName = 'mongodb' + '_Duration_' + hashCode;
let gaugeDurationMetric:client.Gauge = global.monitoringServer.getGauge(gaugeDurationMetricName);
if (!gaugeDurationMetric) {
gaugeDurationMetric = this.createMetric(gaugeDurationMetricName);
- gaugeDurationMetric.labels({ tenant: tenant.subdomain, module: module, method: method }).set(executionDurationMillis);
+ gaugeDurationMetric.labels(labels).set(executionDurationMillis);
}
- const gaugeRequestSizeMetricName = 'mongodb' + '_RequestSize_' + crypto.randomBytes(8).toString('hex');
+ const gaugeRequestSizeMetricName = 'mongodb' + '_RequestSize_' + hashCode;
let gaugeRequestSizeMetric :client.Gauge = global.monitoringServer.getGauge(gaugeRequestSizeMetricName);
if (!gaugeRequestSizeMetric) {
gaugeRequestSizeMetric = this.createMetric(gaugeRequestSizeMetricName);
- gaugeRequestSizeMetric.labels({ tenant: tenant.subdomain, module: module, method: method }).set(sizeOfRequestDataKB);
+ gaugeRequestSizeMetric.labels(labels).set(sizeOfRequestDataKB);
}
- const gaugeResponseSizeMetricName = 'mongodb' + '_ResponseSize_' + crypto.randomBytes(8).toString('hex');
+ const gaugeResponseSizeMetricName = 'mongodb' + '_ResponseSize_' + hashCode;
let gaugeResponseSizeMetric :client.Gauge = global.monitoringServer.getGauge(gaugeResponseSizeMetricName);
if (!gaugeResponseSizeMetric) {
gaugeResponseSizeMetric = this.createMetric(gaugeResponseSizeMetricName);
}
- gaugeResponseSizeMetric.labels({ tenant: tenant.subdomain, module: module, method: method }).set(sizeOfResponseDataKB);
+ gaugeResponseSizeMetric.labels(labels).set(sizeOfResponseDataKB);
}
await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
@@ -134,6 +136,7 @@ export default class Logging {
}
}
+
public static traceNotificationStart(): number {
if (Logging.getTraceConfiguration().traceNotification) {
return Date.now();

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1773,6 +1773,19 @@ export default class Utils {
}
}
+ public static positiveHashcode(str :string):number {
+ return this.hashCode(str) + 2147483647 + 1;
+ }
+
+ private static hashCode(s:string): number {
+ let hash = 0,i = 0;
+ const len = s.length;
+ while (i < len) {
+ hash = ((hash << 5) - hash + s.charCodeAt(i++)) << 0;
+ }
+ return hash;
+ }
+
private static deleteUserPropertiesFromEntity(entityData?: EntityData): void {
Utils.deletePropertiesFromEntity(entityData, ['user', 'userID']);
}

Added hashcode to metric names