1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3116 from node-red-hitachi/dev-httpreqlog

Extend HTTP request node to log detailed timing information
This commit is contained in:
Nick O'Leary 2021-09-27 17:56:34 +01:00 committed by GitHub
commit 3eb438c8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,6 +99,11 @@ in your Node-RED user directory (${RED.settings.userDir}).
noprox = proxyConfig.noproxy; noprox = proxyConfig.noproxy;
} }
let timingLog = false;
if (RED.settings.hasOwnProperty("httpRequestTimingLog")) {
timingLog = RED.settings.httpRequestTimingLog;
}
this.on("input",function(msg,nodeSend,nodeDone) { this.on("input",function(msg,nodeSend,nodeDone) {
checkNodeAgentPatch(); checkNodeAgentPatch();
//reset redirectList on each request //reset redirectList on each request
@ -514,6 +519,9 @@ in your Node-RED user directory (${RED.settings.userDir}).
if (res.client && res.client.bytesRead) { if (res.client && res.client.bytesRead) {
node.metric("size.bytes", msg, res.client.bytesRead); node.metric("size.bytes", msg, res.client.bytesRead);
} }
if (timingLog) {
emitTimingMetricLog(res.timings, msg);
}
} }
// Convert the payload to the required return type // Convert the payload to the required return type
@ -538,6 +546,9 @@ in your Node-RED user directory (${RED.settings.userDir}).
} }
msg.payload = err.toString() + " : " + url; msg.payload = err.toString() + " : " + url;
msg.statusCode = err.code || (err.response?err.response.statusCode:undefined); msg.statusCode = err.code || (err.response?err.response.statusCode:undefined);
if (node.metric() && timingLog) {
emitTimingMetricLog(err.timings, msg);
}
nodeSend(msg); nodeSend(msg);
nodeDone(); nodeDone();
}); });
@ -547,6 +558,28 @@ in your Node-RED user directory (${RED.settings.userDir}).
node.status({}); node.status({});
}); });
function emitTimingMetricLog(timings, msg) {
const props = [
"start",
"socket",
"lookup",
"connect",
"secureConnect",
"upload",
"response",
"end",
"error",
"abort"
];
if (timings) {
props.forEach(p => {
if (timings[p]) {
node.metric(`timings.${p}`, msg, timings[p]);
}
});
}
}
function extractCookies(setCookie) { function extractCookies(setCookie) {
var cookies = {}; var cookies = {};
setCookie.forEach(function(c) { setCookie.forEach(function(c) {