@mojaloop/central-services-shared 18.30.8 → 18.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [18.31.0](https://github.com/mojaloop/central-services-shared/compare/v18.30.8...v18.31.0) (2025-09-05)
6
+
7
+
8
+ ### Features
9
+
10
+ * **csi-1713:** add general app-critical metric on healthcheck ([#475](https://github.com/mojaloop/central-services-shared/issues/475)) ([f3c2980](https://github.com/mojaloop/central-services-shared/commit/f3c2980b1f4167bcf0821c8b524651233799e218))
11
+
5
12
  ### [18.30.8](https://github.com/mojaloop/central-services-shared/compare/v18.30.7...v18.30.8) (2025-09-01)
6
13
 
7
14
 
package/audit-ci.jsonc CHANGED
@@ -5,6 +5,5 @@
5
5
  "moderate": true,
6
6
  "allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
7
7
  // e.g. Currently no fixes available for the following
8
- "GHSA-968p-4wvh-cqc8" // https://github.com/advisories/GHSA-968p-4wvh-cqc8
9
8
  ]
10
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/central-services-shared",
3
- "version": "18.30.8",
3
+ "version": "18.31.0",
4
4
  "description": "Shared code for mojaloop central services",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ModusBox",
@@ -74,7 +74,7 @@
74
74
  "axios": "1.11.0",
75
75
  "clone": "2.1.2",
76
76
  "convict": "^6.2.4",
77
- "dotenv": "17.2.1",
77
+ "dotenv": "17.2.2",
78
78
  "env-var": "7.5.0",
79
79
  "event-stream": "4.0.1",
80
80
  "fast-safe-stringify": "2.1.1",
@@ -84,7 +84,7 @@
84
84
  "lodash": "4.17.21",
85
85
  "mustache": "4.2.0",
86
86
  "openapi-backend": "5.15.0",
87
- "raw-body": "3.0.0",
87
+ "raw-body": "3.0.1",
88
88
  "rc": "1.2.8",
89
89
  "redlock": "5.0.0-beta.2",
90
90
  "shins": "2.6.0",
@@ -96,10 +96,10 @@
96
96
  "devDependencies": {
97
97
  "@mojaloop/central-services-error-handling": "13.1.0",
98
98
  "@mojaloop/central-services-logger": "11.9.1",
99
- "@mojaloop/central-services-metrics": "12.6.0",
100
- "@mojaloop/event-sdk": "14.6.1",
99
+ "@mojaloop/central-services-metrics": "12.7.0",
100
+ "@mojaloop/event-sdk": "14.7.0",
101
101
  "@mojaloop/sdk-standard-components": "19.16.7",
102
- "@opentelemetry/auto-instrumentations-node": "^0.62.1",
102
+ "@opentelemetry/auto-instrumentations-node": "^0.62.2",
103
103
  "@types/hapi__joi": "17.1.15",
104
104
  "ajv": "^8.17.1",
105
105
  "ajv-formats": "^3.0.1",
@@ -32,6 +32,7 @@ const {
32
32
  statusEnum
33
33
  } = require('./HealthCheckEnums')
34
34
  const Logger = require('@mojaloop/central-services-logger')
35
+ const Metrics = require('@mojaloop/central-services-metrics')
35
36
 
36
37
  /**
37
38
  * @class HealthCheck
@@ -118,6 +119,20 @@ class HealthCheck {
118
119
  status = statusEnum.DOWN
119
120
  }
120
121
 
122
+ try {
123
+ const metrics = Metrics.getInstance ? Metrics.getInstance() : Metrics
124
+ if (metrics && typeof metrics.getGauge === 'function') {
125
+ const criticalGauge = metrics.getGauge('app-critical', 'App critical health status: 1=critical, 0=not critical', ['general'])
126
+ criticalGauge.set(isHealthy ? 0 : 1)
127
+ }
128
+ if (!isHealthy && metrics && typeof metrics.getCounter === 'function') {
129
+ const criticalCounter = metrics.getCounter('app-critical-total', 'Total times app entered critical health', ['general'])
130
+ criticalCounter.inc()
131
+ }
132
+ } catch (err) {
133
+ Logger.isErrorEnabled && Logger.error(`Failed to set app-critical metrics: ${err.message}`)
134
+ }
135
+
121
136
  return {
122
137
  status,
123
138
  uptime,
@@ -31,6 +31,7 @@
31
31
  const Test = require('tapes')(require('tape'))
32
32
  const Sinon = require('sinon')
33
33
  const Joi = require('joi')
34
+ const Metrics = require('@mojaloop/central-services-metrics')
34
35
 
35
36
  const HealthCheck = require('../../../src/healthCheck').HealthCheck
36
37
 
@@ -172,5 +173,54 @@ Test('HealthCheck test', healthCheckTest => {
172
173
  evaluateServiceHealthTest.end()
173
174
  })
174
175
 
176
+ healthCheckTest.test('getHealth metrics', metricsTest => {
177
+ let metricsMock
178
+
179
+ metricsTest.beforeEach(t => {
180
+ metricsMock = {
181
+ getGauge: Sinon.stub().returns({ set: Sinon.spy() }),
182
+ getCounter: Sinon.stub().returns({ inc: Sinon.spy() })
183
+ }
184
+ // Mock Metrics
185
+ sandbox.stub(Metrics, 'getGauge').callsFake(metricsMock.getGauge)
186
+ sandbox.stub(Metrics, 'getCounter').callsFake(metricsMock.getCounter)
187
+ t.end()
188
+ })
189
+
190
+ metricsTest.afterEach(t => {
191
+ sandbox.restore()
192
+ t.end()
193
+ })
194
+
195
+ metricsTest.test('sets app-critical gauge to 0 when healthy', async test => {
196
+ // Arrange
197
+ const healthCheck = new HealthCheck({ version: '1.0.0' }, [
198
+ async () => ({ status: 'OK', name: 'datastore' })
199
+ ])
200
+ // Act
201
+ await healthCheck.getHealth()
202
+ // Assert
203
+ test.ok(metricsMock.getGauge.calledWith('app-critical'), 'getGauge called')
204
+ test.equal(metricsMock.getGauge().set.firstCall.args[0], 0, 'gauge set to 0')
205
+ test.end()
206
+ })
207
+
208
+ metricsTest.test('sets app-critical gauge to 1 and increments counter when unhealthy', async test => {
209
+ // Arrange
210
+ const healthCheck = new HealthCheck({ version: '1.0.0' }, [
211
+ async () => ({ status: 'DOWN', name: 'datastore' })
212
+ ])
213
+ // Act
214
+ await healthCheck.getHealth()
215
+ // Assert
216
+ test.ok(metricsMock.getGauge.calledWith('app-critical'), 'getGauge called')
217
+ test.equal(metricsMock.getGauge().set.firstCall.args[0], 1, 'gauge set to 1')
218
+ test.ok(metricsMock.getCounter.calledWith('app-critical-total'), 'getCounter called')
219
+ test.ok(metricsMock.getCounter().inc.calledOnce, 'counter incremented')
220
+ test.end()
221
+ })
222
+
223
+ metricsTest.end()
224
+ })
175
225
  healthCheckTest.end()
176
226
  })