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: add error metrics #1140

Merged
merged 6 commits into from
Jan 8, 2025
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
Prev Previous commit
Next Next commit
chore: use lib
  • Loading branch information
kleyow committed Jan 6, 2025
commit 5caeac0817a7cc4722691172e743b6bd32104f85
25 changes: 12 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@mojaloop/central-services-health": "15.0.0",
"@mojaloop/central-services-logger": "11.5.1",
"@mojaloop/central-services-metrics": "12.4.2",
"@mojaloop/central-services-shared": "18.14.2",
"@mojaloop/central-services-shared": "18.15.0-snapshot.1",
"@mojaloop/central-services-stream": "11.4.1",
"@mojaloop/database-lib": "11.1.0",
"@mojaloop/event-sdk": "14.1.1",
Expand Down
5 changes: 2 additions & 3 deletions src/api/ledgerAccountTypes/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

const LedgerAccountTypesService = require('../../domain/ledgerAccountTypes')
const ErrorHandler = require('@mojaloop/central-services-error-handling')

const util = require('../../lib/util')
const { rethrow } = require('@mojaloop/central-services-shared').Util

const getAll = async function () {
return LedgerAccountTypesService.getAll()
Expand All @@ -43,7 +42,7 @@ async function create (request, h) {
return h.response().code(201)
}
} catch (err) {
util.rethrowFspiopError(err, 'ledgerAccountTypesCreate')
rethrow.rethrowAndCountFspiopError(err, { operation: 'ledgerAccountTypesCreate' })
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/api/participants/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Logger = require('@mojaloop/central-services-logger')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const Enums = require('../../lib/enumCached')
const SettlementService = require('../../domain/settlement')
const util = require('../../lib/util')
const { rethrow } = Util

const LocalEnum = {
activated: 'activated',
Expand Down Expand Up @@ -108,7 +108,7 @@ const create = async function (request, h) {
}
return h.response(entityItem(participant, ledgerAccountIds)).code(201)
} catch (err) {
util.rethrowFspiopError(err, 'participantCreate')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantCreate' })
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ const createHubAccount = async function (request, h) {
const ledgerAccountIds = Util.transpose(ledgerAccountTypes)
return h.response(entityItem(participant, ledgerAccountIds)).code(201)
} catch (err) {
util.rethrowFspiopError(err, 'participantCreateHubAccount')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantCreateHubAccount' })
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ const update = async function (request) {
const ledgerAccountIds = Util.transpose(ledgerAccountTypes)
return entityItem(updatedEntity, ledgerAccountIds)
} catch (err) {
util.rethrowFspiopError(err, 'participantUpdate')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantUpdate' })
}
}

Expand All @@ -195,7 +195,7 @@ const addEndpoint = async function (request, h) {
await ParticipantService.addEndpoint(request.params.name, request.payload)
return h.response().code(201)
} catch (err) {
util.rethrowFspiopError(err, 'participantAddEndpoint')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAddEndpoint' })
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ const getEndpoint = async function (request) {
return endpoints
}
} catch (err) {
util.rethrowFspiopError(err, 'participantGetEndpoint')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetEndpoint' })
}
}

Expand All @@ -234,7 +234,7 @@ const addLimitAndInitialPosition = async function (request, h) {
await ParticipantService.addLimitAndInitialPosition(request.params.name, request.payload)
return h.response().code(201)
} catch (err) {
util.rethrowFspiopError(err, 'participantAddLimitAndInitialPosition')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAddLimitAndInitialPosition' })
}
}

Expand All @@ -256,7 +256,7 @@ const getLimits = async function (request) {
}
return limits
} catch (err) {
util.rethrowFspiopError(err, 'participantGetLimits')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetLimits' })
}
}

Expand All @@ -279,7 +279,7 @@ const getLimitsForAllParticipants = async function (request) {
}
return limits
} catch (err) {
util.rethrowFspiopError(err, ' participantGetLimitsForAllParticipants')
rethrow.rethrowAndCountFspiopError(err, { operation: ' participantGetLimitsForAllParticipants' })
}
}

Expand All @@ -298,23 +298,23 @@ const adjustLimits = async function (request, h) {
}
return h.response(updatedLimit).code(200)
} catch (err) {
util.rethrowFspiopError(err, 'participantAdjustLimits')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantAdjustLimits' })
}
}

const getPositions = async function (request) {
try {
return await ParticipantService.getPositions(request.params.name, request.query)
} catch (err) {
util.rethrowFspiopError(err, 'participantGetPositions')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetPositions' })
}
}

const getAccounts = async function (request) {
try {
return await ParticipantService.getAccounts(request.params.name, request.query)
} catch (err) {
util.rethrowFspiopError(err, 'participantGetAccounts')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantGetAccounts' })
}
}

Expand All @@ -331,7 +331,7 @@ const updateAccount = async function (request, h) {
}
return h.response().code(200)
} catch (err) {
util.rethrowFspiopError(err, 'participantUpdateAccount')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantUpdateAccount' })
}
}

Expand All @@ -341,7 +341,7 @@ const recordFunds = async function (request, h) {
await ParticipantService.recordFundsInOut(request.payload, request.params, enums)
return h.response().code(202)
} catch (err) {
util.rethrowFspiopError(err, 'participantRecordFunds')
rethrow.rethrowAndCountFspiopError(err, { operation: 'participantRecordFunds' })
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/api/settlementModels/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const Enums = require('../../lib/enumCached')
const Util = require('@mojaloop/central-services-shared').Util
const Enum = require('@mojaloop/central-services-shared').Enum.Settlements
const Logger = require('@mojaloop/central-services-logger')

const util = require('../../lib/util')
const { rethrow } = Util

const entityItem = ({ settlementModelId, name, isActive, settlementGranularityId, settlementInterchangeId, settlementDelayId, currencyId, requireLiquidityCheck, ledgerAccountTypeId, autoPositionReset }, ledgerAccountIds, settlementGranularityIds, settlementInterchangeIds, settlementDelayIds) => {
return {
Expand Down Expand Up @@ -92,15 +91,15 @@ const update = async function (request) {
const settlementDelayIds = Util.transpose(Enum.SettlementDelay)
return entityItem(updatedEntity, ledgerAccountIds, settlementGranularityIds, settlementInterchangeIds, settlementDelayIds)
} catch (err) {
util.rethrowFspiopError(err, 'settlementModelUpdate')
rethrow.rethrowAndCountFspiopError(err, { operation: 'settlementModelUpdate' })
}
}
const create = async function (request, h) {
try {
await SettlementService.createSettlementModel(request.payload)
return h.response().code(201)
} catch (err) {
util.rethrowFspiopError(err, 'settlementModelCreate')
rethrow.rethrowAndCountFspiopError(err, { operation: 'settlementModelCreate' })
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/transactions/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
'use strict'

const ErrorHandler = require('@mojaloop/central-services-error-handling')
const { rethrow } = require('@mojaloop/central-services-shared').Util

const Transaction = require('../../domain/transactions')
const util = require('../../lib/util')

const getById = async function (request) {
try {
Expand All @@ -37,7 +37,7 @@ const getById = async function (request) {
}
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, 'The requested resource could not be found.')
} catch (err) {
util.rethrowFspiopError(err, 'transactionsGetById')
rethrow.rethrowAndCountFspiopError(err, { operation: 'transactionsGetById' })
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/handlers/admin/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Db = require('../../lib/db')
const httpPostRelatedActions = [Enum.Events.Event.Action.RECORD_FUNDS_IN, Enum.Events.Event.Action.RECORD_FUNDS_OUT_PREPARE_RESERVE]
const httpPutRelatedActions = [Enum.Events.Event.Action.RECORD_FUNDS_OUT_COMMIT, Enum.Events.Event.Action.RECORD_FUNDS_OUT_ABORT]
const allowedActions = [].concat(httpPostRelatedActions).concat(httpPutRelatedActions)
const util = require('../../lib/util')
const { rethrow } = require('@mojaloop/central-services-shared').Util

const createRecordFundsInOut = async (payload, transactionTimestamp, enums) => {
/** @namespace Db.getKnex **/
Expand All @@ -64,7 +64,7 @@ const createRecordFundsInOut = async (payload, transactionTimestamp, enums) => {
await TransferService.reconciliationTransferPrepare(payload, transactionTimestamp, enums, trx)
await TransferService.reconciliationTransferReserve(payload, transactionTimestamp, enums, trx)
} catch (err) {
util.rethrowFspiopError(err, 'adminCreateRecordFundsInOut')
rethrow.rethrowAndCountFspiopError(err, { operation: 'adminCreateRecordFundsInOut' })
}
})
}
Expand Down Expand Up @@ -114,7 +114,7 @@ const transferExists = async (payload, transferId) => {

const transfer = async (error, messages) => {
if (error) {
util.rethrowFspiopError(error, 'adminTransfer')
rethrow.rethrowAndCountFspiopError(error, { operation: 'adminTransfer' })
}
let message = {}
try {
Expand Down Expand Up @@ -158,7 +158,7 @@ const transfer = async (error, messages) => {
await Kafka.commitMessageSync(Consumer, kafkaTopic, message)
return true
} catch (err) {
util.rethrowFspiopError(err, 'adminTransfer')
rethrow.rethrowAndCountFspiopError(err, { operation: 'adminTransfer' })
}
}

Expand All @@ -181,7 +181,7 @@ const registerTransferHandler = async () => {
await Consumer.createHandler(transferHandler.topicName, transferHandler.config, transferHandler.command)
return true
} catch (err) {
util.rethrowFspiopError(err, 'registerTransferHandler')
rethrow.rethrowAndCountFspiopError(err, { operation: 'registerTransferHandler' })
}
}

Expand All @@ -198,7 +198,7 @@ const registerAllHandlers = async () => {
await registerTransferHandler()
return true
} catch (err) {
util.rethrowFspiopError(err, 'registerAllHandlers')
rethrow.rethrowAndCountFspiopError(err, { operation: 'registerAllHandlers' })
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/handlers/bulk/fulfil/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const BulkTransferModels = require('@mojaloop/object-store-lib').Models.BulkTran
const encodePayload = require('@mojaloop/central-services-shared').Util.StreamingProtocol.encodePayload
const Comparators = require('@mojaloop/central-services-shared').Util.Comparators
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const util = require('../../../lib/util')
const location = { module: 'BulkFulfilHandler', method: '', path: '' } // var object used as pointer

const location = { module: 'BulkFulfilHandler', method: '', path: '' } // var object used as pointer
const { rethrow } = Util
const consumerCommit = true
const fromSwitch = true

Expand Down Expand Up @@ -110,7 +110,7 @@ const bulkFulfil = async (error, messages) => {
const fspiopError = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.MODIFIED_REQUEST)
const eventDetail = { functionality: Enum.Events.Event.Type.NOTIFICATION, action }
await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, fspiopError: fspiopError.toApiErrorObject(Config.ERROR_HANDLING), eventDetail, fromSwitch, hubName: Config.HUB_NAME })
util.rethrowFspiopError(fspiopError, 'bulkFulfil')
rethrow.rethrowAndCountFspiopError(fspiopError, { operation: 'bulkFulfil' })
}

// TODO: move FSPIOP-Source validation before Transfer Duplicate Check to accept only Payee's first request
Expand All @@ -134,7 +134,7 @@ const bulkFulfil = async (error, messages) => {
params.message.value.content.uriParams = { id: bulkTransferId }

await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, fspiopError: fspiopError.toApiErrorObject(Config.ERROR_HANDLING), eventDetail, fromSwitch, hubName: Config.HUB_NAME })
util.rethrowFspiopError(fspiopError, 'bulkFulfil')
rethrow.rethrowAndCountFspiopError(fspiopError, { operation: 'bulkFulfil' })
}
try {
Logger.isInfoEnabled && Logger.info(Util.breadcrumb(location, 'individualTransferFulfils'))
Expand Down Expand Up @@ -240,20 +240,20 @@ const bulkFulfil = async (error, messages) => {
params.message.value.content.uriParams = { id: bulkTransferId }

await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, fspiopError: fspiopError.toApiErrorObject(Config.ERROR_HANDLING), eventDetail, fromSwitch, hubName: Config.HUB_NAME })
util.rethrowFspiopError(fspiopError, 'bulkFulfil')
rethrow.rethrowAndCountFspiopError(fspiopError, { operation: 'bulkFulfil' })
}
Logger.isInfoEnabled && Logger.info(Util.breadcrumb(location, `callbackErrorGeneric--${actionLetter}8`))

