feat: add missing lifecycle monitoring for catalog, search and server

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-03-27 16:08:20 +02:00
parent 9624efb688
commit c6cb568f39
6 changed files with 45 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Add lifecycle monitoring for the catalog processing
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-search-backend-node': patch
'@backstage/plugin-search-backend': patch
---
Add lifecycle monitoring for the search index registry
@@ -201,7 +201,7 @@ export const catalogPlugin = createBackendPlugin({
permissions: coreServices.permissions,
database: coreServices.database,
httpRouter: coreServices.httpRouter,
lifecycle: coreServices.lifecycle,
lifecycle: coreServices.rootLifecycle,
scheduler: coreServices.scheduler,
discovery: coreServices.discovery,
auth: coreServices.auth,
@@ -253,7 +253,9 @@ export const catalogPlugin = createBackendPlugin({
const { processingEngine, router } = await builder.build();
await processingEngine.start();
lifecycle.addStartupHook(async () => {
await processingEngine.start();
});
lifecycle.addShutdownHook(() => processingEngine.stop());
httpRouter.use(router);
},
@@ -34,6 +34,7 @@ export const searchIndexRegistryExtensionPoint: ExtensionPoint<SearchIndexRegist
export interface SearchIndexService {
getDocumentTypes(): Record<string, DocumentTypeInfo>;
start(options: SearchIndexServiceStartOptions): Promise<void>;
stop(): Promise<void>;
}
// @alpha
+17 -3
View File
@@ -22,11 +22,11 @@ import {
LoggerService,
} from '@backstage/backend-plugin-api';
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
import {
IndexBuilder,
RegisterCollatorParameters,
RegisterDecoratorParameters,
Scheduler,
SearchEngine,
} from '@backstage/plugin-search-backend-node';
@@ -49,6 +49,11 @@ export interface SearchIndexService {
* Starts indexing process
*/
start(options: SearchIndexServiceStartOptions): Promise<void>;
/**
* Stops indexing process
*/
stop(): Promise<void>;
/**
* Returns an index types list.
*/
@@ -81,8 +86,9 @@ type DefaultSearchIndexServiceOptions = {
* Reponsible for register the indexing task and start the schedule.
*/
class DefaultSearchIndexService implements SearchIndexService {
private logger: LoggerService;
private readonly logger: LoggerService;
private indexBuilder: IndexBuilder | null = null;
private scheduler: Scheduler | null = null;
private constructor(options: DefaultSearchIndexServiceOptions) {
this.logger = options.logger;
@@ -107,7 +113,15 @@ class DefaultSearchIndexService implements SearchIndexService {
);
const { scheduler } = await this.indexBuilder?.build();
scheduler.start();
this.scheduler = scheduler;
this.scheduler!.start();
}
async stop(): Promise<void> {
if (this.scheduler) {
this.scheduler.stop();
this.scheduler = null;
}
}
getDocumentTypes(): Record<string, DocumentTypeInfo> {
+12 -4
View File
@@ -98,6 +98,7 @@ export default createBackendPlugin({
auth: coreServices.auth,
http: coreServices.httpRouter,
httpAuth: coreServices.httpAuth,
lifecycle: coreServices.rootLifecycle,
searchIndexService: searchIndexServiceRef,
},
async init({
@@ -108,6 +109,7 @@ export default createBackendPlugin({
auth,
http,
httpAuth,
lifecycle,
searchIndexService,
}) {
let searchEngine = searchEngineRegistry.getSearchEngine();
@@ -120,10 +122,16 @@ export default createBackendPlugin({
const collators = searchIndexRegistry.getCollators();
const decorators = searchIndexRegistry.getDecorators();
await searchIndexService.start({
searchEngine,
collators,
decorators,
lifecycle.addStartupHook(async () => {
await searchIndexService.start({
searchEngine: searchEngine!,
collators,
decorators,
});
});
lifecycle.addShutdownHook(async () => {
await searchIndexService.stop();
});
const router = await createRouter({