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

feat(mojaloop/#3885): extend fxquote functionality to persistant mode #348

Merged
merged 11 commits into from
Aug 19, 2024

Conversation

kleyow
Copy link
Contributor

@kleyow kleyow commented Aug 17, 2024

No description provided.

try {
// calculate a SHA-256 of the request
const hash = calculateRequestHash(fxQuoteResponse)
this.log.debug(`Calculated sha256 hash of quote response with id ${conversionRequestId} as: ${hash}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just:

this.log.debug('Calculated sha256 hash of quote response:', { conversionRequestId, hash })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. here and throughout.

}
} catch (err) {
// internal-error
this.log.error(`Error in checkDuplicateFxQuoteResponse: ${getStackOrInspect(err)}`)
Copy link
Contributor

@geka-evk geka-evk Aug 19, 2024

Choose a reason for hiding this comment

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

this.log.error('Error in checkDuplicateFxQuoteResponse: ', err)

This way we'll log much more useful information about an error (e.g.: message, stack, code, cause):
https://github.com/mojaloop/central-services-logger/blob/master/src/contextLogger.js#L131

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. here and throughout

this.log.debug(`Calculated sha256 hash of quote response with id ${conversionRequestId} as: ${hash}`)

const dupchk = await this.db.getFxQuoteResponseDuplicateCheck(conversionRequestId)
this.log.debug(`DB query for quote response duplicate check with id ${conversionRequestId} returned: ${util.inspect(dupchk)}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

this.log.debug('DB query for fxQuote response duplicate check returned: ', { conversionRequestId,  dupchk }) 

Or we we don't want to repeat conversionRequestId in all logs across the the method, we can create a child logger an the beginning, and use it through the rest of the method code:

async checkDuplicateFxQuoteResponse (conversionRequestId, fxQuoteResponse) {
    const log = this.log.child({ conversionRequestId })
    try {
       ....
       log.debug('DB query for fxQuote response duplicate check returned: ', { dupchk }) 
       //  conversionRequestId will be added to logs output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -67,6 +67,14 @@
}
}
},
"PROXY_CACHE": {
"enabled": false,
"type": "redis",
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we use redis-cluster as it's default proxyCache type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me do that in a follow up PR. I didn't want to touch the int harness.

this.writeLog(`inserted new fxQuote in db: ${util.inspect(newFxQuote)}`)
return newFxQuote
} catch (err) {
this.writeLog(`Error in createFxQuote: ${getStackOrInspect(err)}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest stopping using this.writeLog to log error, coz it uses debug severity, so we won't have such logs in production

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. I overlooked this when merging in your changes.

this.log.debug(`DB query for quote duplicate check with id ${fxQuoteRequest.conversionRequestId} returned: ${util.inspect(dupchk)}`)

if (!dupchk) {
// no existing record for this quoteId found
Copy link
Contributor

@geka-evk geka-evk Aug 19, 2024

Choose a reason for hiding this comment

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

Personally, I prefer add log instead of such comment:

if (!dupchk) {
  this.log.info('no existing record for this quoteId found')
  return ...

so we'll have additional info in logs during debugging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

const envConfig = new Config()
if (!envConfig.simpleRoutingMode) {
// check if this is a resend or an erroneous duplicate
const dupe = await this.checkDuplicateFxQuoteRequest(fxQuoteRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

just wondering about naming: what is dupe?

Copy link
Contributor Author

@kleyow kleyow Aug 19, 2024

Choose a reason for hiding this comment

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

shorthand for an object that details whether a request id is a duplicate request and/or if a hash of the request has been seen before.

// any-error
// as we are on our own in this context, dont just rethrow the error, instead...
// get the model to handle it
this.log.error(`Error forwarding quote request: ${getStackOrInspect(err)}. Attempting to send error callback to ${fspiopSource}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can log just this part here:

   this.log.error('Error forwarding fxQuote request: ', err)

coz this.handleException() already logs the next info inside itself:

async handleException (...) {
  this.log.info('Attempting to send error callback to fspiopSource:', { conversionRequestId, fspiopSource })
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
11.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@kleyow kleyow marked this pull request as ready for review August 19, 2024 17:24
@kleyow kleyow merged commit 5d22d4d into feat/fx-impl Aug 19, 2024
9 of 10 checks passed
@kleyow kleyow deleted the chore/3885-fx-persistant branch August 19, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants