diff --git a/.circleci/config.yml b/.circleci/config.yml index f51316a9..882c6ff1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -358,7 +358,7 @@ jobs: --set ml-api-adapter.ml-api-adapter-service.image.repository=$DOCKER_ORG/$CIRCLE_PROJECT_REPONAME \ --set ml-api-adapter.ml-api-adapter-service.image.tag=$CIRCLE_TAG \ --set ml-api-adapter.ml-api-adapter-handler-notification.image.repository=$DOCKER_ORG/$CIRCLE_PROJECT_REPONAME \ - --set ml-api-adapter.ml-api-adapter-handler-notification.image.tag=$CIRCLE_TAG + --set ml-api-adapter.ml-api-adapter-handler-notification.image.tag=$CIRCLE_TAG ## # Workflows diff --git a/package-lock.json b/package-lock.json index defa16cb..e31f59ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1227,28 +1227,8 @@ "resolved": "https://registry.npmjs.org/@mojaloop/central-services-logger/-/central-services-logger-9.5.1.tgz", "integrity": "sha512-VItX0jmJkGk5GiXnO5s2Fz7cpYvGtq0AmzrjT+Va39XvL/eMPMvzDy08wRbkcyD/RRTzu/20BKMWBw7GtkzG6A==", "requires": { - "parse-strings-in-object": "2.0.0", - "rc": "1.2.8", - "winston": "3.2.1" - } - }, - "@sinonjs/formatio": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-5.0.1.tgz", - "integrity": "sha512-KaiQ5pBf1MpS09MuA0kp6KBQt2JUOQycqVG1NZXvzeaXe5LGFqAKueIS0bw4w0P9r7KuBSVdUk5QjXsUdu2CxQ==", - "requires": { - "@sinonjs/commons": "^1", - "@sinonjs/samsam": "^5.0.2" - } - }, - "@sinonjs/samsam": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.0.3.tgz", - "integrity": "sha512-QucHkc2uMJ0pFGjJUDP3F9dq5dx8QIaqISl9QgwLOh6P9yv877uONPGXh/OH/0zmM3tW1JjuJltAZV2l7zU+uQ==", - "requires": { - "@sinonjs/commons": "^1.6.0", - "lodash.get": "^4.4.2", - "type-detect": "^4.0.8" + "lodash.camelcase": "^4.3.0", + "protobufjs": "^6.8.6" } }, "error-callsites": { @@ -1261,18 +1241,6 @@ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, - "nise": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.3.tgz", - "integrity": "sha512-EGlhjm7/4KvmmE6B/UFsKh7eHykRl9VH+au8dduHLCyWUO/hr7+N+WtTvDUwc9zHuM1IaIJs/0lQ6Ag1jDkQSg==", - "requires": { - "@sinonjs/commons": "^1.7.0", - "@sinonjs/fake-timers": "^6.0.0", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" - } - }, "protobufjs": { "version": "6.8.9", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.8.9.tgz", @@ -6899,9 +6867,9 @@ } }, "npm-pick-manifest": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-6.0.0.tgz", - "integrity": "sha512-PdJpXMvjqt4nftNEDpCgjBUF8yI3Q3MyuAmVB9nemnnCg32F4BPL/JFBfdj8DubgHCYUFQhtLWmBPvdsFtjWMg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-6.1.0.tgz", + "integrity": "sha512-ygs4k6f54ZxJXrzT0x34NybRlLeZ4+6nECAIbr2i0foTnijtS1TJiyzpqtuUAJOps/hO0tNDr8fRV5g+BtRlTw==", "dev": true, "requires": { "npm-install-checks": "^4.0.0", @@ -8503,7 +8471,6 @@ "version": "9.0.2", "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.0.2.tgz", "integrity": "sha512-0uF8Q/QHkizNUmbK3LRFqx5cpTttEVXudywY9Uwzy8bTfZUhljZ7ARzSxnRHWYWtVTeh4Cw+tTb3iU21FQVO9A==", - "dev": true, "requires": { "@sinonjs/commons": "^1.7.2", "@sinonjs/fake-timers": "^6.0.1", @@ -8518,7 +8485,6 @@ "version": "1.7.2", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.2.tgz", "integrity": "sha512-+DUO6pnp3udV/v2VfUWgaY5BIE1IfT7lLfeDzPVeMT1XKkaAp9LgSI9x5RtrFQoZ9Oi0PgXQQHPaoKu7dCjVxw==", - "dev": true, "requires": { "type-detect": "4.0.8" } @@ -8527,7 +8493,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-5.0.1.tgz", "integrity": "sha512-KaiQ5pBf1MpS09MuA0kp6KBQt2JUOQycqVG1NZXvzeaXe5LGFqAKueIS0bw4w0P9r7KuBSVdUk5QjXsUdu2CxQ==", - "dev": true, "requires": { "@sinonjs/commons": "^1", "@sinonjs/samsam": "^5.0.2" @@ -8537,7 +8502,6 @@ "version": "5.0.3", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.0.3.tgz", "integrity": "sha512-QucHkc2uMJ0pFGjJUDP3F9dq5dx8QIaqISl9QgwLOh6P9yv877uONPGXh/OH/0zmM3tW1JjuJltAZV2l7zU+uQ==", - "dev": true, "requires": { "@sinonjs/commons": "^1.6.0", "lodash.get": "^4.4.2", @@ -8548,7 +8512,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.3.tgz", "integrity": "sha512-EGlhjm7/4KvmmE6B/UFsKh7eHykRl9VH+au8dduHLCyWUO/hr7+N+WtTvDUwc9zHuM1IaIJs/0lQ6Ag1jDkQSg==", - "dev": true, "requires": { "@sinonjs/commons": "^1.7.0", "@sinonjs/fake-timers": "^6.0.0", diff --git a/src/api/transfers/handler.js b/src/api/transfers/handler.js index 6ec86941..82adf982 100644 --- a/src/api/transfers/handler.js +++ b/src/api/transfers/handler.js @@ -61,8 +61,8 @@ const create = async function (request, h) { span.setTracestateTags({ timeApiPrepare: `${Date.now()}` }) try { span.setTags(getTransferSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.PREPARE)) - Logger.debug('create::payload(%s)', JSON.stringify(request.payload)) - Logger.debug('create::headers(%s)', JSON.stringify(request.headers)) + Logger.isDebugEnabled && Logger.debug('create::payload(%s)', JSON.stringify(request.payload)) + Logger.isDebugEnabled && Logger.debug('create::headers(%s)', JSON.stringify(request.headers)) await span.audit({ headers: request.headers, dataUri: request.dataUri, @@ -104,9 +104,9 @@ const fulfilTransfer = async function (request, h) { try { span.setTags(getTransferSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.FULFIL)) Validator.fulfilTransfer(request) - Logger.debug('fulfilTransfer::payload(%s)', JSON.stringify(request.payload)) - Logger.debug('fulfilTransfer::headers(%s)', JSON.stringify(request.headers)) - Logger.debug('fulfilTransfer::id(%s)', request.params.id) + Logger.isDebugEnabled && Logger.debug('fulfilTransfer::payload(%s)', JSON.stringify(request.payload)) + Logger.isDebugEnabled && Logger.debug('fulfilTransfer::headers(%s)', JSON.stringify(request.headers)) + Logger.isDebugEnabled && Logger.debug('fulfilTransfer::id(%s)', request.params.id) await span.audit({ headers: request.headers, dataUri: request.dataUri, @@ -146,7 +146,7 @@ const getTransferById = async function (request, h) { const span = request.span try { span.setTags(getTransferSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.GET)) - Logger.info(`getById::id(${request.params.id})`) + Logger.isInfoEnabled && Logger.info(`getById::id(${request.params.id})`) await span.audit({ headers: request.headers, params: request.params @@ -183,9 +183,9 @@ const fulfilTransferError = async function (request, h) { const span = request.span try { span.setTags(getTransferSpanTags(request, Enum.Events.Event.Type.TRANSFER, Enum.Events.Event.Action.ABORT)) - Logger.debug('fulfilTransferError::payload(%s)', JSON.stringify(request.payload)) - Logger.debug('fulfilTransferError::headers(%s)', JSON.stringify(request.headers)) - Logger.debug('fulfilTransfer::id(%s)', request.params.id) + Logger.isDebugEnabled && Logger.debug('fulfilTransferError::payload(%s)', JSON.stringify(request.payload)) + Logger.isDebugEnabled && Logger.debug('fulfilTransferError::headers(%s)', JSON.stringify(request.headers)) + Logger.isDebugEnabled && Logger.debug('fulfilTransfer::id(%s)', request.params.id) await span.audit({ headers: request.headers, dataUri: request.dataUri, diff --git a/src/domain/participant/index.js b/src/domain/participant/index.js index 3c1f60a9..1c834265 100644 --- a/src/domain/participant/index.js +++ b/src/domain/participant/index.js @@ -58,9 +58,9 @@ const getEndpoint = async (fsp, endpointType, transferId = null, span = null) => getEndpointSpan = span.getChild(`${span.getContext().service}_getEndpoint`) getEndpointSpan.setTags({ endpointType, fsp }) } - Logger.debug(`domain::participant::getEndpoint::fsp - ${fsp}`) - Logger.debug(`domain::participant::getEndpoint::endpointType - ${endpointType}`) - Logger.debug(`domain::participant::getEndpoint::transferId - ${transferId}`) + Logger.isDebugEnabled && Logger.debug(`domain::participant::getEndpoint::fsp - ${fsp}`) + Logger.isDebugEnabled && Logger.debug(`domain::participant::getEndpoint::endpointType - ${endpointType}`) + Logger.isDebugEnabled && Logger.debug(`domain::participant::getEndpoint::transferId - ${transferId}`) try { const url = await Endpoints.getEndpoint(Config.ENDPOINT_SOURCE_URL, fsp, endpointType, { transferId }) diff --git a/src/domain/transfer/index.js b/src/domain/transfer/index.js index 3bd80604..5759d5f9 100644 --- a/src/domain/transfer/index.js +++ b/src/domain/transfer/index.js @@ -51,7 +51,7 @@ const generalEnum = require('@mojaloop/central-services-shared').Enum * @returns {boolean} Returns true on successful publishing of message to kafka, throws error on failures */ const prepare = async (headers, dataUri, payload, span) => { - Logger.debug('domain::transfer::prepare::start(%s, %s)', headers, payload) + Logger.isDebugEnabled && Logger.debug('domain::transfer::prepare::start(%s, %s)', headers, payload) try { const state = StreamingProtocol.createEventState(generalEnum.Events.EventStatus.SUCCESS.status, generalEnum.Events.EventStatus.SUCCESS.code, generalEnum.Events.EventStatus.SUCCESS.description) const event = StreamingProtocol.createEventMetadata(generalEnum.Events.Event.Type.PREPARE, generalEnum.Events.Event.Type.PREPARE, state) @@ -59,9 +59,9 @@ const prepare = async (headers, dataUri, payload, span) => { let messageProtocol = StreamingProtocol.createMessageFromRequest(payload.transferId, { headers, dataUri, params: { id: payload.transferId } }, payload.payeeFsp, payload.payerFsp, metadata) const topicConfig = KafkaUtil.createGeneralTopicConf(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, generalEnum.Events.Event.Action.TRANSFER, generalEnum.Events.Event.Action.PREPARE) const kafkaConfig = KafkaUtil.getKafkaConfig(Config.KAFKA_CONFIG, generalEnum.Kafka.Config.PRODUCER, generalEnum.Events.Event.Action.TRANSFER.toUpperCase(), generalEnum.Events.Event.Action.PREPARE.toUpperCase()) - Logger.debug(`domain::transfer::prepare::messageProtocol - ${messageProtocol}`) - Logger.debug(`domain::transfer::prepare::topicConfig - ${topicConfig}`) - Logger.debug(`domain::transfer::prepare::kafkaConfig - ${kafkaConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::prepare::messageProtocol - ${messageProtocol}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::prepare::topicConfig - ${topicConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::prepare::kafkaConfig - ${kafkaConfig}`) // TODO: re-enable once we are able to configure the log-level // await span.debug({ // messageProtocol, @@ -93,7 +93,7 @@ const prepare = async (headers, dataUri, payload, span) => { * @returns {boolean} Returns true on successful publishing of message to kafka, throws error on failures */ const fulfil = async (headers, dataUri, payload, params, span) => { - Logger.debug('domain::transfer::fulfil::start(%s, %s, %s)', params.id, headers, payload) + Logger.isDebugEnabled && Logger.debug('domain::transfer::fulfil::start(%s, %s, %s)', params.id, headers, payload) try { const action = payload.transferState === generalEnum.Transfers.TransferState.ABORTED ? generalEnum.Events.Event.Action.REJECT : generalEnum.Events.Event.Action.COMMIT const state = StreamingProtocol.createEventState(generalEnum.Events.EventStatus.SUCCESS.status, generalEnum.Events.EventStatus.SUCCESS.code, generalEnum.Events.EventStatus.SUCCESS.description) @@ -102,9 +102,9 @@ const fulfil = async (headers, dataUri, payload, params, span) => { let messageProtocol = StreamingProtocol.createMessageFromRequest(params.id, { headers, dataUri, params }, headers[generalEnum.Http.Headers.FSPIOP.DESTINATION], headers[generalEnum.Http.Headers.FSPIOP.SOURCE], metadata) const topicConfig = KafkaUtil.createGeneralTopicConf(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, generalEnum.Events.Event.Action.TRANSFER, generalEnum.Events.Event.Action.FULFIL) const kafkaConfig = KafkaUtil.getKafkaConfig(Config.KAFKA_CONFIG, generalEnum.Kafka.Config.PRODUCER, generalEnum.Events.Event.Action.TRANSFER.toUpperCase(), generalEnum.Events.Event.Action.FULFIL.toUpperCase()) - Logger.debug(`domain::transfer::fulfil::messageProtocol - ${messageProtocol}`) - Logger.debug(`domain::transfer::fulfil::topicConfig - ${topicConfig}`) - Logger.debug(`domain::transfer::fulfil::kafkaConfig - ${kafkaConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::fulfil::messageProtocol - ${messageProtocol}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::fulfil::topicConfig - ${topicConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::fulfil::kafkaConfig - ${kafkaConfig}`) await span.debug({ messageProtocol, topicName: topicConfig.topicName, @@ -133,7 +133,7 @@ const fulfil = async (headers, dataUri, payload, params, span) => { * @returns {boolean} Returns true on successful publishing of message to kafka, throws error on failures */ const getTransferById = async (headers, params, span) => { - Logger.info('domain::transfer::transferById::start(%s, %s, %s)', params.id, headers) + Logger.isInfoEnabled && Logger.info('domain::transfer::transferById::start(%s, %s, %s)', params.id, headers) try { const state = StreamingProtocol.createEventState(generalEnum.Events.EventStatus.SUCCESS.status, generalEnum.Events.EventStatus.SUCCESS.code, generalEnum.Events.EventStatus.SUCCESS.description) const event = StreamingProtocol.createEventMetadata(generalEnum.Events.Event.Type.GET, generalEnum.Events.Event.Type.GET, state) @@ -141,9 +141,9 @@ const getTransferById = async (headers, params, span) => { let messageProtocol = StreamingProtocol.createMessageFromRequest(params.id, { headers, dataUri: undefined, params }, headers[generalEnum.Http.Headers.FSPIOP.DESTINATION], headers[generalEnum.Http.Headers.FSPIOP.SOURCE], metadata) const topicConfig = KafkaUtil.createGeneralTopicConf(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, generalEnum.Events.Event.Action.TRANSFER, generalEnum.Events.Event.Action.GET) const kafkaConfig = KafkaUtil.getKafkaConfig(Config.KAFKA_CONFIG, generalEnum.Kafka.Config.PRODUCER, generalEnum.Events.Event.Action.TRANSFER.toUpperCase(), generalEnum.Events.Event.Action.GET.toUpperCase()) - Logger.info(`domain::transfer::get::messageProtocol - ${messageProtocol}`) - Logger.info(`domain::transfer::get::topicConfig - ${topicConfig}`) - Logger.info(`domain::transfer::get::kafkaConfig - ${kafkaConfig}`) + Logger.isInfoEnabled && Logger.info(`domain::transfer::get::messageProtocol - ${messageProtocol}`) + Logger.isInfoEnabled && Logger.info(`domain::transfer::get::topicConfig - ${topicConfig}`) + Logger.isInfoEnabled && Logger.info(`domain::transfer::get::kafkaConfig - ${kafkaConfig}`) // TODO: re-enable once we are able to configure the log-level // await span.debug({ // messageProtocol, @@ -175,7 +175,7 @@ const getTransferById = async (headers, params, span) => { * @returns {boolean} Returns true on successful publishing of message to kafka, throws error on failures */ const transferError = async (headers, dataUri, payload, params, span) => { - Logger.debug('domain::transfer::abort::start(%s, %s, %s)', params.id, headers, payload) + Logger.isDebugEnabled && Logger.debug('domain::transfer::abort::start(%s, %s, %s)', params.id, headers, payload) try { const state = StreamingProtocol.createEventState(generalEnum.Events.EventStatus.SUCCESS.status, generalEnum.Events.EventStatus.SUCCESS.code, generalEnum.Events.EventStatus.SUCCESS.description) const event = StreamingProtocol.createEventMetadata(generalEnum.Events.Event.Type.FULFIL, generalEnum.Events.Event.Action.ABORT, state) @@ -183,9 +183,9 @@ const transferError = async (headers, dataUri, payload, params, span) => { let messageProtocol = StreamingProtocol.createMessageFromRequest(params.id, { headers, dataUri, params }, headers[generalEnum.Http.Headers.FSPIOP.DESTINATION], headers[generalEnum.Http.Headers.FSPIOP.SOURCE], metadata) const topicConfig = KafkaUtil.createGeneralTopicConf(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, generalEnum.Events.Event.Action.TRANSFER, generalEnum.Events.Event.Action.FULFIL) const kafkaConfig = KafkaUtil.getKafkaConfig(Config.KAFKA_CONFIG, generalEnum.Kafka.Config.PRODUCER, generalEnum.Events.Event.Action.TRANSFER.toUpperCase(), generalEnum.Events.Event.Action.FULFIL.toUpperCase()) - Logger.debug(`domain::transfer::abort::messageProtocol - ${messageProtocol}`) - Logger.debug(`domain::transfer::abort::topicConfig - ${topicConfig}`) - Logger.debug(`domain::transfer::abort::kafkaConfig - ${kafkaConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::abort::messageProtocol - ${messageProtocol}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::abort::topicConfig - ${topicConfig}`) + Logger.isDebugEnabled && Logger.debug(`domain::transfer::abort::kafkaConfig - ${kafkaConfig}`) // TODO: re-enable once we are able to configure the log-level // await span.debug({ // messageProtocol, diff --git a/src/handlers/index.js b/src/handlers/index.js index daca7c5c..126fa196 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -55,7 +55,7 @@ Program.command('handler') // sub-command name, coffeeType = type, required .action(async (args) => { const handlerList = [] if (args.notification && typeof args.notification === 'boolean') { - Logger.debug('CLI: Executing --notification') + Logger.isDebugEnabled && Logger.debug('CLI: Executing --notification') const handler = { type: 'notification', enabled: true diff --git a/src/handlers/notification/index.js b/src/handlers/notification/index.js index 1bfefcbb..fc347efa 100644 --- a/src/handlers/notification/index.js +++ b/src/handlers/notification/index.js @@ -84,12 +84,12 @@ const recordTxMetrics = (timeApiPrepare, timeApiFulfil, success) => { * @returns {boolean} Returns true on success and throws error on failure */ const startConsumer = async () => { - Logger.info('Notification::startConsumer') + Logger.isInfoEnabled && Logger.info('Notification::startConsumer') let topicName try { const topicConfig = KafkaUtil.createGeneralTopicConf(Config.KAFKA_CONFIG.TOPIC_TEMPLATES.GENERAL_TOPIC_TEMPLATE.TEMPLATE, ENUM.Events.Event.Type.NOTIFICATION, ENUM.Events.Event.Action.EVENT) topicName = topicConfig.topicName - Logger.info(`Notification::startConsumer - starting Consumer for topicNames: [${topicName}]`) + Logger.isInfoEnabled && Logger.info(`Notification::startConsumer - starting Consumer for topicNames: [${topicName}]`) const config = KafkaUtil.getKafkaConfig(Config.KAFKA_CONFIG, ENUM.Kafka.Config.CONSUMER, ENUM.Events.Event.Type.NOTIFICATION.toUpperCase(), ENUM.Events.Event.Action.EVENT.toUpperCase()) config.rdkafkaConf['client.id'] = topicName @@ -98,9 +98,9 @@ const startConsumer = async () => { } notificationConsumer = new Consumer([topicName], config) await notificationConsumer.connect() - Logger.info(`Notification::startConsumer - Kafka Consumer connected for topicNames: [${topicName}]`) + Logger.isInfoEnabled && Logger.info(`Notification::startConsumer - Kafka Consumer connected for topicNames: [${topicName}]`) await notificationConsumer.consume(consumeMessage) - Logger.info(`Notification::startConsumer - Kafka Consumer created for topicNames: [${topicName}]`) + Logger.isInfoEnabled && Logger.info(`Notification::startConsumer - Kafka Consumer created for topicNames: [${topicName}]`) return true } catch (err) { Logger.error(`Notification::startConsumer - error for topicNames: [${topicName}] - ${err}`) @@ -121,7 +121,7 @@ const startConsumer = async () => { * @returns {boolean} Returns true on success or false on failure */ const consumeMessage = async (error, message) => { - Logger.info('Notification::consumeMessage') + Logger.isInfoEnabled && Logger.info('Notification::consumeMessage') const histTimerEnd = Metrics.getHistogram( 'notification_event', 'Consume a notification message from the kafka topic and process it accordingly', @@ -135,12 +135,12 @@ const consumeMessage = async (error, message) => { Logger.error(fspiopError) throw fspiopError } - Logger.info(`Notification:consumeMessage message: - ${JSON.stringify(message)}`) + Logger.isInfoEnabled && Logger.info(`Notification:consumeMessage message: - ${JSON.stringify(message)}`) message = (!Array.isArray(message) ? [message] : message) let combinedResult = true for (const msg of message) { - Logger.info('Notification::consumeMessage::processMessage') + Logger.isInfoEnabled && Logger.info('Notification::consumeMessage::processMessage') const contextFromMessage = EventSdk.Tracer.extractContextFromMessage(msg.value) const span = EventSdk.Tracer.createChildSpanFromContext('ml_notification_event', contextFromMessage) const traceTags = span.getTracestateTags() @@ -159,7 +159,7 @@ const consumeMessage = async (error, message) => { if (!autoCommitEnabled) { notificationConsumer.commitMessageSync(msg) } - Logger.debug(`Notification:consumeMessage message processed: - ${res}`) + Logger.isDebugEnabled && Logger.debug(`Notification:consumeMessage message processed: - ${res}`) combinedResult = (combinedResult && res) } catch (err) { const fspiopError = ErrorHandler.Factory.reformatFSPIOPError(err) @@ -223,7 +223,7 @@ const processMessage = async (msg, span) => { 'Consume a notification message from the kafka topic and process it accordingly', ['success', 'action'] ).startTimer() - Logger.info('Notification::processMessage') + Logger.isInfoEnabled && Logger.info('Notification::processMessage') if (!msg.value || !msg.value.content || !msg.value.content.headers || !msg.value.content.payload) { histTimerEnd({ success: false, action: 'unknown' }) throw ErrorHandler.Factory.createInternalServerFSPIOPError('Invalid message received from kafka') @@ -237,8 +237,8 @@ const processMessage = async (msg, span) => { const actionLower = action.toLowerCase() const statusLower = status.toLowerCase() - Logger.info('Notification::processMessage action: ' + action) - Logger.info('Notification::processMessage status: ' + status) + Logger.isInfoEnabled && Logger.info('Notification::processMessage action: ' + action) + Logger.isInfoEnabled && Logger.info('Notification::processMessage status: ' + status) const decodedPayload = decodePayload(content.payload, { asParsed: false }) const id = JSON.parse(decodedPayload.body.toString()).transferId || (content.uriParams && content.uriParams.id) let payloadForCallback @@ -258,7 +258,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.PREPARE && statusLower === ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_POST, id, span) callbackHeaders = createCallbackHeaders({ headers: content.headers, httpMethod: ENUM.Http.RestMethods.POST, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_POST }) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.POST}, ${JSON.stringify(content.headers)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.POST}, ${JSON.stringify(content.headers)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) let response = { status: 'unknown' } const histTimerEndSendRequest = Metrics.getHistogram( 'notification_event_delivery', @@ -282,7 +282,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.PREPARE && statusLower !== ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -291,7 +291,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.PREPARE_DUPLICATE && statusLower === ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) return true } @@ -300,7 +300,7 @@ const processMessage = async (msg, span) => { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }) // forward the fulfil to the destination - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) let response = { status: 'unknown' } const histTimerEndSendRequest = Metrics.getHistogram( 'notification_event_delivery', @@ -319,7 +319,7 @@ const processMessage = async (msg, span) => { // send an extra notification back to the original sender (if enabled in config) if (Config.SEND_TRANSFER_CONFIRMATION_TO_PAYEE) { const callbackURLFrom = await Participant.getEndpoint(from, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) callbackHeaders = createCallbackHeaders({ dfspId: from, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }, fromSwitch) const histTimerEndSendRequest2 = Metrics.getHistogram( 'notification_event_delivery', @@ -339,7 +339,7 @@ const processMessage = async (msg, span) => { histTimerEnd({ success: true, action }) return rv } else { - Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) histTimerEnd({ success: true, action }) return true } @@ -348,7 +348,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.COMMIT && statusLower !== ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -359,18 +359,18 @@ const processMessage = async (msg, span) => { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }) // forward the reject to the destination - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) // send an extra notification back to the original sender (if enabled in config) if (Config.SEND_TRANSFER_CONFIRMATION_TO_PAYEE) { - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) callbackHeaders = createCallbackHeaders({ dfspId: from, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }, fromSwitch) const response = await Callback.sendRequest(callbackURLFrom, callbackHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, from, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return response } else { - Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) } histTimerEnd({ success: true, action }) return true @@ -381,18 +381,18 @@ const processMessage = async (msg, span) => { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }) // forward the abort to the destination - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) // send an extra notification back to the original sender (if enabled in config) if (Config.SEND_TRANSFER_CONFIRMATION_TO_PAYEE) { - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLFrom}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${ENUM.Http.Headers.FSPIOP.SWITCH.value}, ${from})`) callbackHeaders = createCallbackHeaders({ dfspId: from, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) const response = await Callback.sendRequest(callbackURLFrom, callbackHeaders, ENUM.Http.Headers.FSPIOP.SWITCH.value, from, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return response } else { - Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Action: ${actionLower} - Skipping notification callback to original sender (${from}) because feature is disabled in config.`) } histTimerEnd({ success: true, action }) return true @@ -401,7 +401,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.FULFIL_DUPLICATE && statusLower === ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -410,7 +410,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.FULFIL_DUPLICATE && statusLower !== ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -419,7 +419,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.ABORT_DUPLICATE && statusLower === ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_PUT, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT }) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -428,7 +428,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.ABORT_DUPLICATE && statusLower !== ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -437,7 +437,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.TIMEOUT_RECEIVED) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${to}, ${from})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${to}, ${from})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -455,7 +455,7 @@ const processMessage = async (msg, span) => { if (actionLower === ENUM.Events.Event.Action.GET && statusLower !== ENUM.Events.EventStatus.SUCCESS.status) { const callbackURLTo = await Participant.getEndpoint(to, ENUM.EndPoints.FspEndpointTypes.FSPIOP_CALLBACK_URL_TRANSFER_ERROR, id, span) callbackHeaders = createCallbackHeaders({ dfspId: to, transferId: id, headers: content.headers, httpMethod: ENUM.Http.RestMethods.PUT, endpointTemplate: ENUM.EndPoints.FspEndpointTemplates.TRANSFERS_PUT_ERROR }, fromSwitch) - Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) + Logger.isDebugEnabled && Logger.debug(`Notification::processMessage - Callback.sendRequest(${callbackURLTo}, ${ENUM.Http.RestMethods.PUT}, ${JSON.stringify(callbackHeaders)}, ${payloadForCallback}, ${id}, ${from}, ${to})`) await Callback.sendRequest(callbackURLTo, callbackHeaders, from, to, ENUM.Http.RestMethods.PUT, payloadForCallback, ENUM.Http.ResponseTypes.JSON, span) histTimerEnd({ success: true, action }) return true @@ -506,7 +506,7 @@ const isConnected = async () => { const foundTopics = metadata.topics.map(topic => topic.name) if (foundTopics.indexOf(topicName) === -1) { - Logger.debug(`Connected to consumer, but ${topicName} not found.`) + Logger.isDebugEnabled && Logger.debug(`Connected to consumer, but ${topicName} not found.`) throw new Error(`Connected to consumer, but ${topicName} not found.`) } diff --git a/src/lib/healthCheck/subServiceHealth.js b/src/lib/healthCheck/subServiceHealth.js index 3b858d65..b8a7805c 100644 --- a/src/lib/healthCheck/subServiceHealth.js +++ b/src/lib/healthCheck/subServiceHealth.js @@ -48,7 +48,7 @@ const getSubServiceHealthBroker = async () => { status = await Producer.isConnected() status = status === Producer.stateList.PENDING ? statusEnum.OK : status } catch (err) { - Logger.debug(`getSubServiceHealthBroker failed with error: ${err.message}.`) + Logger.isDebugEnabled && Logger.debug(`getSubServiceHealthBroker failed with error: ${err.message}.`) status = statusEnum.DOWN } @@ -80,7 +80,7 @@ const getSubServiceHealthCentralLedger = async () => { throw new Error(`getSubServiceHealthCentralLedger request failed with unknown status: ${response.status}`) } } catch (err) { - Logger.debug(`getSubServiceHealthCentralLedger failed with error: ${err.message}.`) + Logger.isDebugEnabled && Logger.debug(`getSubServiceHealthCentralLedger failed with error: ${err.message}.`) status = statusEnum.DOWN } diff --git a/src/lib/validator.js b/src/lib/validator.js index 0e309daf..5e0cb6f5 100644 --- a/src/lib/validator.js +++ b/src/lib/validator.js @@ -33,7 +33,7 @@ const fulfilTransfer = (request) => { const maxCallbackTimeLagDilation = Config.MAX_CALLBACK_TIME_LAG_DILATION_MILLISECONDS ? Config.MAX_CALLBACK_TIME_LAG_DILATION_MILLISECONDS : 0 const completedTimestamp = new Date(request.payload.completedTimestamp) const now = new Date() - Logger.debug(`completedTimestamp: ${completedTimestamp.toISOString()}, now: ${now.toISOString()}, maxLag: ${maxLag}, maxCallbackTimeLagDilation: ${maxCallbackTimeLagDilation}`) + Logger.isDebugEnabled && Logger.debug(`completedTimestamp: ${completedTimestamp.toISOString()}, now: ${now.toISOString()}, maxLag: ${maxLag}, maxCallbackTimeLagDilation: ${maxCallbackTimeLagDilation}`) if (completedTimestamp.getTime() > now.getTime() + maxCallbackTimeLagDilation) { throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, 'completedTimestamp fails because future timestamp was provided') } else if (completedTimestamp.getTime() < now.getTime() - maxLag) { diff --git a/src/shared/setup.js b/src/shared/setup.js index fb519a92..5fc15316 100644 --- a/src/shared/setup.js +++ b/src/shared/setup.js @@ -73,7 +73,7 @@ const createServer = async (port, modules) => { await server.register(modules) await server.start() - Logger.debug('Server running at: ', server.info.uri) + Logger.isDebugEnabled && Logger.debug('Server running at: ', server.info.uri) return server } @@ -105,7 +105,7 @@ const createHandlers = async (handlers) => { for (handlerIndex in handlers) { const handler = handlers[handlerIndex] if (handler.enabled) { - Logger.info(`Handler Setup - Registering ${JSON.stringify(handler)}!`) + Logger.isInfoEnabled && Logger.info(`Handler Setup - Registering ${JSON.stringify(handler)}!`) if (handler.type === Enums.Kafka.Topics.NOTIFICATION) { await Endpoints.initializeCache(Config.ENDPOINT_CACHE_CONFIG) await RegisterHandlers.registerNotificationHandler() diff --git a/test/unit/api/transfers/handler.test.js b/test/unit/api/transfers/handler.test.js index 703f112b..880e09ac 100644 --- a/test/unit/api/transfers/handler.test.js +++ b/test/unit/api/transfers/handler.test.js @@ -30,6 +30,7 @@ const Config = require('../../../../src/lib/config') const Handler = require('../../../../src/api/transfers/handler') const TransferService = require('../../../../src/domain/transfer') const Enum = require('@mojaloop/central-services-shared').Enum +const Logger = require('@mojaloop/central-services-logger') const createRequest = (payload) => { const requestPayload = payload || {} @@ -70,6 +71,9 @@ Test('transfer handler', handlerTest => { handlerTest.beforeEach(t => { sandbox = Sinon.createSandbox() + sandbox.stub(Logger, 'isErrorEnabled').value(true) + sandbox.stub(Logger, 'isInfoEnabled').value(true) + sandbox.stub(Logger, 'isDebugEnabled').value(true) sandbox.stub(TransferService, 'prepare') sandbox.stub(TransferService, 'fulfil') sandbox.stub(TransferService, 'getTransferById') diff --git a/test/unit/domain/participant/index.test.js b/test/unit/domain/participant/index.test.js index aee834a8..dd8955ab 100644 --- a/test/unit/domain/participant/index.test.js +++ b/test/unit/domain/participant/index.test.js @@ -7,12 +7,14 @@ const Facade = require('@mojaloop/central-services-shared').Util.Endpoints const Service = require('../../../../src/domain/participant') const Enum = require('@mojaloop/central-services-shared').Enum const Config = require('../../../../src/lib/config') +const Logger = require('@mojaloop/central-services-logger') Test('ParticipantEndpoint Service Test', endpointTest => { let sandbox endpointTest.beforeEach(async test => { sandbox = Sinon.createSandbox() + sandbox.stub(Logger, 'isDebugEnabled').value(true) sandbox.stub(Facade, 'getEndpoint') test.end() }) diff --git a/test/unit/domain/transfer/index.test.js b/test/unit/domain/transfer/index.test.js index 8117b85b..7e9bfaa9 100644 --- a/test/unit/domain/transfer/index.test.js +++ b/test/unit/domain/transfer/index.test.js @@ -33,6 +33,7 @@ const KafkaUtil = require('@mojaloop/central-services-shared').Util.Kafka const Kafka = require('@mojaloop/central-services-stream').Util const Enum = require('@mojaloop/central-services-shared').Enum const Config = require('../../../../src/lib/config') +const Logger = require('@mojaloop/central-services-logger') const TRANSFER = 'transfer' const PREPARE = 'prepare' @@ -44,6 +45,9 @@ Test('Transfer Service tests', serviceTest => { serviceTest.beforeEach(t => { sandbox = Sinon.createSandbox() + sandbox.stub(Logger, 'isErrorEnabled').value(true) + sandbox.stub(Logger, 'isInfoEnabled').value(true) + sandbox.stub(Logger, 'isDebugEnabled').value(true) sandbox.stub(Kafka.Producer, 'produceMessage') sandbox.stub(Kafka.Producer, 'disconnect').returns(Promise.resolve(true)) t.end() diff --git a/test/unit/handlers/notification/index.test.js b/test/unit/handlers/notification/index.test.js index 154eba83..1c8096ff 100644 --- a/test/unit/handlers/notification/index.test.js +++ b/test/unit/handlers/notification/index.test.js @@ -64,6 +64,10 @@ Test('Notification Service tests', async notificationTest => { sandbox.stub(Participant, 'getEndpoint').returns(Promise.resolve(url)) sandbox.stub(Logger) + sandbox.stub(Logger, 'isErrorEnabled').value(true) + sandbox.stub(Logger, 'isInfoEnabled').value(true) + sandbox.stub(Logger, 'isDebugEnabled').value(true) + // sandbox.stub(Callback, 'sendRequest').returns(Promise.resolve(true)) sandbox.stub(Callback, 'sendRequest').returns(Promise.resolve(true)) t.end() diff --git a/test/unit/lib/healthCheck/subServiceHealth.test.js b/test/unit/lib/healthCheck/subServiceHealth.test.js index cb5980c4..b7e29164 100644 --- a/test/unit/lib/healthCheck/subServiceHealth.test.js +++ b/test/unit/lib/healthCheck/subServiceHealth.test.js @@ -37,6 +37,7 @@ const axios = require('axios') const Producer = require('@mojaloop/central-services-stream').Util.Producer const Config = require('../../../../src/lib/config') const { statusEnum, serviceName } = require('@mojaloop/central-services-shared').HealthCheck.HealthCheckEnums +const Logger = require('@mojaloop/central-services-logger') const Notification = require('../../../../src/handlers/notification/index') @@ -52,6 +53,9 @@ Test('SubServiceHealth test', subServiceHealthTest => { sandbox.stub(Notification, 'isConnected') sandbox.stub(axios, 'get') + sandbox.stub(Logger, 'isErrorEnabled').value(true) + sandbox.stub(Logger, 'isInfoEnabled').value(true) + sandbox.stub(Logger, 'isDebugEnabled').value(true) t.end() })