@backstage/plugin-search-backend-module-elasticsearch 1.7.9-next.1 → 1.7.10-next.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @backstage/plugin-search-backend-module-elasticsearch
2
2
 
3
+ ## 1.7.10-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7455dae: Use node prefix on native imports
8
+ - Updated dependencies
9
+ - @backstage/integration-aws-node@0.1.20-next.0
10
+ - @backstage/backend-plugin-api@1.7.0-next.0
11
+ - @backstage/plugin-search-backend-node@1.4.1-next.0
12
+ - @backstage/plugin-search-common@1.2.22-next.0
13
+ - @backstage/config@1.3.6
14
+
15
+ ## 1.7.9
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - @backstage/plugin-search-backend-node@1.4.0
21
+ - @backstage/backend-plugin-api@1.6.0
22
+
3
23
  ## 1.7.9-next.1
4
24
 
5
25
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"ElasticSearchClientOptions.cjs.js","sources":["../../src/engines/ElasticSearchClientOptions.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\nimport type { ConnectionOptions as TLSConnectionOptions } from 'tls';\n\n/**\n * Typeguard to differentiate ElasticSearch client options which are compatible\n * with OpenSearch vs. ElasticSearch clients. Useful when calling the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport const isOpenSearchCompatible = (\n opts: ElasticSearchClientOptions,\n): opts is OpenSearchElasticSearchClientOptions => {\n return ['aws', 'opensearch'].includes(opts?.provider ?? '');\n};\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client or the\n * `@opensearch-project/opensearch` client, depending on the given config. It\n * will be passed as an argument to the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport type ElasticSearchClientOptions =\n | ElasticSearchElasticSearchClientOptions\n | OpenSearchElasticSearchClientOptions;\n\n/**\n * Options used to configure the `@opensearch-project/opensearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@opensearch-project/opensearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface OpenSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'aws' | 'opensearch';\n region?: string;\n service?: 'es' | 'aoss';\n auth?: OpenSearchAuth;\n connection?: OpenSearchConnectionConstructor;\n node?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n nodes?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n}\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@elastic/elasticsearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface ElasticSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'elastic';\n auth?: ElasticSearchAuth;\n Connection?: ElasticSearchConnectionConstructor;\n node?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n nodes?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n cloud?: {\n id: string;\n username?: string;\n password?: string;\n };\n}\n\n/**\n * Base client options that are shared across `@opensearch-project/opensearch`\n * and `@elastic/elasticsearch` clients.\n *\n * @public\n */\nexport interface BaseElasticSearchClientOptions {\n Transport?: ElasticSearchTransportConstructor;\n maxRetries?: number;\n requestTimeout?: number;\n pingTimeout?: number;\n sniffInterval?: number | boolean;\n sniffOnStart?: boolean;\n sniffEndpoint?: string;\n sniffOnConnectionFault?: boolean;\n resurrectStrategy?: 'ping' | 'optimistic' | 'none';\n suggestCompression?: boolean;\n compression?: 'gzip';\n ssl?: TLSConnectionOptions;\n agent?: ElasticSearchAgentOptions | ((opts?: any) => unknown) | false;\n nodeFilter?: (connection: any) => boolean;\n nodeSelector?: ((connections: any[]) => any) | string;\n headers?: Record<string, any>;\n opaqueIdPrefix?: string;\n name?: string | symbol;\n proxy?: string | URL;\n enableMetaHeader?: boolean;\n disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor';\n}\n\n/**\n * @public\n */\nexport type OpenSearchAuth = {\n username: string;\n password: string;\n};\n\n/**\n * @public\n */\nexport type ElasticSearchAuth =\n | OpenSearchAuth\n | {\n apiKey:\n | string\n | {\n id: string;\n api_key: string;\n };\n };\n\n/**\n * @public\n */\nexport interface ElasticSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n ml: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchAgentOptions {\n keepAlive?: boolean;\n keepAliveMsecs?: number;\n maxSockets?: number;\n maxFreeSockets?: number;\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n ML: string;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchTransportConstructor {\n new (opts?: any): any;\n sniffReasons: {\n SNIFF_ON_START: string;\n SNIFF_INTERVAL: string;\n SNIFF_ON_CONNECTION_FAULT: string;\n DEFAULT: string;\n };\n}\n\n// todo(iamEAP) implement canary types to ensure we remain compatible through upgrades.\n"],"names":[],"mappings":";;AAwBO,MAAM,sBAAA,GAAyB,CACpC,IAAA,KACiD;AACjD,EAAA,OAAO,CAAC,KAAA,EAAO,YAAY,EAAE,QAAA,CAAS,IAAA,EAAM,YAAY,EAAE,CAAA;AAC5D;;;;"}
1
+ {"version":3,"file":"ElasticSearchClientOptions.cjs.js","sources":["../../src/engines/ElasticSearchClientOptions.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\nimport type { ConnectionOptions as TLSConnectionOptions } from 'node:tls';\n\n/**\n * Typeguard to differentiate ElasticSearch client options which are compatible\n * with OpenSearch vs. ElasticSearch clients. Useful when calling the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport const isOpenSearchCompatible = (\n opts: ElasticSearchClientOptions,\n): opts is OpenSearchElasticSearchClientOptions => {\n return ['aws', 'opensearch'].includes(opts?.provider ?? '');\n};\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client or the\n * `@opensearch-project/opensearch` client, depending on the given config. It\n * will be passed as an argument to the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport type ElasticSearchClientOptions =\n | ElasticSearchElasticSearchClientOptions\n | OpenSearchElasticSearchClientOptions;\n\n/**\n * Options used to configure the `@opensearch-project/opensearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@opensearch-project/opensearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface OpenSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'aws' | 'opensearch';\n region?: string;\n service?: 'es' | 'aoss';\n auth?: OpenSearchAuth;\n connection?: OpenSearchConnectionConstructor;\n node?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n nodes?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n}\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@elastic/elasticsearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface ElasticSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'elastic';\n auth?: ElasticSearchAuth;\n Connection?: ElasticSearchConnectionConstructor;\n node?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n nodes?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n cloud?: {\n id: string;\n username?: string;\n password?: string;\n };\n}\n\n/**\n * Base client options that are shared across `@opensearch-project/opensearch`\n * and `@elastic/elasticsearch` clients.\n *\n * @public\n */\nexport interface BaseElasticSearchClientOptions {\n Transport?: ElasticSearchTransportConstructor;\n maxRetries?: number;\n requestTimeout?: number;\n pingTimeout?: number;\n sniffInterval?: number | boolean;\n sniffOnStart?: boolean;\n sniffEndpoint?: string;\n sniffOnConnectionFault?: boolean;\n resurrectStrategy?: 'ping' | 'optimistic' | 'none';\n suggestCompression?: boolean;\n compression?: 'gzip';\n ssl?: TLSConnectionOptions;\n agent?: ElasticSearchAgentOptions | ((opts?: any) => unknown) | false;\n nodeFilter?: (connection: any) => boolean;\n nodeSelector?: ((connections: any[]) => any) | string;\n headers?: Record<string, any>;\n opaqueIdPrefix?: string;\n name?: string | symbol;\n proxy?: string | URL;\n enableMetaHeader?: boolean;\n disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor';\n}\n\n/**\n * @public\n */\nexport type OpenSearchAuth = {\n username: string;\n password: string;\n};\n\n/**\n * @public\n */\nexport type ElasticSearchAuth =\n | OpenSearchAuth\n | {\n apiKey:\n | string\n | {\n id: string;\n api_key: string;\n };\n };\n\n/**\n * @public\n */\nexport interface ElasticSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n ml: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchAgentOptions {\n keepAlive?: boolean;\n keepAliveMsecs?: number;\n maxSockets?: number;\n maxFreeSockets?: number;\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n ML: string;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchTransportConstructor {\n new (opts?: any): any;\n sniffReasons: {\n SNIFF_ON_START: string;\n SNIFF_INTERVAL: string;\n SNIFF_ON_CONNECTION_FAULT: string;\n DEFAULT: string;\n };\n}\n\n// todo(iamEAP) implement canary types to ensure we remain compatible through upgrades.\n"],"names":[],"mappings":";;AAwBO,MAAM,sBAAA,GAAyB,CACpC,IAAA,KACiD;AACjD,EAAA,OAAO,CAAC,KAAA,EAAO,YAAY,EAAE,QAAA,CAAS,IAAA,EAAM,YAAY,EAAE,CAAA;AAC5D;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ElasticSearchClientWrapper.cjs.js","sources":["../../src/engines/ElasticSearchClientWrapper.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Client as ElasticSearchClient } from '@elastic/elasticsearch';\nimport { Client as OpenSearchClient } from '@opensearch-project/opensearch';\nimport { Readable } from 'stream';\nimport {\n ElasticSearchClientOptions,\n isOpenSearchCompatible,\n} from './ElasticSearchClientOptions';\nimport { ElasticSearchCustomIndexTemplate } from './types';\n\n/**\n * @public\n */\nexport type ElasticSearchAliasAction =\n | {\n remove: { index: any; alias: any };\n add?: undefined;\n }\n | {\n add: { indices: any; alias: any; index?: undefined };\n remove?: undefined;\n }\n | {\n add: { index: any; alias: any; indices?: undefined };\n remove?: undefined;\n }\n | undefined;\n\n/**\n * @public\n */\nexport type ElasticSearchIndexAction = {\n index: {\n _index: string;\n [key: string]: any;\n };\n};\n\n/**\n * A wrapper class that exposes logical methods that are conditionally fired\n * against either a configured Elasticsearch client or a configured Opensearch\n * client.\n *\n * This is necessary because, despite its intention to be API-compatible, the\n * opensearch client does not support API key-based authentication. This is\n * also the sanest way to accomplish this while making typescript happy.\n *\n * In the future, if the differences between implementations become\n * unmaintainably divergent, we should split out the Opensearch and\n * Elasticsearch search engine implementations.\n *\n * @public\n */\nexport class ElasticSearchClientWrapper {\n private readonly elasticSearchClient: ElasticSearchClient | undefined;\n private readonly openSearchClient: OpenSearchClient | undefined;\n\n private constructor(options: {\n openSearchClient?: OpenSearchClient;\n elasticSearchClient?: ElasticSearchClient;\n }) {\n this.openSearchClient = options.openSearchClient;\n this.elasticSearchClient = options.elasticSearchClient;\n }\n\n static fromClientOptions(options: ElasticSearchClientOptions) {\n if (isOpenSearchCompatible(options)) {\n return new ElasticSearchClientWrapper({\n openSearchClient: new OpenSearchClient(options),\n });\n }\n\n return new ElasticSearchClientWrapper({\n elasticSearchClient: new ElasticSearchClient(options),\n });\n }\n\n search(options: { index: string | string[]; body: Object }) {\n const searchOptions = {\n ignore_unavailable: true,\n allow_no_indices: true,\n };\n\n if (this.openSearchClient) {\n return this.openSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n throw new Error('No client defined');\n }\n\n bulk(bulkOptions: {\n datasource: Readable;\n onDocument: (doc: any) => ElasticSearchIndexAction;\n refreshOnCompletion?: string | boolean;\n }) {\n if (this.openSearchClient) {\n return this.openSearchClient.helpers.bulk(bulkOptions);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.helpers.bulk(bulkOptions);\n }\n\n throw new Error('No client defined');\n }\n\n putIndexTemplate(template: ElasticSearchCustomIndexTemplate) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.putIndexTemplate(template);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.putIndexTemplate(template);\n }\n\n throw new Error('No client defined');\n }\n\n listIndices(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.get(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.get(options);\n }\n\n throw new Error('No client defined');\n }\n\n indexExists(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.exists(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.exists(options);\n }\n\n throw new Error('No client defined');\n }\n\n deleteIndex(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.delete(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.delete(options);\n }\n\n throw new Error('No client defined');\n }\n\n /**\n * @deprecated unused by the ElasticSearch Engine, will be removed in the future\n */\n getAliases(options: { aliases: string[] }) {\n const { aliases } = options;\n\n if (this.openSearchClient) {\n return this.openSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n throw new Error('No client defined');\n }\n\n createIndex(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.create(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.create(options);\n }\n\n throw new Error('No client defined');\n }\n\n updateAliases(options: { actions: ElasticSearchAliasAction[] }) {\n const filteredActions = options.actions.filter(Boolean);\n\n if (this.openSearchClient) {\n return this.openSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n throw new Error('No client defined');\n }\n}\n"],"names":["isOpenSearchCompatible","OpenSearchClient","ElasticSearchClient"],"mappings":";;;;;;AAoEO,MAAM,0BAAA,CAA2B;AAAA,EACrB,mBAAA;AAAA,EACA,gBAAA;AAAA,EAET,YAAY,OAAA,EAGjB;AACD,IAAA,IAAA,CAAK,mBAAmB,OAAA,CAAQ,gBAAA;AAChC,IAAA,IAAA,CAAK,sBAAsB,OAAA,CAAQ,mBAAA;AAAA,EACrC;AAAA,EAEA,OAAO,kBAAkB,OAAA,EAAqC;AAC5D,IAAA,IAAIA,iDAAA,CAAuB,OAAO,CAAA,EAAG;AACnC,MAAA,OAAO,IAAI,0BAAA,CAA2B;AAAA,QACpC,gBAAA,EA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AAqB;AAC5B,MAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,OAAA,CAAQ,aAAA,CAAc;AAAA,QACpD,IAAA,EAAM;AAAA,UACJ,OAAA,EAAS;AAAA;AACX,OACD,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,IAAI,MAAM,mBAAmB,CAAA;AAAA,EACrC;AACF;;;;"}
1
+ {"version":3,"file":"ElasticSearchClientWrapper.cjs.js","sources":["../../src/engines/ElasticSearchClientWrapper.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { Client as ElasticSearchClient } from '@elastic/elasticsearch';\nimport { Client as OpenSearchClient } from '@opensearch-project/opensearch';\nimport { Readable } from 'node:stream';\nimport {\n ElasticSearchClientOptions,\n isOpenSearchCompatible,\n} from './ElasticSearchClientOptions';\nimport { ElasticSearchCustomIndexTemplate } from './types';\n\n/**\n * @public\n */\nexport type ElasticSearchAliasAction =\n | {\n remove: { index: any; alias: any };\n add?: undefined;\n }\n | {\n add: { indices: any; alias: any; index?: undefined };\n remove?: undefined;\n }\n | {\n add: { index: any; alias: any; indices?: undefined };\n remove?: undefined;\n }\n | undefined;\n\n/**\n * @public\n */\nexport type ElasticSearchIndexAction = {\n index: {\n _index: string;\n [key: string]: any;\n };\n};\n\n/**\n * A wrapper class that exposes logical methods that are conditionally fired\n * against either a configured Elasticsearch client or a configured Opensearch\n * client.\n *\n * This is necessary because, despite its intention to be API-compatible, the\n * opensearch client does not support API key-based authentication. This is\n * also the sanest way to accomplish this while making typescript happy.\n *\n * In the future, if the differences between implementations become\n * unmaintainably divergent, we should split out the Opensearch and\n * Elasticsearch search engine implementations.\n *\n * @public\n */\nexport class ElasticSearchClientWrapper {\n private readonly elasticSearchClient: ElasticSearchClient | undefined;\n private readonly openSearchClient: OpenSearchClient | undefined;\n\n private constructor(options: {\n openSearchClient?: OpenSearchClient;\n elasticSearchClient?: ElasticSearchClient;\n }) {\n this.openSearchClient = options.openSearchClient;\n this.elasticSearchClient = options.elasticSearchClient;\n }\n\n static fromClientOptions(options: ElasticSearchClientOptions) {\n if (isOpenSearchCompatible(options)) {\n return new ElasticSearchClientWrapper({\n openSearchClient: new OpenSearchClient(options),\n });\n }\n\n return new ElasticSearchClientWrapper({\n elasticSearchClient: new ElasticSearchClient(options),\n });\n }\n\n search(options: { index: string | string[]; body: Object }) {\n const searchOptions = {\n ignore_unavailable: true,\n allow_no_indices: true,\n };\n\n if (this.openSearchClient) {\n return this.openSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n throw new Error('No client defined');\n }\n\n bulk(bulkOptions: {\n datasource: Readable;\n onDocument: (doc: any) => ElasticSearchIndexAction;\n refreshOnCompletion?: string | boolean;\n }) {\n if (this.openSearchClient) {\n return this.openSearchClient.helpers.bulk(bulkOptions);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.helpers.bulk(bulkOptions);\n }\n\n throw new Error('No client defined');\n }\n\n putIndexTemplate(template: ElasticSearchCustomIndexTemplate) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.putIndexTemplate(template);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.putIndexTemplate(template);\n }\n\n throw new Error('No client defined');\n }\n\n listIndices(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.get(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.get(options);\n }\n\n throw new Error('No client defined');\n }\n\n indexExists(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.exists(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.exists(options);\n }\n\n throw new Error('No client defined');\n }\n\n deleteIndex(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.delete(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.delete(options);\n }\n\n throw new Error('No client defined');\n }\n\n /**\n * @deprecated unused by the ElasticSearch Engine, will be removed in the future\n */\n getAliases(options: { aliases: string[] }) {\n const { aliases } = options;\n\n if (this.openSearchClient) {\n return this.openSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n throw new Error('No client defined');\n }\n\n createIndex(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.create(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.create(options);\n }\n\n throw new Error('No client defined');\n }\n\n updateAliases(options: { actions: ElasticSearchAliasAction[] }) {\n const filteredActions = options.actions.filter(Boolean);\n\n if (this.openSearchClient) {\n return this.openSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n throw new Error('No client defined');\n }\n}\n"],"names":["isOpenSearchCompatible","OpenSearchClient","ElasticSearchClient"],"mappings":";;;;;;AAoEO,MAAM,0BAAA,CAA2B;AAAA,EACrB,mBAAA;AAAA,EACA,gBAAA;AAAA,EAET,YAAY,OAAA,EAGjB;AACD,IAAA,IAAA,CAAK,mBAAmB,OAAA,CAAQ,gBAAA;AAChC,IAAA,IAAA,CAAK,sBAAsB,OAAA,CAAQ,mBAAA;AAAA,EACrC;AAAA,EAEA,OAAO,kBAAkB,OAAA,EAAqC;AAC5D,IAAA,IAAIA,i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M;AAAA,UACJ,OAAA,EAAS;AAAA;AACX,OACD,CAAA;AAAA,IACH;AAEA,IAAA,IAAI,KAAK,mBAAA,EAAqB;AAC5B,MAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,OAAA,CAAQ,aAAA,CAAc;AAAA,QACpD,IAAA,EAAM;AAAA,UACJ,OAAA,EAAS;AAAA;AACX,OACD,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,IAAI,MAAM,mBAAmB,CAAA;AAAA,EACrC;AACF;;;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var pluginSearchBackendNode = require('@backstage/plugin-search-backend-node');
4
- var stream = require('stream');
4
+ var node_stream = require('node:stream');
5
5
 
6
6
  function duration(startTimestamp) {
7
7
  const delta = process.hrtime(startTimestamp);
@@ -34,7 +34,7 @@ class ElasticSearchSearchEngineIndexer extends pluginSearchBackendNode.BatchSear
34
34
  this.indexName = this.constructIndexName(`${Date.now()}`);
35
35
  this.alias = options.alias;
36
36
  this.elasticSearchClientWrapper = options.elasticSearchClientWrapper;
37
- this.sourceStream = new stream.Readable({ objectMode: true });
37
+ this.sourceStream = new node_stream.Readable({ objectMode: true });
38
38
  this.sourceStream._read = () => {
39
39
  };
40
40
  const that = this;
@@ -1 +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 batchKeyField?: string;\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(doc) {\n that.processed++;\n return {\n index: { _index: that.indexName },\n ...(options.batchKeyField && doc[options.batchKeyField]\n ? { _id: doc[options.batchKeyField] }\n : {}),\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.indexName} of ${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.indexName} of ${\n this.type\n } in ${duration(this.startTimestamp)}`,\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":";;;;;AAsCA,SAAS,SAAS,cAAA,EAA0C;AAC1D,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,MAAA,CAAO,cAAc,CAAA;AAC3C,EAAA,MAAM,UAAU,KAAA,CAAM,CAAC,CAAA,GAAI,KAAA,CAAM,CAAC,CAAA,GAAI,GAAA;AACtC,EAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAC9B;AAMO,MAAM,yCAAyCA,gDAAA,CAAyB;AAAA,EACrE,SAAA,GAAoB,CAAA;AAAA,EACpB,mBAA6B,EAAC;AAAA,EAErB,cAAA;AAAA,EACA,IAAA;AAAA,EACD,SAAA;AAAA,EACC,WAAA;AAAA,EACA,cAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,0BAAA;AAAA,EACT,mBAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EAER,YAAY,OAAA,EAAkD;AAC5D,IAAA,KAAA,CAAM,EAAE,SAAA,EAAW,OAAA,CAAQ,SAAA,EAAW,CAAA;AACtC,IAAA,IAAA,CAAK,sBAAsB,OAAA,CAAQ,SAAA;AACnC,IAAA,IAAA,CAAK,MAAA,GAAS,QAAQ,MAAA,CAAO,KAAA,CAAM,EAAE,YAAA,EAAc,OAAA,CAAQ,MAAM,CAAA;AACjE,IAAA,IAAA,CAAK,cAAA,GAAiB,QAAQ,MAAA,EAAO;AACrC,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ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OAAA,EAAiB;AAC1C,IAAA,OAAO,CAAA,EAAG,IAAA,CAAK,WAAW,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAG,IAAA,CAAK,cAAc,CAAA,EAAG,OAAO,CAAA,CAAA;AAAA,EACxE;AACF;;;;"}
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 'node: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 batchKeyField?: string;\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(doc) {\n that.processed++;\n return {\n index: { _index: that.indexName },\n ...(options.batchKeyField && doc[options.batchKeyField]\n ? { _id: doc[options.batchKeyField] }\n : {}),\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.indexName} of ${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.indexName} of ${\n this.type\n } in ${duration(this.startTimestamp)}`,\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":";;;;;AAsCA,SAAS,SAAS,cAAA,EAA0C;AAC1D,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,MAAA,CAAO,cAAc,CAAA;AAC3C,EAAA,MAAM,UAAU,KAAA,CAAM,CAAC,CAAA,GAAI,KAAA,CAAM,CAAC,CAAA,GAAI,GAAA;AACtC,EAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,CAAA;AAC9B;AAMO,MAAM,yCAAyCA,gDAAA,CAAyB;AAAA,EACrE,SAAA,GAAoB,CAAA;AAAA,EACpB,mBAA6B,EAAC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;AAC/D,MAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,IACzB;AAIA,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,KAAA,KAAU;AACrC,MAAA,IAAI,kBAAA,GAAqB,CAAA;AACzB,MAAA,MAAM,QAAA,GAAW,YAAY,MAAM;AACjC,QAAA,kBAAA,EAAA;AAEA,QAAA,IAAI,IAAA,CAAK,YAAA,CAAa,cAAA,GAAiB,IAAA,CAAK,mBAAA,EAAqB;AAC/D,UAAA,aAAA,CAAc,QAAQ,CAAA;AACtB,UAAA,OAAA,EAAQ;AAAA,QACV;AAMA,QAAA,IAAI,sBAAsB,GAAA,EAAM;AAC9B,UAAA,aAAA,CAAc,QAAQ,CAAA;AACtB,UAAA,KAAA;AAAA,YACE,IAAI,KAAA;AAAA,cACF;AAAA;AACF,WACF;AAAA,QACF;AAAA,MACF,GAAG,EAAE,CAAA;AAAA,IACP,CAAC,CAAA;AAAA,EACH;AAAA,EAEQ,mBAAmB,OAAA,EAAiB;AAC1C,IAAA,OAAO,CAAA,EAAG,IAAA,CAAK,WAAW,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAG,IAAA,CAAK,cAAc,CAAA,EAAG,OAAO,CAAA,CAAA;AAAA,EACxE;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -3,13 +3,13 @@ import { LoggerService } from '@backstage/backend-plugin-api';
3
3
  import { IndexableDocument, SearchQuery, IndexableResultSet } from '@backstage/plugin-search-common';
4
4
  import { BatchSearchEngineIndexer, SearchEngine } from '@backstage/plugin-search-backend-node';
5
5
  import { Config } from '@backstage/config';
6
- import { ConnectionOptions } from 'tls';
6
+ import { ConnectionOptions } from 'node:tls';
7
7
  import * as _elastic_elasticsearch_lib_Helpers from '@elastic/elasticsearch/lib/Helpers';
8
8
  import * as _elastic_elasticsearch_lib_Transport from '@elastic/elasticsearch/lib/Transport';
9
9
  import * as _elastic_elasticsearch from '@elastic/elasticsearch';
10
10
  import * as _opensearch_project_opensearch_lib_Transport_js from '@opensearch-project/opensearch/lib/Transport.js';
11
11
  import * as _opensearch_project_opensearch from '@opensearch-project/opensearch';
12
- import { Readable } from 'stream';
12
+ import { Readable } from 'node:stream';
13
13
 
14
14
  /**
15
15
  * Typeguard to differentiate ElasticSearch client options which are compatible
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-search-backend-module-elasticsearch",
3
- "version": "1.7.9-next.1",
3
+ "version": "1.7.10-next.0",
4
4
  "description": "A module for the search backend that implements search using ElasticSearch",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -62,11 +62,11 @@
62
62
  "test": "backstage-cli package test"
63
63
  },
64
64
  "dependencies": {
65
- "@backstage/backend-plugin-api": "1.6.0-next.1",
65
+ "@backstage/backend-plugin-api": "1.7.0-next.0",
66
66
  "@backstage/config": "1.3.6",
67
- "@backstage/integration-aws-node": "0.1.19",
68
- "@backstage/plugin-search-backend-node": "1.4.0-next.1",
69
- "@backstage/plugin-search-common": "1.2.21",
67
+ "@backstage/integration-aws-node": "0.1.20-next.0",
68
+ "@backstage/plugin-search-backend-node": "1.4.1-next.0",
69
+ "@backstage/plugin-search-common": "1.2.22-next.0",
70
70
  "@elastic/elasticsearch": "^7.13.0",
71
71
  "@opensearch-project/opensearch": "^2.2.1",
72
72
  "aws4": "^1.12.0",
@@ -75,8 +75,8 @@
75
75
  "uuid": "^11.0.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@backstage/backend-test-utils": "1.10.2-next.1",
79
- "@backstage/cli": "0.35.0-next.2",
78
+ "@backstage/backend-test-utils": "1.10.4-next.0",
79
+ "@backstage/cli": "0.35.3-next.0",
80
80
  "@elastic/elasticsearch-mock": "^1.0.0",
81
81
  "@short.io/opensearch-mock": "^0.4.0",
82
82
  "@types/aws4": "^1.5.1"