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

Single endpoint for all prometheus metrics #278

Merged
merged 15 commits into from
Mar 19, 2025
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "cht-user-management",
"version": "2.1.7",
"version": "2.1.8",
"main": "dist/index.js",
"dependencies": {
"@bull-board/api": "^5.17.0",
4 changes: 2 additions & 2 deletions scripts/deploy/values/users-chis-civ.yaml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "2.1.7" # Set this to the version of the docker image
tag: "2.1.8" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "2.1.7"
tag: "2.1.8"
env:
NODE_ENV: production
REDIS_HOST: users-chis-civ-redis-master.users-chis-prod.svc.cluster.local
4 changes: 2 additions & 2 deletions scripts/deploy/values/users-chis-ke.yaml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "2.1.7" # Set this to the version of the docker image
tag: "2.1.8" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "2.1.7"
tag: "2.1.8"
env:
NODE_ENV: production
REDIS_HOST: users-chis-ke-redis-master.users-chis-prod.svc.cluster.local
4 changes: 2 additions & 2 deletions scripts/deploy/values/users-chis-ml.yaml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "2.1.7" # Set this to the version of the docker image
tag: "2.1.8" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "2.1.7"
tag: "2.1.8"
env:
NODE_ENV: production
REDIS_HOST: users-chis-ml-redis-master.users-chis-prod.svc.cluster.local
4 changes: 2 additions & 2 deletions scripts/deploy/values/users-chis-tg.yaml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "2.1.7" # Set this to the version of the docker image
tag: "2.1.8" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
@@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "2.1.7"
tag: "2.1.8"
env:
NODE_ENV: production
REDIS_HOST: users-chis-tg-redis-master.users-chis-prod.svc.cluster.local
22 changes: 14 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ import SessionCache from './services/session-cache';
import { checkRedisConnection } from './config/config-worker';
import { getChtConfQueue } from './lib/queues';

const PROMETHEUS_ENDPOINT = '/metrics';
const UNAUTHENTICATED_ENDPOINTS = [
'/public/*',
'/fastify-metrics',
'/bullmq-metrics'
PROMETHEUS_ENDPOINT,
];

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

fastify.register(metricsPlugin, {
endpoint: '/fastify-metrics',
endpoint: PROMETHEUS_ENDPOINT,
routeMetrics: {
registeredRoutesOnly: false,
groupStatusCodes: false,
methodBlacklist: ['HEAD', 'OPTIONS', 'TRACE'],
invalidRouteGroup: '__unknown__',
enabled: {
histogram: true,
summary: false
summary: true,
}
}
});

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

Auth.assertEnvironmentSetup();