Tag indexing logs with document type

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2022-10-10 18:02:33 +02:00
parent 0cc6914ae3
commit 8006f8a602
8 changed files with 20 additions and 9 deletions
@@ -0,0 +1,9 @@
---
'@backstage/plugin-adr-backend': patch
'@backstage/plugin-search-backend-module-elasticsearch': patch
'@backstage/plugin-search-backend-node': patch
'@backstage/plugin-stack-overflow-backend': patch
'@backstage/plugin-techdocs-backend': patch
---
In order to improve the debuggability of the search indexing process, messages logged during indexing are now tagged with a `documentType` whose value corresponds to the `type` being indexed.
+1
View File
@@ -68,6 +68,7 @@ dataflow
dayjs
debounce
Debounce
debuggability
declaratively
deduplicated
deps
@@ -113,7 +113,7 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory {
this.catalogClient =
options.catalogClient ??
new CatalogClient({ discoveryApi: options.discovery });
this.logger = options.logger;
this.logger = options.logger.child({ documentType: this.type });
this.parser = options.parser ?? createMadrParser();
this.reader = options.reader;
this.scmIntegrations = ScmIntegrations.fromConfig(options.config);
@@ -63,7 +63,7 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
constructor(options: ElasticSearchSearchEngineIndexerOptions) {
super({ batchSize: options.batchSize });
this.logger = options.logger;
this.logger = options.logger.child({ documentType: options.type });
this.startTimestamp = process.hrtime();
this.type = options.type;
this.indexPrefix = options.indexPrefix;
@@ -112,13 +112,14 @@ export class IndexBuilder {
});
Object.keys(this.collators).forEach(type => {
const taskLogger = this.logger.child({ documentType: type });
scheduler.addToSchedule({
id: `search_index_${type.replace('-', '_').toLocaleLowerCase('en-US')}`,
scheduledRunner: this.collators[type].schedule,
task: async () => {
// Instantiate the collator.
const collator = await this.collators[type].factory.getCollator();
this.logger.info(
taskLogger.info(
`Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`,
);
@@ -128,7 +129,7 @@ export class IndexBuilder {
.concat(this.decorators[type] || [])
.map(async factory => {
const decorator = await factory.getDecorator();
this.logger.info(
taskLogger.info(
`Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`,
);
return decorator;
@@ -144,13 +145,13 @@ export class IndexBuilder {
[collator, ...decorators, indexer],
(error: NodeJS.ErrnoException | null) => {
if (error) {
this.logger.error(
taskLogger.error(
`Collating documents for ${type} failed: ${error}`,
);
reject(error);
} else {
// Signal index pipeline completion!
this.logger.info(`Collating documents for ${type} succeeded`);
taskLogger.info(`Collating documents for ${type} succeeded`);
resolve();
}
},
@@ -93,7 +93,7 @@ export class NewlineDelimitedJsonCollatorFactory
options.type,
options.searchPattern,
options.reader,
options.logger,
options.logger.child({ documentType: options.type }),
options.visibilityPermission,
);
}
@@ -76,7 +76,7 @@ export class StackOverflowQuestionsCollatorFactory
this.apiKey = options.apiKey;
this.maxPage = options.maxPage;
this.requestParams = options.requestParams;
this.logger = options.logger;
this.logger = options.logger.child({ documentType: this.type });
}
static fromConfig(
@@ -90,7 +90,7 @@ export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory {
this.discovery = options.discovery;
this.locationTemplate =
options.locationTemplate || '/docs/:namespace/:kind/:name/:path';
this.logger = options.logger;
this.logger = options.logger.child({ documentType: this.type });
this.catalogClient =
options.catalogClient ||
new CatalogClient({ discoveryApi: options.discovery });