Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add response header about procesing time #685

Merged
merged 9 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is based in some existing (pseudo)standard? Or it has been fully invented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just a new invented header. But we can use other...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should do a little searching to check is there is something similar we can reuse or inspire on...

Copy link
Member Author

@AlvaroVega AlvaroVega Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe X-Process-Time matches better?

};
Loading