From a557e278bd4dc1aaca8b052bb3575df536f0a774 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 15:14:07 +0200 Subject: [PATCH 1/9] add_response_header_procesing_time --- CHANGES_NEXT_RELEASE | 2 +- Changelog | 2 ++ lib/bindings/HTTPBindings.js | 8 ++++++++ lib/constants.js | 4 +++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d3f5a12f..3a7b7bcb 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ - +- ADD: reponse header about procesing time (iotagent-node-lib#1650) diff --git a/Changelog b/Changelog index 905a4720..9584183c 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +- ADD: reponse header about procesing time (iotagent-node-lib#1650) + 3.6.0 (September 18th, 2024) - Upgrade express from 4.19.2 to 4.20.0 due to a vulnerability diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index 44f1f11b..654f264f 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -46,6 +46,11 @@ let context = { op: 'IOTAUL.HTTP.Binding' }; +function reqTiming(req, res, next) { + req.startTime = Date.now(); + next(); +} + /* eslint-disable-next-line no-unused-vars */ function handleError(error, req, res, next) { let code = 500; @@ -198,6 +203,7 @@ function returnCommands(req, res, next) { if (req.query && req.query.getCmd === '1') { iotAgentLib.commandQueue(req.device.service, req.device.subservice, req.deviceId, function (error, list) { + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); if (error || !list || list.count === 0) { res.set('Content-Type', 'text/plain'); res.status(200).send(''); @@ -209,6 +215,7 @@ function returnCommands(req, res, next) { }); } else { res.set('Content-Type', 'text/plain'); + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); res.status(200).send(''); } } @@ -477,6 +484,7 @@ function start(callback) { httpBindingServer.app.set('port', config.getConfig().http.port); httpBindingServer.app.set('host', config.getConfig().http.host || '0.0.0.0'); + httpBindingServer.app.use(reqTiming); httpBindingServer.router.get( config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH, diff --git a/lib/constants.js b/lib/constants.js index d299b870..dee1d4f0 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -53,5 +53,7 @@ module.exports = { AMQP_DEFAULT_QUEUE: 'iotaqueue', AMQP_DEFAULT_DURABLE: true, AMQP_DEFAULT_RETRIES: 5, - AMQP_DEFAULT_RETRY_TIME: 5 + AMQP_DEFAULT_RETRY_TIME: 5, + + X_PROCESSING_TIME: 'X-Processing-Time' }; From 36e065c9575efda743e0578fbae7bd6ad94b2ad9 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 15:36:54 +0200 Subject: [PATCH 2/9] Update Changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fermín Galán Márquez --- Changelog | 2 -- 1 file changed, 2 deletions(-) diff --git a/Changelog b/Changelog index 9584183c..905a4720 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,3 @@ -- ADD: reponse header about procesing time (iotagent-node-lib#1650) - 3.6.0 (September 18th, 2024) - Upgrade express from 4.19.2 to 4.20.0 due to a vulnerability From a4699ed7fa0ba6b06ee7c9d1a678bfc91ced1515 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 15:37:36 +0200 Subject: [PATCH 3/9] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 3a7b7bcb..d3742e32 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- ADD: reponse header about procesing time (iotagent-node-lib#1650) +- ADD: reponse header about processing time (iotagent-node-lib#1650) From 32b21d2a3b559e18715aca35eea474b068a48457 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 24 Sep 2024 09:28:19 +0200 Subject: [PATCH 4/9] add doc --- docs/usermanual.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/usermanual.md b/docs/usermanual.md index e7f335fa..36f21779 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -30,14 +30,15 @@ t|15|k|abc In this example, two attributes, one named "t" with value "15" and another named "k" with value "abc" are transmitted. Values in Ultralight 2.0 are not typed (everything is treated as a string). -Multiple groups of measures can be combined into a single request (but just for HTTP/POST or MQTT), using the `#` character. In that case, a different -NGSI request will be generated for each group of measures. E.g.: +Multiple groups of measures can be combined into a single request (but just for HTTP/POST or MQTT), using the `#` +character. In that case, a different NGSI request will be generated for each group of measures. E.g.: ```text gps|1.2/3.4#t|10 ``` -This will generate two elements in the NGSI batch update request (POST /v2/op/update) for the same entity, one for each one of the measures. Each one of those elements can contain any number of attributes. +This will generate two elements in the NGSI batch update request (POST /v2/op/update) for the same entity, one for each +one of the measures. Each one of those elements can contain any number of attributes. Measure groups can additionally have an optional timestamp, with the following syntax: @@ -291,6 +292,11 @@ Content-type: text/plain Robot1@turn|left ``` +##### Time processing + +HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current HTTP measure +request. + #### MQTT binding MQTT is a machine-to-machine (M2M)/IoT connectivity protocol, focused on a lightweight interaction between peers. MQTT From 6fbd798d0f800515fd6260413a2dd0a31d1e2176 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:31:44 +0200 Subject: [PATCH 5/9] Update usermanual.md --- docs/usermanual.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/usermanual.md b/docs/usermanual.md index 36f21779..0e344e28 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -294,8 +294,11 @@ Robot1@turn|left ##### Time processing -HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current HTTP measure -request. +HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time (in milliseconds) expended by current HTTP measure +request. For example: +``` +X-Processing-Time: 38 ms +``` #### MQTT binding From 537ea76221333fe7e1da0379525f23ace6f765b9 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:39:29 +0200 Subject: [PATCH 6/9] Update usermanual.md --- docs/usermanual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usermanual.md b/docs/usermanual.md index 0e344e28..f2a415a1 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -297,7 +297,7 @@ Robot1@turn|left HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time (in milliseconds) expended by current HTTP measure request. For example: ``` -X-Processing-Time: 38 ms +X-Processing-Time: 38 ``` #### MQTT binding From 4f523b1f0ca0a0e5094b4cee0ea88378548a06ff Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:40:39 +0200 Subject: [PATCH 7/9] Update HTTPBindings.js --- lib/bindings/HTTPBindings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index 654f264f..bbfeb4d5 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -203,7 +203,7 @@ function returnCommands(req, res, next) { if (req.query && req.query.getCmd === '1') { iotAgentLib.commandQueue(req.device.service, req.device.subservice, req.deviceId, function (error, list) { - res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime); if (error || !list || list.count === 0) { res.set('Content-Type', 'text/plain'); res.status(200).send(''); @@ -215,7 +215,7 @@ function returnCommands(req, res, next) { }); } else { res.set('Content-Type', 'text/plain'); - res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime); res.status(200).send(''); } } From 5f541cbcfe71a1cca18cb18849bb2ce99ffeebdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 27 Sep 2024 09:53:10 +0200 Subject: [PATCH 8/9] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d3742e32..842288fb 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- ADD: reponse header about processing time (iotagent-node-lib#1650) +- Add: reponse header about processing time (iotagent-node-lib#1650) From 02edb8569e870f391e29973dc881a0a8010fdaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 27 Sep 2024 13:22:34 +0200 Subject: [PATCH 9/9] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 842288fb..89a93372 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- Add: reponse header about processing time (iotagent-node-lib#1650) +- Add: X-Processing-Time response header with processing time (in milliseconds) expended by current HTTP measure (iotagent-node-lib#1650)