Skip to content

Commit

Permalink
Merge pull request #685 from telefonicaid/task/add_response_header_pr…
Browse files Browse the repository at this point in the history
…ocesing_time

add response header about procesing time
  • Loading branch information
fgalan authored Sep 27, 2024
2 parents fcc5c03 + 02edb85 commit e61e33a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add: X-Processing-Time response header with processing time (in milliseconds) expended by current HTTP measure (iotagent-node-lib#1650)
15 changes: 12 additions & 3 deletions docs/usermanual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -291,6 +292,14 @@ Content-type: text/plain
Robot1@turn|left
```

##### Time processing

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
```

#### MQTT binding

MQTT is a machine-to-machine (M2M)/IoT connectivity protocol, focused on a lightweight interaction between peers. MQTT
Expand Down
8 changes: 8 additions & 0 deletions lib/bindings/HTTPBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
if (error || !list || list.count === 0) {
res.set('Content-Type', 'text/plain');
res.status(200).send('');
Expand All @@ -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);
res.status(200).send('');
}
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

0 comments on commit e61e33a

Please sign in to comment.