Removed default tenant's subdomain
Compute Axios response size when Content-Length is not provided
MODIFY
src/storage/mongodb/PerformanceStorage.ts
src/storage/mongodb/PerformanceStorage.ts
@@ -8,6 +8,10 @@ import Utils from '../../utils/Utils';
export default class PerformanceStorage {
public static async savePerformanceRecord(performanceRecord: PerformanceRecord): Promise<void> {
+ // Remove default Tenant
+ if (!performanceRecord.tenantSubdomain || performanceRecord.tenantSubdomain === Constants.DEFAULT_TENANT) {
+ delete performanceRecord.tenantSubdomain;
+ }
// Validate
performanceRecord = PerformanceValidatorStorage.getInstance().validatePerformance(
performanceRecord as unknown as Record<string, unknown>);

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -87,7 +87,7 @@ export default class Logging {
}
Utils.isDevelopmentEnv() && await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
- tenantSubdomain: tenant.id,
+ tenantSubdomain: tenant.subdomain,
group: PerformanceRecordGroup.MONGO_DB,
durationMs: executionDurationMillis,
resSizeKb: sizeOfDataKB,
@@ -407,13 +407,19 @@ export default class Logging {
executionDurationMillis = (new Date().getTime() - response.config['timestamp'].getTime());
}
// Compute Length
- let sizeOfDataKB = 0;
+ const sizeOfRequestDataKB = Utils.truncTo(Utils.createDecimal(
+ sizeof(response.config)).div(1000).toNumber(), 2);
+ let sizeOfResponseDataKB = 0;
if (response.config.headers['Content-Length']) {
- sizeOfDataKB = Utils.truncTo(response.config.headers['Content-Length'] / 1024, 2);
+ sizeOfResponseDataKB = Utils.truncTo(
+ Utils.createDecimal(response.config.headers['Content-Length']).div(1024).toNumber(), 2);
+ } else if (response.data) {
+ sizeOfResponseDataKB = Utils.truncTo(
+ Utils.createDecimal(sizeof(response.data)).div(1024).toNumber(), 2);
}
- const message = `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'} ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'} KB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`;
+ const message = `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'} ms - Req ${(sizeOfRequestDataKB > 0) ? sizeOfRequestDataKB : '?'} KB - Res ${(sizeOfResponseDataKB > 0) ? sizeOfResponseDataKB : '?'} KB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`;
Utils.isDevelopmentEnv() && console.log(chalk.green(message));
- if (sizeOfDataKB > Constants.PERF_MAX_DATA_VOLUME_KB) {
+ if (sizeOfResponseDataKB > Constants.PERF_MAX_DATA_VOLUME_KB) {
const error = new Error(`Data must be < ${Constants.PERF_MAX_DATA_VOLUME_KB}`);
await Logging.logWarning({
tenantID: tenant.id,
@@ -471,7 +477,8 @@ export default class Logging {
httpResponseCode: response.status,
httpMethod: response.config.method.toLocaleUpperCase(),
durationMs: executionDurationMillis,
- resSizeKb: sizeOfDataKB,
+ reqSizeKb: sizeOfRequestDataKB,
+ resSizeKb: sizeOfResponseDataKB,
action: ServerAction.HTTP_RESPONSE,
})
);
@@ -479,7 +486,7 @@ export default class Logging {
await Logging.logSecurityDebug({
tenantID: tenant.id,
action: ServerAction.HTTP_RESPONSE,
- message: `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'} ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'} KB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`,
+ message: `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'} ms - Req ${(sizeOfRequestDataKB > 0) ? sizeOfRequestDataKB : '?'} KB - Res ${(sizeOfResponseDataKB > 0) ? sizeOfResponseDataKB : '?'} KB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`,
module: Constants.MODULE_AXIOS, method: 'logAxiosResponse',
detailedMessages: {
status: response.status,

Removed default tenant's subdomain
Compute Axios response size when Content-Length is not provided