From 401466d6c0f59147a65f74cdc8188490f469f4f3 Mon Sep 17 00:00:00 2001 From: Kunihiko Toumura Date: Mon, 23 Aug 2021 11:54:05 +0900 Subject: [PATCH 1/2] Add timing log --- .../nodes/core/network/21-httprequest.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index c2d6d1d0f..dbf23463f 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -514,6 +514,7 @@ in your Node-RED user directory (${RED.settings.userDir}). if (res.client && res.client.bytesRead) { node.metric("size.bytes", msg, res.client.bytesRead); } + emitTimingMetricLog(res.timings, msg); } // Convert the payload to the required return type @@ -538,6 +539,9 @@ in your Node-RED user directory (${RED.settings.userDir}). } msg.payload = err.toString() + " : " + url; msg.statusCode = err.code || (err.response?err.response.statusCode:undefined); + if (node.metric()) { + emitTimingMetricLog(err.timings, msg); + } nodeSend(msg); nodeDone(); }); @@ -547,6 +551,28 @@ in your Node-RED user directory (${RED.settings.userDir}). 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) { var cookies = {}; setCookie.forEach(function(c) { From 490547cd3dfd622d85eda3cb2edd7e58be276cb9 Mon Sep 17 00:00:00 2001 From: Kunihiko Toumura Date: Sun, 5 Sep 2021 15:22:13 +0900 Subject: [PATCH 2/2] Use httpRequestTimingLog for enable detailed timing log --- .../@node-red/nodes/core/network/21-httprequest.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index dbf23463f..43d8ee42f 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -99,6 +99,11 @@ in your Node-RED user directory (${RED.settings.userDir}). noprox = proxyConfig.noproxy; } + let timingLog = false; + if (RED.settings.hasOwnProperty("httpRequestTimingLog")) { + timingLog = RED.settings.httpRequestTimingLog; + } + this.on("input",function(msg,nodeSend,nodeDone) { checkNodeAgentPatch(); //reset redirectList on each request @@ -514,7 +519,9 @@ in your Node-RED user directory (${RED.settings.userDir}). if (res.client && res.client.bytesRead) { node.metric("size.bytes", msg, res.client.bytesRead); } - emitTimingMetricLog(res.timings, msg); + if (timingLog) { + emitTimingMetricLog(res.timings, msg); + } } // Convert the payload to the required return type @@ -539,7 +546,7 @@ in your Node-RED user directory (${RED.settings.userDir}). } msg.payload = err.toString() + " : " + url; msg.statusCode = err.code || (err.response?err.response.statusCode:undefined); - if (node.metric()) { + if (node.metric() && timingLog) { emitTimingMetricLog(err.timings, msg); } nodeSend(msg);