diff --git a/docs/backend-system/core-services/01-index.md b/docs/backend-system/core-services/01-index.md index 04d2e57ae8..63324292c1 100644 --- a/docs/backend-system/core-services/01-index.md +++ b/docs/backend-system/core-services/01-index.md @@ -20,6 +20,7 @@ import { coreServices } from '@backstage/backend-plugin-api'; - [Cache Service](./cache.md) - Key-value store for caching data. - [Database Service](./database.md) - Database access and management via [knex](https://knexjs.org/). - [Discovery Service](./discovery.md) - Service discovery for inter-plugin communication. +- [Health Service](./health.md) - Health check endpoints for the backend. - [Http Auth Service](./http-auth.md) - Authentication of HTTP requests. - [Http Router Service](./http-router.md) - HTTP route registration for plugins. - [Identity Service](./identity.md) - Deprecated user authentication service, use the [Auth Service](./auth.md) instead. diff --git a/docs/backend-system/core-services/health.md b/docs/backend-system/core-services/health.md new file mode 100644 index 0000000000..9a69891624 --- /dev/null +++ b/docs/backend-system/core-services/health.md @@ -0,0 +1,39 @@ +--- +id: health +title: Heath Service +sidebar_label: Health +description: Documentation for the Health service +--- + +The Health service provides some health check endpoints for the plugins. By default, it attaches `/.backstage/health/v1/readiness` and `/.backstage/health/v1/liveness` endpoints to the backend server, which return a JSON object with the status of the backend services. + +## Configuring the service + +The following example is how you can override the health service to add custom endpoints. + +```ts +import { coreServices } from '@backstage/backend-plugin-api'; +import { WinstonLogger } from '@backstage/backend-app-api'; + +const backend = createBackend(); + +backend.add( + createServiceFactory({ + service: coreServices.health, + deps: { + rootHttpRouter: coreServices.rootHttpRouter, + }, + async factory({ rootHttpRouter }) { + rootHttpRouter.get('.backstage/health/v1/readiness', async (req, res) => { + res.json({ status: 'ok' }); + }); + + rootHttpRouter.get('.backstage/health/v1/liveness', async (req, res) => { + res.json({ status: 'ok' }); + }); + + return {}; + }, + }), +); +```