diff --git a/README.md b/README.md index 6a42c9fb..566aee72 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,6 @@ Service template also comes with a curated set of plugins [installed](./src/app. - @scalar/fastify-api-reference (OpenAPI specification website) - fastify-graceful-shutdown (handling SEGTERM gracefully) - fastify-no-icon (avoiding warnings when sending GET calls via browser) -- fastify-custom-healthcheck (registering app and dependency healthchecks) - @lokalise/fastify-extras -> metricsPlugin (exposing Prometheus metrics) - @lokalise/fastify-extras -> requestContextProviderPlugin (storing requestId in AsyncLocalStorage and populating requestContext on request) diff --git a/package-lock.json b/package-lock.json index dd8d9c47..9cf5c8d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@fastify/swagger": "^9.4.0", "@lokalise/backend-http-client": "^2.4.0", "@lokalise/background-jobs-common": "^9.0.0", - "@lokalise/fastify-extras": "^25.3.0", + "@lokalise/fastify-extras": "^25.4.1", "@lokalise/healthcheck-utils": "^1.4.0", "@lokalise/id-utils": "^2.2.0", "@lokalise/node-core": "^13.1.0", @@ -2214,9 +2214,9 @@ } }, "node_modules/@lokalise/fastify-extras": { - "version": "25.3.0", - "resolved": "https://registry.npmjs.org/@lokalise/fastify-extras/-/fastify-extras-25.3.0.tgz", - "integrity": "sha512-TSbMQbFuwyNXF8r/l8J52bT56UyzjGMdQJIwT73wo+b8jy3qgpN0LKZcDBVDomSfKVbSTyHXh3Lf9STO2mKvyw==", + "version": "25.4.1", + "resolved": "https://registry.npmjs.org/@lokalise/fastify-extras/-/fastify-extras-25.4.1.tgz", + "integrity": "sha512-hUJASlHuTauhJMCvVj/FBpAv+tI/RcOGNbC673twItsojv28ebLyW4uB64J95oqQboS51TR3sNopcVjKLHOlOA==", "license": "Apache-2.0", "dependencies": { "@amplitude/analytics-node": "^1.3.6", diff --git a/package.json b/package.json index 3c775f32..f1269ff6 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@fastify/swagger": "^9.4.0", "@lokalise/backend-http-client": "^2.4.0", "@lokalise/background-jobs-common": "^9.0.0", - "@lokalise/fastify-extras": "^25.3.0", + "@lokalise/fastify-extras": "^25.4.1", "@lokalise/healthcheck-utils": "^1.4.0", "@lokalise/id-utils": "^2.2.0", "@lokalise/node-core": "^13.1.0", @@ -65,7 +65,6 @@ "awilix-manager": "^5.5.0", "bullmq": "^5.29.1", "fastify": "^5.1.0", - "fastify-custom-healthcheck": "^3.1.0", "fastify-graceful-shutdown": "^4.0.1", "fastify-metrics": "^12.1.0", "fastify-no-icon": "^7.0.0", diff --git a/src/app.e2e.spec.ts b/src/app.e2e.spec.ts index 6ad259bb..2d23368c 100644 --- a/src/app.e2e.spec.ts +++ b/src/app.e2e.spec.ts @@ -27,20 +27,18 @@ describe('app', () => { }) describe('healthcheck', () => { - it('Returns health check information', async () => { + it('Returns public health check information', async () => { const response = await app.inject().get('/').end() expect(response.json()).toMatchObject({ - healthChecks: { - heartbeat: 'HEALTHY', - redis: 'HEALTHY', - postgres: 'HEALTHY', - }, + gitCommitSha: 'sha', + heartbeat: 'HEALTHY', + version: '1', }) expect(response.statusCode).toBe(200) }) - it('Returns public health check information', async () => { + it('Returns private health check information', async () => { const response = await app.inject().get('/health').end() expect(response.json()).toMatchObject({ diff --git a/src/app.ts b/src/app.ts index 6c6cc5b8..c2f9fe6c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,10 +13,10 @@ import fastifySwagger from '@fastify/swagger' import { amplitudePlugin, bugsnagPlugin, + commonHealthcheckPlugin, getRequestIdFastifyAppConfig, metricsPlugin, newrelicTransactionManagerPlugin, - publicHealthcheckPlugin, requestContextProviderPlugin, } from '@lokalise/fastify-extras' import { type CommonLogger, resolveLogger } from '@lokalise/node-core' @@ -25,7 +25,6 @@ import scalarFastifyApiReference from '@scalar/fastify-api-reference' import { type AwilixContainer, asFunction } from 'awilix' import fastify from 'fastify' import type { FastifyInstance } from 'fastify' -import customHealthCheck from 'fastify-custom-healthcheck' import fastifyGracefulShutdown from 'fastify-graceful-shutdown' import fastifyNoIcon from 'fastify-no-icon' import { @@ -42,7 +41,6 @@ import { errorHandler } from './infrastructure/errors/errorHandler.js' import { dbHealthCheck, redisHealthCheck, - registerHealthChecks, } from './infrastructure/healthchecks/healthchecksWrappers.js' import { SINGLETON_CONFIG, registerDependencies } from './infrastructure/parentDiConfig.js' import type { DependencyOverrides } from './infrastructure/parentDiConfig.js' @@ -244,20 +242,7 @@ export async function getApp( } if (configOverrides.healthchecksEnabled !== false) { - await app.register(customHealthCheck, { - path: '/', - logLevel: 'warn', - info: { - env: appConfig.nodeEnv, - app_version: appConfig.appVersion, - git_commit_sha: appConfig.gitCommitSha, - }, - schema: false, - exposeFailure: false, - }) - - await app.register(publicHealthcheckPlugin, { - url: '/health', + await app.register(commonHealthcheckPlugin, { healthChecks: [ { name: 'postgres', @@ -318,10 +303,6 @@ export async function getApp( return Promise.resolve() }) } - - if (configOverrides.healthchecksEnabled !== false) { - registerHealthChecks(app) - } }) try { diff --git a/src/infrastructure/healthchecks/healthchecksWrappers.ts b/src/infrastructure/healthchecks/healthchecksWrappers.ts index f3ee990a..e5654008 100644 --- a/src/infrastructure/healthchecks/healthchecksWrappers.ts +++ b/src/infrastructure/healthchecks/healthchecksWrappers.ts @@ -2,17 +2,6 @@ import type { HealthChecker } from '@lokalise/fastify-extras' import type { Either } from '@lokalise/node-core' import type { FastifyInstance } from 'fastify' -import type { AppInstance } from '../../app.js' - -export const wrapHealthCheck = (app: AppInstance, healthCheck: HealthChecker) => { - return async () => { - const response = await healthCheck(app as unknown as FastifyInstance) - if (response.error) { - throw response.error - } - } -} - export const redisHealthCheck: HealthChecker = ( app: FastifyInstance, ): Promise> => { @@ -38,9 +27,3 @@ export const dbHealthCheck: HealthChecker = ( } return Promise.resolve({ result: true }) } - -export function registerHealthChecks(app: AppInstance) { - app.addHealthCheck('heartbeat', () => true) - app.addHealthCheck('redis', wrapHealthCheck(app, redisHealthCheck)) - app.addHealthCheck('postgres', wrapHealthCheck(app, dbHealthCheck)) -}