Skip to content

Commit 7a698b8

Browse files
authored
Single endpoint for all prometheus metrics (#278)
2.1.8
1 parent e76889b commit 7a698b8

7 files changed

+25
-19
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cht-user-management",
3-
"version": "2.1.7",
3+
"version": "2.1.8",
44
"main": "dist/index.js",
55
"dependencies": {
66
"@bull-board/api": "^5.17.0",

scripts/deploy/values/users-chis-civ.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cht-user-management:
55
enabled: true
66
image:
77
repository: public.ecr.aws/medic/cht-user-management
8-
tag: "2.1.7" # Set this to the version of the docker image
8+
tag: "2.1.8" # Set this to the version of the docker image
99

1010
# Environment variablues to set in the pod, for example:
1111
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
5151
replicaCount: 1
5252
image:
5353
repository: public.ecr.aws/medic/cht-user-management-worker
54-
tag: "2.1.7"
54+
tag: "2.1.8"
5555
env:
5656
NODE_ENV: production
5757
REDIS_HOST: users-chis-civ-redis-master.users-chis-prod.svc.cluster.local

scripts/deploy/values/users-chis-ke.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cht-user-management:
55
enabled: true
66
image:
77
repository: public.ecr.aws/medic/cht-user-management
8-
tag: "2.1.7" # Set this to the version of the docker image
8+
tag: "2.1.8" # Set this to the version of the docker image
99

1010
# Environment variablues to set in the pod, for example:
1111
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
5151
replicaCount: 1
5252
image:
5353
repository: public.ecr.aws/medic/cht-user-management-worker
54-
tag: "2.1.7"
54+
tag: "2.1.8"
5555
env:
5656
NODE_ENV: production
5757
REDIS_HOST: users-chis-ke-redis-master.users-chis-prod.svc.cluster.local

scripts/deploy/values/users-chis-ml.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cht-user-management:
55
enabled: true
66
image:
77
repository: public.ecr.aws/medic/cht-user-management
8-
tag: "2.1.7" # Set this to the version of the docker image
8+
tag: "2.1.8" # Set this to the version of the docker image
99

1010
# Environment variablues to set in the pod, for example:
1111
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
5151
replicaCount: 1
5252
image:
5353
repository: public.ecr.aws/medic/cht-user-management-worker
54-
tag: "2.1.7"
54+
tag: "2.1.8"
5555
env:
5656
NODE_ENV: production
5757
REDIS_HOST: users-chis-ml-redis-master.users-chis-prod.svc.cluster.local

scripts/deploy/values/users-chis-tg.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cht-user-management:
55
enabled: true
66
image:
77
repository: public.ecr.aws/medic/cht-user-management
8-
tag: "2.1.7" # Set this to the version of the docker image
8+
tag: "2.1.8" # Set this to the version of the docker image
99

1010
# Environment variablues to set in the pod, for example:
1111
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
5151
replicaCount: 1
5252
image:
5353
repository: public.ecr.aws/medic/cht-user-management-worker
54-
tag: "2.1.7"
54+
tag: "2.1.8"
5555
env:
5656
NODE_ENV: production
5757
REDIS_HOST: users-chis-tg-redis-master.users-chis-prod.svc.cluster.local

src/server.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import SessionCache from './services/session-cache';
1616
import { checkRedisConnection } from './config/config-worker';
1717
import { getChtConfQueue } from './lib/queues';
1818

19+
const PROMETHEUS_ENDPOINT = '/metrics';
1920
const UNAUTHENTICATED_ENDPOINTS = [
2021
'/public/*',
21-
'/fastify-metrics',
22-
'/bullmq-metrics'
22+
PROMETHEUS_ENDPOINT,
2323
];
2424

2525
const build = (opts: FastifyServerOptions): FastifyInstance => {
@@ -53,19 +53,25 @@ const build = (opts: FastifyServerOptions): FastifyInstance => {
5353
});
5454

5555
fastify.register(metricsPlugin, {
56-
endpoint: '/fastify-metrics',
56+
endpoint: PROMETHEUS_ENDPOINT,
5757
routeMetrics: {
58+
registeredRoutesOnly: false,
59+
groupStatusCodes: false,
60+
methodBlacklist: ['HEAD', 'OPTIONS', 'TRACE'],
61+
invalidRouteGroup: '__unknown__',
5862
enabled: {
5963
histogram: true,
60-
summary: false
64+
summary: true,
6165
}
6266
}
6367
});
6468

65-
fastify.get('/bullmq-metrics', async (req, resp) => {
66-
const promMetrics = await getChtConfQueue().bullQueue.exportPrometheusMetrics();
67-
resp.header('Content-Type', 'text/plain');
68-
resp.send(promMetrics);
69+
// hijack the response from fastify-metrics appending additional metrics
70+
fastify.addHook('onSend', async (request, reply, payload: string) => {
71+
if (request.routerPath === PROMETHEUS_ENDPOINT) {
72+
const bullmqMetrics = await getChtConfQueue().bullQueue.exportPrometheusMetrics();
73+
return payload + bullmqMetrics;
74+
}
6975
});
7076

7177
Auth.assertEnvironmentSetup();

0 commit comments

Comments
 (0)