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 3 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: reponse header about processing time (iotagent-node-lib#1650)
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 + ' ms ');
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 + ' ms ');
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