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

fix: enhance logging for request node #1463

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions packages/request-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"graphql-request": "6.1.0",
"http-shutdown": "1.2.2",
"http-status-codes": "2.1.4",
"morgan": "^1.10.0",
"shelljs": "0.8.5",
"tslib": "2.5.0",
"yargs": "17.6.2"
Expand All @@ -66,6 +67,7 @@
"@types/cors": "2.8.9",
"@types/express": "4.17.17",
"@types/jest": "29.5.6",
"@types/morgan": "^1.9.9",
"@types/node": "18.11.9",
"@types/supertest": "2.0.10",
"@types/yargs": "17.0.14",
Expand Down
20 changes: 17 additions & 3 deletions packages/request-node/src/request/ipfsAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default class IpfsAddHandler {

// Set the timeout from the value from config and convert seconds to milliseconds
/* eslint-disable no-magic-numbers */
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => {
this.logger.error('ipfs add timeout');
serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('ipfs add timeout');
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
});
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

// Verifies if data send from post are correct
// clientRequest.body is expected to contain data for data-acces layer:
Expand All @@ -48,12 +51,23 @@ export default class IpfsAddHandler {
JSON.stringify(clientRequest.body.data),
);

this.logger.debug(`ipfsAdd successfully completed`, ['metric', 'successRate']);
this.logger.debug(
`ipfsAdd successfully completed ${JSON.stringify({
ipfsHash: dataAccessResponse.ipfsHash,
ipfsSize: dataAccessResponse.ipfsSize,
})}`,
['metric', 'successRate'],
);
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

serverResponse.status(StatusCodes.OK).send(dataAccessResponse);
} catch (e) {
this.logger.error(`ipfsAdd error: ${e}`);
this.logger.debug(`ipfsAdd fail`, ['metric', 'successRate']);
this.logger.debug(
`ipfsAdd fail ${JSON.stringify({
data: clientRequest.body.data,
})}`,
['metric', 'successRate'],
);
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e);
}
Expand Down
24 changes: 21 additions & 3 deletions packages/request-node/src/request/persistTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default class PersistTransactionHandler {

// Set the timeout from the value from config and convert seconds to milliseconds
/* eslint-disable no-magic-numbers */
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => {
this.logger.error('persistTransaction timeout');
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('persistTransaction timeout');
});
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

// Verifies if data send from post are correct
// clientRequest.body is expected to contain data for data-acces layer:
Expand Down Expand Up @@ -83,12 +86,27 @@ export default class PersistTransactionHandler {
)}`);
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
});

this.logger.debug(`persistTransaction successfully completed`, ['metric', 'successRate']);
this.logger.debug(
`persistTransaction successfully completed ${JSON.stringify({
transactionHash,
channelId: clientRequest.body.channelId,
topics: clientRequest.body.topics,
transactionData: clientRequest.body.transactionData,
})}`,
['metric', 'successRate'],
);
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

serverResponse.status(StatusCodes.OK).send(dataAccessResponse);
} catch (e) {
this.logger.error(`persistTransaction error: ${e}`);
this.logger.debug(`persistTransaction fail`, ['metric', 'successRate']);
this.logger.debug(
`persistTransaction fail ${JSON.stringify({
channelId: clientRequest.body.channelId,
topics: clientRequest.body.topics,
transactionData: clientRequest.body.transactionData,
})}`,
['metric', 'successRate'],
);
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/request-node/src/requestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PersistTransactionHandler from './request/persistTransaction';
import GetChannelsByTopicHandler from './request/getChannelsByTopic';
import GetStatusHandler from './request/getStatus';
import IpfsAddHandler from './request/ipfsAdd';
import morgan from 'morgan';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json');
Expand Down Expand Up @@ -133,6 +134,9 @@ export class RequestNode {
// Enable all CORS requests
this.express.use(cors());

// Enable logging of all requests
this.express.use(morgan('combined'));
rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved

rodrigopavezi marked this conversation as resolved.
Show resolved Hide resolved
// Set the Request Node version to the header
this.express.use((_, res, next) => {
res.header(REQUEST_NODE_VERSION_HEADER, this.requestNodeVersion);
Expand Down
11 changes: 9 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5319,6 +5319,13 @@
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.3.tgz"
integrity sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==

"@types/morgan@^1.9.9":
version "1.9.9"
resolved "https://registry.yarnpkg.com/@types/morgan/-/morgan-1.9.9.tgz#d60dec3979e16c203a000159daa07d3fb7270d7f"
integrity sha512-iRYSDKVaC6FkGSpEVVIvrRGw0DfJMiQzIn3qr2G5B3C//AWkulhXgaBd7tS9/J79GWSYMTHGs7PfI5b3Y8m+RQ==
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "0.5.0"
resolved "https://registry.npmjs.org/@types/multicoin-address-validator/-/multicoin-address-validator-0.5.0.tgz"
Expand Down Expand Up @@ -16876,9 +16883,9 @@ module-error@^1.0.1, module-error@^1.0.2:
resolved "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz"
integrity sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==

morgan@^1.9.1:
morgan@^1.10.0, morgan@^1.9.1:
version "1.10.0"
resolved "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
integrity sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==
dependencies:
basic-auth "~2.0.1"
Expand Down
Loading