Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 91
fix: enhance logging for request node#1463
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5ee006f2436a4f435fb26cda06dff6da6d696ccf7eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| @@ -66,6 +67,7 @@ | ||
| "@types/cors": "2.8.9", | ||
| "@types/express": "4.17.17", | ||
| "@types/jest": "29.5.6", | ||
| "@types/morgan": "1.9.9", | ||
rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "@types/node": "18.11.9", | ||
| "@types/supertest": "2.0.10", | ||
| "@types/yargs": "17.0.14", | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,10 +24,6 @@ export default class IpfsAddHandler { | ||
| // Retrieves data access layer | ||
| let dataAccessResponse; | ||
| // Set the timeout from the value from config and convert seconds to milliseconds | ||
| /* eslint-disable no-magic-numbers */ | ||
| clientRequest.setTimeout(getPersistTransactionTimeout() * 1000); | ||
| // Verifies if data send from post are correct | ||
| // clientRequest.body is expected to contain data for data-acces layer: | ||
| // transactionData: data of the transaction | ||
| @@ -43,17 +39,36 @@ export default class IpfsAddHandler { | ||
| return; | ||
| } | ||
| // Set the timeout from the value from config and convert seconds to milliseconds | ||
| /* eslint-disable no-magic-numbers */ | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => { | ||
| this.logger.error(`ipfsAdd timeout. clientRequest.body.data: ${clientRequest.body.data}`, [ | ||
| 'timeout', | ||
| ]); | ||
| serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('ipfsAdd timeout'); | ||
| }); | ||
| try { | ||
| dataAccessResponse = await this.ipfsStorage.ipfsAdd( | ||
| 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.
Uh oh!There was an error while loading. Please reload this page. rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| serverResponse.status(StatusCodes.OK).send(dataAccessResponse); | ||
| } catch (e) { | ||
| this.logger.error(`ipfsAdd error: ${e}`); | ||
| this.logger.debug(`ipfsAdd fail`, ['metric', 'successRate']); | ||
| this.logger.error( | ||
| `ipfsAdd fail ${JSON.stringify({ | ||
| error: e, | ||
| data: clientRequest.body.data, | ||
| })}`, | ||
| ); | ||
rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,10 +30,6 @@ export default class PersistTransactionHandler { | ||
| // Retrieves data access layer | ||
| let dataAccessResponse: DataAccessTypes.IReturnPersistTransaction; | ||
| // Set the timeout from the value from config and convert seconds to milliseconds | ||
| /* eslint-disable no-magic-numbers */ | ||
| clientRequest.setTimeout(getPersistTransactionTimeout() * 1000); | ||
| // Verifies if data send from post are correct | ||
| // clientRequest.body is expected to contain data for data-acces layer: | ||
| // transactionData: data of the transaction | ||
| @@ -46,11 +42,25 @@ export default class PersistTransactionHandler { | ||
| serverResponse.status(StatusCodes.UNPROCESSABLE_ENTITY).send('Incorrect data'); | ||
| return; | ||
| } | ||
| try { | ||
| const transactionHash: MultiFormatTypes.HashTypes.IHash = normalizeKeccak256Hash( | ||
| clientRequest.body.transactionData, | ||
| const transactionHash: MultiFormatTypes.HashTypes.IHash = normalizeKeccak256Hash( | ||
| clientRequest.body.transactionData, | ||
rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Set the timeout from the value from config and convert seconds to milliseconds | ||
| /* eslint-disable no-magic-numbers */ | ||
| clientRequest.setTimeout(getPersistTransactionTimeout() * 1000, () => { | ||
| this.logger.error( | ||
| `persistTransaction timeout ${JSON.stringify({ | ||
| transactionHash, | ||
| channelId: clientRequest.body.channelId, | ||
| })}`, | ||
| ['timeout'], | ||
| ); | ||
| serverResponse.status(StatusCodes.GATEWAY_TIMEOUT).send('persistTransaction timeout'); | ||
| }); | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| try { | ||
| this.logger.debug( | ||
| `Persisting Transaction: ${JSON.stringify({ | ||
| transactionHash, | ||
| @@ -67,10 +77,13 @@ export default class PersistTransactionHandler { | ||
| ); | ||
| dataAccessResponse.on('confirmed', async () => { | ||
| this.logger.info(`Transaction confirmed: ${transactionHash.value}`, [ | ||
| 'metric', | ||
| 'successRate', | ||
| ]); | ||
| this.logger.info( | ||
| `Transaction confirmed: ${JSON.stringify({ | ||
| transactionHash, | ||
| channelId: clientRequest.body.channelId, | ||
| })}`, | ||
| ['metric', 'successRate'], | ||
| ); | ||
| }); | ||
| // when the transaction fails, log an error | ||
| @@ -83,12 +96,25 @@ export default class PersistTransactionHandler { | ||
| )}`); | ||
rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| this.logger.debug(`persistTransaction successfully completed`, ['metric', 'successRate']); | ||
| this.logger.debug( | ||
| `persistTransaction successfully completed ${JSON.stringify({ | ||
| transactionHash, | ||
| channelId: clientRequest.body.channelId, | ||
| })}`, | ||
| ['metric', 'successRate'], | ||
| ); | ||
| serverResponse.status(StatusCodes.OK).send(dataAccessResponse); | ||
| } catch (e) { | ||
| this.logger.error(`persistTransaction error: ${e}`); | ||
| this.logger.debug(`persistTransaction fail`, ['metric', 'successRate']); | ||
| this.logger.error( | ||
| `persistTransaction fail ${JSON.stringify({ | ||
| error: e, | ||
| transactionHash, | ||
| channelId: clientRequest.body.channelId, | ||
| topics: clientRequest.body.topics, | ||
| transactionData: clientRequest.body.transactionData, | ||
| })}`, | ||
| ); | ||
MantisClone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| serverResponse.status(StatusCodes.INTERNAL_SERVER_ERROR).send(e); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'); | ||
| @@ -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.
Uh oh!There was an error while loading. Please reload this page. | ||
rodrigopavezi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Set the Request Node version to the header | ||
| this.express.use((_, res, next) => { | ||
| res.header(REQUEST_NODE_VERSION_HEADER, this.requestNodeVersion); | ||
Uh oh!
There was an error while loading. Please reload this page.