docs: add health service

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2024-06-03 13:45:41 +02:00
parent 972896d192
commit 652da2e3e3
2 changed files with 40 additions and 0 deletions
@@ -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.
@@ -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 {};
},
}),
);
```