@backstage/plugin-search-backend-module-elasticsearch 1.5.7-next.0 → 1.5.7-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ 'use strict';
2
+
3
+ var pluginSearchBackendNode = require('@backstage/plugin-search-backend-node');
4
+ var stream = require('stream');
5
+
6
+ function duration(startTimestamp) {
7
+ const delta = process.hrtime(startTimestamp);
8
+ const seconds = delta[0] + delta[1] / 1e9;
9
+ return `${seconds.toFixed(1)}s`;
10
+ }
11
+ class ElasticSearchSearchEngineIndexer extends pluginSearchBackendNode.BatchSearchEngineIndexer {
12
+ processed = 0;
13
+ removableIndices = [];
14
+ startTimestamp;
15
+ type;
16
+ indexName;
17
+ indexPrefix;
18
+ indexSeparator;
19
+ alias;
20
+ logger;
21
+ sourceStream;
22
+ elasticSearchClientWrapper;
23
+ configuredBatchSize;
24
+ bulkResult;
25
+ bulkClientError;
26
+ constructor(options) {
27
+ super({ batchSize: options.batchSize });
28
+ this.configuredBatchSize = options.batchSize;
29
+ this.logger = options.logger.child({ documentType: options.type });
30
+ this.startTimestamp = process.hrtime();
31
+ this.type = options.type;
32
+ this.indexPrefix = options.indexPrefix;
33
+ this.indexSeparator = options.indexSeparator;
34
+ this.indexName = this.constructIndexName(`${Date.now()}`);
35
+ this.alias = options.alias;
36
+ this.elasticSearchClientWrapper = options.elasticSearchClientWrapper;
37
+ this.sourceStream = new stream.Readable({ objectMode: true });
38
+ this.sourceStream._read = () => {
39
+ };
40
+ const that = this;
41
+ this.bulkResult = this.elasticSearchClientWrapper.bulk({
42
+ datasource: this.sourceStream,
43
+ onDocument() {
44
+ that.processed++;
45
+ return {
46
+ index: { _index: that.indexName }
47
+ };
48
+ },
49
+ refreshOnCompletion: options.skipRefresh !== true
50
+ });
51
+ this.bulkResult.catch((e) => {
52
+ this.bulkClientError = e;
53
+ });
54
+ }
55
+ async initialize() {
56
+ this.logger.info(`Started indexing documents for index ${this.type}`);
57
+ const indices = await this.elasticSearchClientWrapper.listIndices({
58
+ index: this.constructIndexName("*")
59
+ });
60
+ for (const key of Object.keys(indices.body)) {
61
+ this.removableIndices.push(key);
62
+ }
63
+ await this.elasticSearchClientWrapper.createIndex({
64
+ index: this.indexName
65
+ });
66
+ }
67
+ async index(documents) {
68
+ await this.isReady();
69
+ documents.forEach((document) => {
70
+ this.sourceStream.push(document);
71
+ });
72
+ }
73
+ async finalize() {
74
+ await this.isReady();
75
+ this.sourceStream.push(null);
76
+ const result = await this.bulkResult;
77
+ if (this.processed === 0) {
78
+ this.logger.warn(
79
+ `Index for ${this.type} was not ${this.removableIndices.length ? "replaced" : "created"}: indexer received 0 documents`
80
+ );
81
+ try {
82
+ await this.elasticSearchClientWrapper.deleteIndex({
83
+ index: this.indexName
84
+ });
85
+ } catch (error) {
86
+ this.logger.error(`Unable to clean up elastic index: ${error}`);
87
+ }
88
+ return;
89
+ }
90
+ this.logger.info(
91
+ `Indexing completed for index ${this.type} in ${duration(
92
+ this.startTimestamp
93
+ )}`,
94
+ result
95
+ );
96
+ await this.elasticSearchClientWrapper.updateAliases({
97
+ actions: [
98
+ {
99
+ remove: { index: this.constructIndexName("*"), alias: this.alias }
100
+ },
101
+ {
102
+ add: { index: this.indexName, alias: this.alias }
103
+ }
104
+ ].filter(Boolean)
105
+ });
106
+ if (this.removableIndices.length) {
107
+ this.logger.info("Removing stale search indices", {
108
+ removableIndices: this.removableIndices
109
+ });
110
+ const chunks = this.removableIndices.reduce(
111
+ (resultArray, item, index) => {
112
+ const chunkIndex = Math.floor(index / 50);
113
+ if (!resultArray[chunkIndex]) {
114
+ resultArray[chunkIndex] = [];
115
+ }
116
+ resultArray[chunkIndex].push(item);
117
+ return resultArray;
118
+ },
119
+ []
120
+ );
121
+ for (const chunk of chunks) {
122
+ try {
123
+ await this.elasticSearchClientWrapper.deleteIndex({
124
+ index: chunk
125
+ });
126
+ } catch (e) {
127
+ this.logger.warn(`Failed to remove stale search indices: ${e}`);
128
+ }
129
+ }
130
+ }
131
+ }
132
+ /**
133
+ * Ensures that the number of documents sent over the wire to ES matches the
134
+ * number of documents this stream has received so far. This helps manage
135
+ * backpressure in other parts of the indexing pipeline.
136
+ */
137
+ isReady() {
138
+ if (this.bulkClientError) {
139
+ return Promise.reject(this.bulkClientError);
140
+ }
141
+ if (this.sourceStream.readableLength < this.configuredBatchSize) {
142
+ return Promise.resolve();
143
+ }
144
+ return new Promise((isReady, abort) => {
145
+ let streamLengthChecks = 0;
146
+ const interval = setInterval(() => {
147
+ streamLengthChecks++;
148
+ if (this.sourceStream.readableLength < this.configuredBatchSize) {
149
+ clearInterval(interval);
150
+ isReady();
151
+ }
152
+ if (streamLengthChecks >= 6e3) {
153
+ clearInterval(interval);
154
+ abort(
155
+ new Error(
156
+ "Exceeded 5 minutes waiting for elastic to be ready to accept more documents. Check the elastic logs for possible problems."
157
+ )
158
+ );
159
+ }
160
+ }, 50);
161
+ });
162
+ }
163
+ constructIndexName(postFix) {
164
+ return `${this.indexPrefix}${this.type}${this.indexSeparator}${postFix}`;
165
+ }
166
+ }
167
+
168
+ exports.ElasticSearchSearchEngineIndexer = ElasticSearchSearchEngineIndexer;
169
+ //# sourceMappingURL=ElasticSearchSearchEngineIndexer.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElasticSearchSearchEngineIndexer.cjs.js","sources":["../../src/engines/ElasticSearchSearchEngineIndexer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';\nimport { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Readable } from 'stream';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * Options for instantiate ElasticSearchSearchEngineIndexer\n * @public\n */\nexport type ElasticSearchSearchEngineIndexerOptions = {\n type: string;\n indexPrefix: string;\n indexSeparator: string;\n alias: string;\n logger: LoggerService;\n elasticSearchClientWrapper: ElasticSearchClientWrapper;\n batchSize: number;\n skipRefresh?: boolean;\n};\n\nfunction duration(startTimestamp: [number, number]): string {\n const delta = process.hrtime(startTimestamp);\n const seconds = delta[0] + delta[1] / 1e9;\n return `${seconds.toFixed(1)}s`;\n}\n\n/**\n * Elasticsearch specific search engine indexer.\n * @public\n */\nexport class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {\n private processed: number = 0;\n private removableIndices: string[] = [];\n\n private readonly startTimestamp: [number, number];\n private readonly type: string;\n public readonly indexName: string;\n private readonly indexPrefix: string;\n private readonly indexSeparator: string;\n private readonly alias: string;\n private readonly logger: LoggerService;\n private readonly sourceStream: Readable;\n private readonly elasticSearchClientWrapper: ElasticSearchClientWrapper;\n private configuredBatchSize: number;\n private bulkResult: Promise<any>;\n private bulkClientError?: Error;\n\n constructor(options: ElasticSearchSearchEngineIndexerOptions) {\n super({ batchSize: options.batchSize });\n this.configuredBatchSize = options.batchSize;\n this.logger = options.logger.child({ documentType: options.type });\n this.startTimestamp = process.hrtime();\n this.type = options.type;\n this.indexPrefix = options.indexPrefix;\n this.indexSeparator = options.indexSeparator;\n this.indexName = this.constructIndexName(`${Date.now()}`);\n this.alias = options.alias;\n this.elasticSearchClientWrapper = options.elasticSearchClientWrapper;\n\n // The ES client bulk helper supports stream-based indexing, but we have to\n // supply the stream directly to it at instantiation-time. We can't supply\n // this class itself, so instead, we create this inline stream instead.\n this.sourceStream = new Readable({ objectMode: true });\n this.sourceStream._read = () => {};\n\n // eslint-disable-next-line consistent-this\n const that = this;\n\n // Keep a reference to the ES Bulk helper so that we can know when all\n // documents have been successfully written to ES.\n this.bulkResult = this.elasticSearchClientWrapper.bulk({\n datasource: this.sourceStream,\n onDocument() {\n that.processed++;\n return {\n index: { _index: that.indexName },\n };\n },\n refreshOnCompletion: options.skipRefresh !== true,\n });\n\n // Safely catch errors thrown by the bulk helper client, e.g. HTTP timeouts\n this.bulkResult.catch(e => {\n this.bulkClientError = e;\n });\n }\n\n async initialize(): Promise<void> {\n this.logger.info(`Started indexing documents for index ${this.type}`);\n\n const indices = await this.elasticSearchClientWrapper.listIndices({\n index: this.constructIndexName('*'),\n });\n\n for (const key of Object.keys(indices.body)) {\n this.removableIndices.push(key);\n }\n\n await this.elasticSearchClientWrapper.createIndex({\n index: this.indexName,\n });\n }\n\n async index(documents: IndexableDocument[]): Promise<void> {\n await this.isReady();\n documents.forEach(document => {\n this.sourceStream.push(document);\n });\n }\n\n async finalize(): Promise<void> {\n // Wait for all documents to be processed.\n await this.isReady();\n\n // Close off the underlying stream connected to ES, indicating that no more\n // documents will be written.\n this.sourceStream.push(null);\n\n // Wait for the bulk helper to finish processing.\n const result = await this.bulkResult;\n\n // Warn that no documents were indexed, early return so that alias swapping\n // does not occur, and clean up the empty index we just created.\n if (this.processed === 0) {\n this.logger.warn(\n `Index for ${this.type} was not ${\n this.removableIndices.length ? 'replaced' : 'created'\n }: indexer received 0 documents`,\n );\n try {\n await this.elasticSearchClientWrapper.deleteIndex({\n index: this.indexName,\n });\n } catch (error) {\n this.logger.error(`Unable to clean up elastic index: ${error}`);\n }\n return;\n }\n\n // Rotate main alias upon completion. Apply permanent secondary alias so\n // stale indices can be referenced for deletion in case initial attempt\n // fails. Allow errors to bubble up so that we can clean up the created index.\n this.logger.info(\n `Indexing completed for index ${this.type} in ${duration(\n this.startTimestamp,\n )}`,\n result,\n );\n await this.elasticSearchClientWrapper.updateAliases({\n actions: [\n {\n remove: { index: this.constructIndexName('*'), alias: this.alias },\n },\n {\n add: { index: this.indexName, alias: this.alias },\n },\n ].filter(Boolean),\n });\n\n // If any indices are removable, remove them. Do not bubble up this error,\n // as doing so would delete the now aliased index. Log instead.\n if (this.removableIndices.length) {\n this.logger.info('Removing stale search indices', {\n removableIndices: this.removableIndices,\n });\n\n // Split the array into chunks of up to 50 indices to handle the case\n // where we need to delete a lot of stalled indices\n const chunks = this.removableIndices.reduce(\n (resultArray, item, index) => {\n const chunkIndex = Math.floor(index / 50);\n\n if (!resultArray[chunkIndex]) {\n resultArray[chunkIndex] = []; // start a new chunk\n }\n\n resultArray[chunkIndex].push(item);\n\n return resultArray;\n },\n [] as string[][],\n );\n\n // Call deleteIndex for each chunk\n for (const chunk of chunks) {\n try {\n await this.elasticSearchClientWrapper.deleteIndex({\n index: chunk,\n });\n } catch (e) {\n this.logger.warn(`Failed to remove stale search indices: ${e}`);\n }\n }\n }\n }\n\n /**\n * Ensures that the number of documents sent over the wire to ES matches the\n * number of documents this stream has received so far. This helps manage\n * backpressure in other parts of the indexing pipeline.\n */\n private isReady(): Promise<void> {\n // Early exit if the underlying ES client encountered an error.\n if (this.bulkClientError) {\n return Promise.reject(this.bulkClientError);\n }\n\n // Optimization: if the stream that ES reads from has fewer docs queued\n // than the configured batch size, continue early to allow more docs to be\n // queued\n if (this.sourceStream.readableLength < this.configuredBatchSize) {\n return Promise.resolve();\n }\n\n // Otherwise, continue periodically checking the stream queue to see if\n // ES has consumed the documents and continue when it's ready for more.\n return new Promise((isReady, abort) => {\n let streamLengthChecks = 0;\n const interval = setInterval(() => {\n streamLengthChecks++;\n\n if (this.sourceStream.readableLength < this.configuredBatchSize) {\n clearInterval(interval);\n isReady();\n }\n\n // Do not allow this interval to loop endlessly; anything longer than 5\n // minutes likely indicates an unrecoverable error in ES; direct the\n // user to inspect ES logs for more clues and abort in order to allow\n // the index to be cleaned up.\n if (streamLengthChecks >= 6000) {\n clearInterval(interval);\n abort(\n new Error(\n 'Exceeded 5 minutes waiting for elastic to be ready to accept more documents. Check the elastic logs for possible problems.',\n ),\n );\n }\n }, 50);\n });\n }\n\n private constructIndexName(postFix: string) {\n return `${this.indexPrefix}${this.type}${this.indexSeparator}${postFix}`;\n }\n}\n"],"names":["BatchSearchEngineIndexer","Readable"],"mappings":";;;;;AAqCA,SAAS,SAAS,cAA0C,EAAA;AAC1D,EAAM,MAAA,KAAA,GAAQ,OAAQ,CAAA,MAAA,CAAO,cAAc,CAAA,CAAA;AAC3C,EAAA,MAAM,UAAU,KAAM,CAAA,CAAC,CAAI,GAAA,KAAA,CAAM,CAAC,CAAI,GAAA,GAAA,CAAA;AACtC,EAAA,OAAO,CAAG,EAAA,OAAA,CAAQ,OAAQ,CAAA,CAAC,CAAC,CAAA,CAAA,CAAA,CAAA;AAC9B,CAAA;AAMO,MAAM,yCAAyCA,gDAAyB,CAAA;AAAA,EACrE,SAAoB,GAAA,CAAA,CAAA;AAAA,EACpB,mBAA6B,EAAC,CAAA;AAAA,EAErB,cAAA,CAAA;AAAA,EACA,IAAA,CAAA;AAAA,EACD,SAAA,CAAA;AAAA,EACC,WAAA,CAAA;AAAA,EACA,cAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,0BAAA,CAAA;AAAA,EACT,mBAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,eAAA,CAAA;AAAA,EAER,YAAY,OAAkD,EAAA;AAC5D,IAAA,KAAA,CAAM,EAAE,SAAA,EAAW,OAAQ,CAAA,SAAA,EAAW,CAAA,CAAA;AACtC,IAAA,IAAA,CAAK,sBAAsB,OAAQ,CAAA,SAAA,CAAA;AACnC,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ,MAAO,CAAA,KAAA,CAAM,EAAE,YAAc,EAAA,OAAA,CAAQ,MAAM,CAAA,CAAA;AACjE,IAAK,IAAA,CAAA,cAAA,GAAiB,QAAQ,MAAO,EAAA,CAAA;AACrC,IAAA,IAAA,CAAK,OAAO,OAAQ,CA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