From e36e507d592c3a6011b6834cd8a0b751bc38c339 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Thu, 20 Jun 2024 12:20:18 +0200 Subject: [PATCH] docs: update root health docs Signed-off-by: Vincenzo Scamporlino --- .../core-services/root-health.md | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/backend-system/core-services/root-health.md b/docs/backend-system/core-services/root-health.md index 9a69891624..2a6625fd70 100644 --- a/docs/backend-system/core-services/root-health.md +++ b/docs/backend-system/core-services/root-health.md @@ -1,38 +1,40 @@ --- -id: health -title: Heath Service +id: root-health +title: Root Health 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. +The Root Health service provides some health check endpoints for the backend. By default, the `rootHttpRouter` exposes a `/.backstage/health/v1/readiness` and `/.backstage/health/v1/liveness` endpoints, which return a JSON object with the status of the backend services according the implementation of the Root Health Service. ## Configuring the service -The following example is how you can override the health service to add custom endpoints. +The following example is how you can override the health service implementation. ```ts -import { coreServices } from '@backstage/backend-plugin-api'; +import { RootHealthService, coreServices } from '@backstage/backend-plugin-api'; import { WinstonLogger } from '@backstage/backend-app-api'; const backend = createBackend(); +class MyRootHealthService implements RootHealthService { + async getLiveness(): Promise<{ status: number; payload?: any }> { + // provide your own implementation + return { status: 200, payload: { status: 'ok' } }; + } + + async getReadiness(): Promise<{ status: number; payload?: any }> { + // provide your own implementation + return { status: 200, payload: { status: 'ok' } }; + } +} + 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 {}; + service: coreServices.rootHealth, + deps: {}, + async factory({}) { + return new MyRootHealthService(); }, }), );