Skip to content

Commit 6d53b32

Browse files
darorasoedirgo
authored andcommitted
feat: add a secondary port with admin endpoints
The first endpoint included is for metrics using the prometheus exposition format.
1 parent 2a199a0 commit 6d53b32

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

package-lock.json

Lines changed: 66 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@sinclair/typebox": "^0.23.4",
38+
"fastify-metrics": "^8.0.0",
3839
"pg": "^8.7.1",
3940
"pg-format": "^1.0.4",
4041
"pgsql-parser": "^13.3.0",

src/server/admin-app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fastify, { FastifyInstance, FastifyServerOptions } from 'fastify'
2+
3+
import _default = require('fastify-metrics')
4+
5+
export function build(opts: FastifyServerOptions = {}): FastifyInstance {
6+
const app = fastify(opts)
7+
app.register(_default, {
8+
endpoint: '/metrics',
9+
enableRouteMetrics: false,
10+
blacklist: ['nodejs_version_info', 'process_start_time_seconds'],
11+
})
12+
return app
13+
}

src/server/app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import routes from './routes'
44
import { extractRequestForLogging } from './utils'
55
import pino from 'pino'
66
import pkg from '../../package.json'
7+
import { build as buildAdminApp } from './admin-app'
78

89
const logger = pino({
910
formatters: {
@@ -57,6 +58,11 @@ if (PG_META_EXPORT_DOCS) {
5758
app.ready(() => {
5859
app.listen(PG_META_PORT, '0.0.0.0', () => {
5960
app.log.info(`App started on port ${PG_META_PORT}`)
61+
const adminApp = buildAdminApp({ logger })
62+
const adminPort = PG_META_PORT + 1
63+
adminApp.listen(adminPort, '0.0.0.0', () => {
64+
adminApp.log.info(`Admin App started on port ${adminPort}`)
65+
})
6066
})
6167
})
6268
}

0 commit comments

Comments
 (0)