logs: pass logger via call context
This commit is contained in:
parent
8193b689ed
commit
cda622de09
|
|
@ -26,8 +26,7 @@ const args = require("yargs")
|
||||||
// CONTAINER_SANDBOX_MOUNT_POINT C:\C\0eac9a8da76f6d7119c5d9f86c8b3106d67dbbf01dbeb22fdc0192476b7e31cb\
|
// CONTAINER_SANDBOX_MOUNT_POINT C:\C\0eac9a8da76f6d7119c5d9f86c8b3106d67dbbf01dbeb22fdc0192476b7e31cb\
|
||||||
// path is injected as C:\config\driver-config-file.yaml
|
// path is injected as C:\config\driver-config-file.yaml
|
||||||
if (process.env.CONTAINER_SANDBOX_MOUNT_POINT) {
|
if (process.env.CONTAINER_SANDBOX_MOUNT_POINT) {
|
||||||
path = `${
|
path = `${process.env.CONTAINER_SANDBOX_MOUNT_POINT
|
||||||
process.env.CONTAINER_SANDBOX_MOUNT_POINT
|
|
||||||
}${stripWindowsDriveLetter(path)}`;
|
}${stripWindowsDriveLetter(path)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +117,7 @@ const cache = new LRU({ max: 500 });
|
||||||
const { logger } = require("../src/utils/logger");
|
const { logger } = require("../src/utils/logger");
|
||||||
const { GrpcError } = require("../src/utils/grpc");
|
const { GrpcError } = require("../src/utils/grpc");
|
||||||
const GeneralUtils = require("../src/utils/general");
|
const GeneralUtils = require("../src/utils/general");
|
||||||
|
const uuidv4 = require("uuid").v4;
|
||||||
|
|
||||||
if (args.logLevel) {
|
if (args.logLevel) {
|
||||||
logger.level = args.logLevel;
|
logger.level = args.logLevel;
|
||||||
|
|
@ -178,17 +178,25 @@ async function requestHandlerProxy(call, callback, serviceMethodName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requestReadableID = GeneralUtils.loggerIdFromRequest(call, serviceMethodName);
|
||||||
|
const requestUUID = uuidv4();
|
||||||
|
const callContext = {
|
||||||
|
logger: logger.child({
|
||||||
|
method: serviceMethodName,
|
||||||
|
requestId: requestReadableID,
|
||||||
|
uuid: requestUUID,
|
||||||
|
}),
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
logger.info(
|
callContext.logger.info(
|
||||||
"new request - driver: %s method: %s call: %j",
|
"new request: driver=%s, call: %j",
|
||||||
driver.constructor.name,
|
driver.constructor.name,
|
||||||
serviceMethodName,
|
|
||||||
cleansedCall
|
cleansedCall
|
||||||
);
|
);
|
||||||
|
|
||||||
const lockKeys = GeneralUtils.lockKeysFromRequest(call, serviceMethodName);
|
const lockKeys = GeneralUtils.lockKeysFromRequest(call, serviceMethodName);
|
||||||
if (lockKeys.length > 0) {
|
if (lockKeys.length > 0) {
|
||||||
logger.debug("operation lock keys: %j", lockKeys);
|
callContext.logger.debug("operation lock keys: %j", lockKeys);
|
||||||
// check locks
|
// check locks
|
||||||
lockKeys.forEach((key) => {
|
lockKeys.forEach((key) => {
|
||||||
if (operationLock.has(key)) {
|
if (operationLock.has(key)) {
|
||||||
|
|
@ -216,13 +224,13 @@ async function requestHandlerProxy(call, callback, serviceMethodName) {
|
||||||
let response;
|
let response;
|
||||||
let responseError;
|
let responseError;
|
||||||
try {
|
try {
|
||||||
// aquire locks
|
// acquire locks
|
||||||
if (lockKeys.length > 0) {
|
if (lockKeys.length > 0) {
|
||||||
lockKeys.forEach((key) => {
|
lockKeys.forEach((key) => {
|
||||||
operationLock.add(key);
|
operationLock.add(key);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
response = await driver[serviceMethodName](call);
|
response = await driver[serviceMethodName](call, callContext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
responseError = e;
|
responseError = e;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -246,10 +254,8 @@ async function requestHandlerProxy(call, callback, serviceMethodName) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
callContext.logger.info(
|
||||||
"new response - driver: %s method: %s response: %j",
|
"new response: %j",
|
||||||
driver.constructor.name,
|
|
||||||
serviceMethodName,
|
|
||||||
response
|
response
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -265,10 +271,8 @@ async function requestHandlerProxy(call, callback, serviceMethodName) {
|
||||||
message = stringify(e);
|
message = stringify(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(
|
callContext.logger.error(
|
||||||
"handler error - driver: %s method: %s error: %s",
|
"handler error: %s",
|
||||||
driver.constructor.name,
|
|
||||||
serviceMethodName,
|
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -498,8 +502,7 @@ if (process.env.LOG_MEMORY_USAGE == "1") {
|
||||||
const used = process.memoryUsage();
|
const used = process.memoryUsage();
|
||||||
for (let key in used) {
|
for (let key in used) {
|
||||||
console.log(
|
console.log(
|
||||||
`[${new Date()}] Memory Usage: ${key} ${
|
`[${new Date()}] Memory Usage: ${key} ${Math.round((used[key] / 1024 / 1024) * 100) / 100
|
||||||
Math.round((used[key] / 1024 / 1024) * 100) / 100
|
|
||||||
} MB`
|
} MB`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +516,7 @@ if (process.env.MANUAL_GC == "1") {
|
||||||
if (global.gc) {
|
if (global.gc) {
|
||||||
global.gc();
|
global.gc();
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) { }
|
||||||
}, process.env.MANUAL_GC_INTERVAL || 60000);
|
}, process.env.MANUAL_GC_INTERVAL || 60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -522,7 +525,7 @@ if (process.env.LOG_GRPC_SESSIONS == "1") {
|
||||||
console.log("dumping sessions");
|
console.log("dumping sessions");
|
||||||
try {
|
try {
|
||||||
console.log(csiServer.sessions);
|
console.log(csiServer.sessions);
|
||||||
} catch (e) {}
|
} catch (e) { }
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,49 @@ function lockKeysFromRequest(call, serviceMethodName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loggerIdFromRequest(call, serviceMethodName) {
|
||||||
|
switch (serviceMethodName) {
|
||||||
|
// controller
|
||||||
|
case "CreateVolume":
|
||||||
|
return call.request.name;
|
||||||
|
case "DeleteVolume":
|
||||||
|
case "ControllerExpandVolume":
|
||||||
|
case "ControllerPublishVolume":
|
||||||
|
case "ControllerUnpublishVolume":
|
||||||
|
case "ValidateVolumeCapabilities":
|
||||||
|
case "ControllerGetVolume":
|
||||||
|
case "ControllerModifyVolume":
|
||||||
|
return call.request.volume_id;
|
||||||
|
case "CreateSnapshot":
|
||||||
|
return call.request.source_volume_id;
|
||||||
|
case "DeleteSnapshot":
|
||||||
|
return call.request.snapshot_id;
|
||||||
|
case "ListVolumes":
|
||||||
|
case "GetCapacity":
|
||||||
|
case "ControllerGetCapabilities":
|
||||||
|
case "ListSnapshots":
|
||||||
|
return '';
|
||||||
|
|
||||||
|
// node
|
||||||
|
case "NodeStageVolume":
|
||||||
|
case "NodeUnstageVolume":
|
||||||
|
case "NodePublishVolume":
|
||||||
|
case "NodeUnpublishVolume":
|
||||||
|
case "NodeGetVolumeStats":
|
||||||
|
case "NodeExpandVolume":
|
||||||
|
return call.request.volume_id;
|
||||||
|
|
||||||
|
case "NodeGetCapabilities":
|
||||||
|
case "NodeGetInfo":
|
||||||
|
case "GetPluginInfo":
|
||||||
|
case "GetPluginCapabilities":
|
||||||
|
case "Probe":
|
||||||
|
return '';
|
||||||
|
default:
|
||||||
|
throw `loggerIdFromRequest: unknown method: ${serviceMethodName}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getLargestNumber() {
|
function getLargestNumber() {
|
||||||
let number;
|
let number;
|
||||||
for (let i = 0; i < arguments.length; i++) {
|
for (let i = 0; i < arguments.length; i++) {
|
||||||
|
|
@ -278,6 +321,7 @@ module.exports.crc32 = crc32;
|
||||||
module.exports.crc16 = crc16;
|
module.exports.crc16 = crc16;
|
||||||
module.exports.crc8 = crc8;
|
module.exports.crc8 = crc8;
|
||||||
module.exports.lockKeysFromRequest = lockKeysFromRequest;
|
module.exports.lockKeysFromRequest = lockKeysFromRequest;
|
||||||
|
module.exports.loggerIdFromRequest = loggerIdFromRequest;
|
||||||
module.exports.getLargestNumber = getLargestNumber;
|
module.exports.getLargestNumber = getLargestNumber;
|
||||||
module.exports.stringify = stringify;
|
module.exports.stringify = stringify;
|
||||||
module.exports.before_string = before_string;
|
module.exports.before_string = before_string;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue