fixes for unit test
MODIFY
src/server/ocpp/json/JsonOCPPServer.ts
src/server/ocpp/json/JsonOCPPServer.ts
@@ -694,12 +694,15 @@ export default class JsonOCPPServer extends OCPPServer {
`${sizeOfCurrentRequestsBytes / 1000} kB used in JSON WS cache`
]
});
+
+ if (global.monitoringServer) {
global.monitoringServer.getGauge(Constants.WEB_SOCKET_RUNNING_REQUEST_RESPONSE).set(this.runningWSMessages);
global.monitoringServer.getGauge(Constants.WEB_SOCKET_OCPP_CONNECTIONS_COUNT).set(this.jsonWSConnections.size);
global.monitoringServer.getGauge(Constants.WEB_SOCKET_REST_CONNECTIONS_COUNT).set(this.jsonRestWSConnections.size);
global.monitoringServer.getGauge(Constants.WEB_SOCKET_CURRRENT_REQUEST).set(numberOfCurrentRequests);
global.monitoringServer.getGauge(Constants.WEB_SOCKET_RUNNING_REQUEST).set(Object.keys(this.runningWSRequestsMessages).length);
global.monitoringServer.getGauge(Constants.WEB_SOCKET_QUEUED_REQUEST).set(this.waitingWSMessages);
+ }
if (this.isDebug()) {
Logging.logConsoleDebug('=====================================');
Logging.logConsoleDebug(`** ${this.jsonWSConnections.size} JSON Connection(s)`);

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
@@ -294,20 +294,22 @@ export default class MongoDBStorage {
readPreference: this.dbConfig.readPreference ? this.dbConfig.readPreference as ReadPreferenceMode : ReadPreferenceMode.secondaryPreferred
}
);
+ if (global.monitoringServer) {
this.mongoDBClient.on('connectionCreated',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- (event) => global.monitoringServer.getGauge(Constants.MONGODB_CONNECTION_CREATED).inc(1)
+ (event) => global.monitoringServer?.getGauge(Constants.MONGODB_CONNECTION_CREATED).inc(1)
);
this.mongoDBClient.on('connectionClosed',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- (event) => global.monitoringServer.getGauge(Constants.MONGODB_CONNECTION_CLOSED).inc(1)
+ (event) => global.monitoringServer?.getGauge(Constants.MONGODB_CONNECTION_CLOSED).inc(1)
);
this.mongoDBClient.on('connectionReady',
(event) => {
this.connections.add(event.connectionId);
- global.monitoringServer.getGauge(Constants.MONGODB_CONNECTION_READY).set(this.connections.size);
+ global.monitoringServer?.getGauge(Constants.MONGODB_CONNECTION_READY).set(this.connections.size);
}
);
+ }
this.database = this.mongoDBClient.db();
// Keep a global reference
global.database = this;

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -101,6 +101,7 @@ export default class Logging {
}
}
+ if (global.monitoringServer) {
const gaugeDurationMetricName = 'mongodb' + '_' + tenant.subdomain + '_DurationMs_' + `${module}_${method}`;
let gaugeDurationMetric:client.Gauge = global.monitoringServer.getGauge(gaugeDurationMetricName);
if (!gaugeDurationMetric) {
@@ -119,6 +120,7 @@ export default class Logging {
gaugeResponseSizeMetric = global.monitoringServer.createGaugeMetric(gaugeResponseSizeMetricName, 'Db perf gauge response size');
}
gaugeResponseSizeMetric.set(sizeOfResponseDataKB);
+ }
await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantSubdomain: tenant.subdomain,

fixes for unit test