From 7f6ddd18efec5f2beaa7c55d58f4cbbd58301a54 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 11:52:34 +0200 Subject: [PATCH 01/11] add response time procesing header --- lib/bindings/HTTPBinding.js | 12 +++++++++++- lib/constants.js | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/bindings/HTTPBinding.js b/lib/bindings/HTTPBinding.js index 770f07c9c..a783e2fee 100644 --- a/lib/bindings/HTTPBinding.js +++ b/lib/bindings/HTTPBinding.js @@ -454,6 +454,7 @@ function sendConfigurationToDevice(apiKey, group, deviceId, results, callback) { function handleConfigurationRequest(req, res, next) { function replyToDevice(error) { + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); if (error) { res.status(error.code).json(error); } else { @@ -476,6 +477,11 @@ function handleConfigurationRequest(req, res, next) { }); } +function reqTiming(req, res, next) { + req.startTime = Date.now(); + next(); +} + function handleError(error, req, res, next) { let code = 500; @@ -484,7 +490,7 @@ function handleError(error, req, res, next) { if (error.code && String(error.code).match(/^[2345]\d\d$/)) { code = error.code; } - + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); res.status(code).json({ name: error.name, message: error.message @@ -623,6 +629,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) { if (req.accepts('json')) { res.status(200).send({}); @@ -639,8 +646,10 @@ function returnCommands(req, res, next) { } }); } else if (req.accepts('json')) { + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); res.status(200).send({}); } else { + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); res.status(200).send(''); } } @@ -664,6 +673,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 f0abf0886..3698b139a 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -58,5 +58,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 3761e1eaf024bedc312e304d55f0e1d421725762 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 12:40:27 +0200 Subject: [PATCH 02/11] update CNR --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 41ab70250..082f7dd86 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 body-parser dep from 1.20.0 to 1.20.3 From 72e77f025aab8b297a9776917991b26c83171f10 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Sep 2024 15:38:01 +0200 Subject: [PATCH 03/11] Update Changelog --- Changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 082f7dd86..8f03d90f9 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,4 @@ -- ADD: reponse header about procesing time (iotagent-node-lib#1650) +- ADD: reponse header about processing time (iotagent-node-lib#1650) 3.6.0 (September 18th, 2024) From 409cd332ae4b8012847792405197c1669c7c39fa Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 24 Sep 2024 09:20:59 +0200 Subject: [PATCH 04/11] update CNR and doc --- CHANGES_NEXT_RELEASE | 2 +- Changelog | 2 -- docs/usermanual.md | 33 ++++++++++++++++++++------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d3f5a12fa..bf8aa8394 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ - +- ADD: response header about procesing time in measures request(iotagent-node-lib#1650) diff --git a/Changelog b/Changelog index 8f03d90f9..41ab70250 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,3 @@ -- ADD: reponse header about processing time (iotagent-node-lib#1650) - 3.6.0 (September 18th, 2024) - Upgrade body-parser dep from 1.20.0 to 1.20.3 diff --git a/docs/usermanual.md b/docs/usermanual.md index 36b90aa6e..aa24cae61 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -118,19 +118,22 @@ It is possible to report as a measure a NGSI-v2 or NGSI-LD payload when related `payloadType` `ngsiv2` or `ngsild`. In these cases payload is ingested as measure where entity attributes are measure attributes. -Note that the entity ID and type in the measure are also include as attributes `measure_id` and `measure_type` as described -[here](https://github.dev/telefonicaid/iotagent-node-lib/doc/api.md#special-measures-and-attributes-names) (both using -attribute type `Text`). The ID and type of the entity updated at Context Broker is taken from device/group configuration or provision, +Note that the entity ID and type in the measure are also include as attributes `measure_id` and `measure_type` as +described [here](https://github.dev/telefonicaid/iotagent-node-lib/doc/api.md#special-measures-and-attributes-names) +(both using attribute type `Text`). The ID and type of the entity updated at Context Broker is taken from device/group +configuration or provision, -However, it is possible to use the same entity ID that the original one by using `entityNameExp` -at [device group provision](https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/api.md#config-group-datamodel), this way: +However, it is possible to use the same entity ID that the original one by using `entityNameExp` at +[device group provision](https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/api.md#config-group-datamodel), +this way: ``` "entityNameExp": "measure_id" ``` -The `actionType` used in the update sent to Context Broker is taken from the measure in the case that measure corresponds to -a NGSI-v2 batch update. In other cases (i.e. NGSI-LD or NGSI-v2 non-batch update), the `actionType` is the default one (`append`). +The `actionType` used in the update sent to Context Broker is taken from the measure in the case that measure +corresponds to a NGSI-v2 batch update. In other cases (i.e. NGSI-LD or NGSI-v2 non-batch update), the `actionType` is +the default one (`append`). For instance, given an incoming **measure** as the follwing one: @@ -138,7 +141,7 @@ For instance, given an incoming **measure** as the follwing one: { "id": "MyEntityId1", "type": "MyEntityType1", - "attr1": { "type": "Text", "value": "MyAttr1Value"} + "attr1": { "type": "Text", "value": "MyAttr1Value" } } ``` @@ -146,11 +149,11 @@ It would persist an entity into the Context Broker like the following one: ```json { - "id":"MyProvisionID", - "type":"MyProvisionType", - "attr1": { "type": "Text", "value": "MyAttr1Value"}, - "measure_id": {"type": "Text","value": "MyEntityId1"}, - "measure_type":{"type": "Text","value": "MyEntityType1"} + "id": "MyProvisionID", + "type": "MyProvisionType", + "attr1": { "type": "Text", "value": "MyAttr1Value" }, + "measure_id": { "type": "Text", "value": "MyEntityId1" }, + "measure_type": { "type": "Text", "value": "MyEntityType1" } } ``` @@ -521,6 +524,10 @@ Content-type: application/json } ``` +#### Time processing + +HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current request. + ### MQTT binding MQTT binding is based on the existence of a MQTT broker and the usage of different topics to separate the different From ddb4c2ffe178214848323380185ccecf395d352c Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 24 Sep 2024 09:25:27 +0200 Subject: [PATCH 05/11] update doc --- docs/usermanual.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/usermanual.md b/docs/usermanual.md index aa24cae61..d879c0a30 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -526,7 +526,8 @@ Content-type: application/json #### Time processing -HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current request. +HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current HTTP measure +request. ### MQTT binding From a0d8345a405d2ab6fba4f1721840ae157e107625 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:25:52 +0200 Subject: [PATCH 06/11] Update CHANGES_NEXT_RELEASE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fermín Galán Márquez --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index bf8aa8394..cfb789093 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- ADD: response header about procesing time in measures request(iotagent-node-lib#1650) +- Add: response header about procesing time in measures request (iotagent-node-lib#1650) From 4e05442043b5b7f3634aa963b8e7af6f8bd873bf Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:28:09 +0200 Subject: [PATCH 07/11] 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 d879c0a30..dc0fafa1a 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -526,7 +526,7 @@ Content-type: application/json #### Time processing -HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time expended by current HTTP measure +HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time (in milliseconds) expended by current HTTP measure request. ### MQTT binding From 55723528927edfbc88671ccb15621477414468d4 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:33:32 +0200 Subject: [PATCH 08/11] Update usermanual.md --- docs/usermanual.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/usermanual.md b/docs/usermanual.md index dc0fafa1a..11d20bc36 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -527,7 +527,10 @@ Content-type: application/json #### Time processing HTTP bindig is returning in a HTTP header named `X-Processing-Time` processing time (in milliseconds) expended by current HTTP measure -request. +request. For example +``` +X-Processing-Time: 38 ms +``` ### MQTT binding From 61d9f7e347c8a596829aa58871452a46fe7d57c7 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:36:19 +0200 Subject: [PATCH 09/11] 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 11d20bc36..083c4d2a9 100644 --- a/docs/usermanual.md +++ b/docs/usermanual.md @@ -529,7 +529,7 @@ Content-type: application/json 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 53b20db898d766348b7d1a5086916582345a5a6a Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 26 Sep 2024 13:38:15 +0200 Subject: [PATCH 10/11] Update HTTPBinding.js --- lib/bindings/HTTPBinding.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bindings/HTTPBinding.js b/lib/bindings/HTTPBinding.js index a783e2fee..bfb64b4ed 100644 --- a/lib/bindings/HTTPBinding.js +++ b/lib/bindings/HTTPBinding.js @@ -454,7 +454,7 @@ function sendConfigurationToDevice(apiKey, group, deviceId, results, callback) { function handleConfigurationRequest(req, res, next) { function replyToDevice(error) { - res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime); if (error) { res.status(error.code).json(error); } else { @@ -490,7 +490,7 @@ function handleError(error, req, res, next) { if (error.code && String(error.code).match(/^[2345]\d\d$/)) { code = error.code; } - res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime + ' ms '); + res.set(constants.X_PROCESSING_TIME, Date.now() - req.startTime); res.status(code).json({ name: error.name, message: error.message @@ -629,7 +629,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) { if (req.accepts('json')) { res.status(200).send({}); @@ -646,10 +646,10 @@ function returnCommands(req, res, next) { } }); } else if (req.accepts('json')) { - 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({}); } else { - 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 d7c26ea8166751717c91bf74acae122f3a2dec42 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:41 +0200 Subject: [PATCH 11/11] 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 cfb789093..89a933723 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- Add: response header about procesing time in measures request (iotagent-node-lib#1650) +- Add: X-Processing-Time response header with processing time (in milliseconds) expended by current HTTP measure (iotagent-node-lib#1650)