const eventDetail = { functionality: Enum.Events.Event.Type.NOTIFICATION, action }
params.message.value.content.uriParams = { id: bulkTransferId }

await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, fspiopError: validationFspiopError.toApiErrorObject(Config.ERROR_HANDLING), eventDetail, fromSwitch, hubName: Config.HUB_NAME })
util.rethrowFspiopError(validationFspiopError, 'bulkFulfil')
rethrow.rethrowAndCountFspiopError(validationFspiopError, { operation: 'bulkFulfil' })
}
} catch (err) {
Logger.isErrorEnabled && Logger.error(`${Util.breadcrumb(location)}::${err.message}--BP0`)
histTimerEnd({ success: false, fspId: Config.INSTRUMENTATION_METRICS_LABELS.fspId })
util.rethrowFspiopError(err, 'bulkFulfil')
rethrow.rethrowAndCountFspiopError(err, { operation: 'bulkFulfil' })
}
}

Expand Down Expand Up @@ -319,7 +319,7 @@ const registerBulkFulfilHandler = async () => {
await Consumer.createHandler(bulkFulfilHandler.topicName, bulkFulfilHandler.config, bulkFulfilHandler.command)
return true
} catch (err) {
util.rethrowFspiopError(err, 'registerBulkFulfilHandler')
rethrow.rethrowAndCountFspiopError(err, { operation: 'registerBulkFulfilHandler' })
}
}

Expand All @@ -342,7 +342,7 @@ const registerAllHandlers = async () => {
}
return true
} catch (err) {
util.rethrowFspiopError(err, 'registerAllHandlers')
rethrow.rethrowAndCountFspiopError(err, { operation: 'registerAllHandlers' })
}
}

Expand Down
Loading