search-backend-module-elasticsearch: allow LoggerService to be used instead of Logger

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-09 11:34:15 +02:00
parent b67f413882
commit 7ccf1f9090
2 changed files with 11 additions and 8 deletions
@@ -38,6 +38,7 @@ import {
AwsCredentialProvider,
DefaultAwsCredentialsManager,
} from '@backstage/integration-aws-node';
import { LoggerService } from '@backstage/backend-plugin-api';
export type { ElasticSearchClientOptions };
@@ -73,7 +74,7 @@ export type ElasticSearchQueryTranslator = (
* @public
*/
export type ElasticSearchOptions = {
logger: Logger;
logger: Logger | LoggerService;
config: Config;
aliasPostfix?: string;
indexPrefix?: string;
@@ -126,7 +127,7 @@ export class ElasticSearchSearchEngine implements SearchEngine {
private readonly elasticSearchClientOptions: ElasticSearchClientOptions,
private readonly aliasPostfix: string,
private readonly indexPrefix: string,
private readonly logger: Logger,
private readonly logger: Logger | LoggerService,
private readonly batchSize: number,
highlightOptions?: ElasticSearchHighlightOptions,
) {
@@ -229,11 +230,10 @@ export class ElasticSearchSearchEngine implements SearchEngine {
.boolQuery()
.should(value.map(it => esb.matchQuery(key, it.toString())));
}
this.logger.error(
'Failed to query, unrecognized filter type',
this.logger.error('Failed to query, unrecognized filter type', {
key,
value,
);
});
throw new Error(
'Failed to add filters to query. Unrecognized filter type',
);
@@ -19,6 +19,7 @@ import { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';
import { IndexableDocument } from '@backstage/plugin-search-common';
import { Logger } from 'winston';
import { Readable } from 'stream';
import { LoggerService } from '@backstage/backend-plugin-api';
/**
* Options for instantiate ElasticSearchSearchEngineIndexer
@@ -29,7 +30,7 @@ export type ElasticSearchSearchEngineIndexerOptions = {
indexPrefix: string;
indexSeparator: string;
alias: string;
logger: Logger;
logger: Logger | LoggerService;
elasticSearchClientWrapper: ElasticSearchClientWrapper;
batchSize: number;
};
@@ -55,7 +56,7 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
private readonly indexSeparator: string;
private readonly alias: string;
private readonly removableAlias: string;
private readonly logger: Logger;
private readonly logger: Logger | LoggerService;
private readonly sourceStream: Readable;
private readonly elasticSearchClientWrapper: ElasticSearchClientWrapper;
private configuredBatchSize: number;
@@ -186,7 +187,9 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
// If any indices are removable, remove them. Do not bubble up this error,
// as doing so would delete the now aliased index. Log instead.
if (this.removableIndices.length) {
this.logger.info('Removing stale search indices', this.removableIndices);
this.logger.info('Removing stale search indices', {
removableIndices: this.removableIndices,
});
try {
await this.elasticSearchClientWrapper.deleteIndex({
index: this.removableIndices,