diff --git a/src/core/server/opensearch/client/cluster_client.ts b/src/core/server/opensearch/client/cluster_client.ts index b29eea89d4db..ac2348921658 100644 --- a/src/core/server/opensearch/client/cluster_client.ts +++ b/src/core/server/opensearch/client/cluster_client.ts @@ -101,7 +101,7 @@ export class ClusterClient implements ICustomClusterClient { return; } this.isClosed = true; - await Promise.all([this.asInternalUser.close(), this.rootScopedClient.close()]); + await Promise.all([this.asInternalUser.close(noop), this.rootScopedClient.close(noop)]); } private getScopedHeaders(request: ScopeableRequest): Headers { diff --git a/src/core/server/opensearch/opensearch_config.ts b/src/core/server/opensearch/opensearch_config.ts index fee26c354fbe..7ef3a7665a97 100644 --- a/src/core/server/opensearch/opensearch_config.ts +++ b/src/core/server/opensearch/opensearch_config.ts @@ -53,7 +53,7 @@ export const configSchema = schema.object({ defaultValue: false, }), sniffOnConnectionFault: schema.boolean({ defaultValue: false }), - hosts: schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })], { + hosts: schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema)], { defaultValue: 'http://localhost:9200', }), username: schema.maybe( diff --git a/src/core/server/opensearch/opensearch_service.test.ts b/src/core/server/opensearch/opensearch_service.test.ts index d5d354f9df86..1280479314a6 100644 --- a/src/core/server/opensearch/opensearch_service.test.ts +++ b/src/core/server/opensearch/opensearch_service.test.ts @@ -266,6 +266,30 @@ describe('#setup', () => { expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); }); }); + + it('opensearchNodeVersionCompatibility$ avoid polling when opensearch hosts is empty', async () => { + const mockedClient = mockClusterClientInstance.asInternalUser; + configService.atPath.mockReturnValueOnce( + new BehaviorSubject({ + hosts: [], + healthCheck: { + delay: duration(2000), + }, + ssl: { + verificationMode: 'none', + }, + } as any) + ); + opensearchService = new OpenSearchService(coreContext); + const setupContract = await opensearchService.setup(setupDeps); + + // reset all mocks called during setup phase + MockLegacyClusterClient.mockClear(); + + setupContract.opensearchNodesCompatibility$.subscribe(async () => { + expect(mockedClient.nodes.info).toHaveBeenCalledTimes(0); + }); + }); }); describe('#start', () => { diff --git a/src/core/server/opensearch/opensearch_service.ts b/src/core/server/opensearch/opensearch_service.ts index 87a2da974ba1..bab3e7ede9f3 100644 --- a/src/core/server/opensearch/opensearch_service.ts +++ b/src/core/server/opensearch/opensearch_service.ts @@ -28,7 +28,7 @@ * under the License. */ -import { Observable, Subject } from 'rxjs'; +import { Observable, Subject, of } from 'rxjs'; import { first, map, shareReplay, takeUntil } from 'rxjs/operators'; import { merge } from '@osd/std'; @@ -91,14 +91,26 @@ export class OpenSearchService this.legacyClient = this.createLegacyClusterClient('data', config); this.client = this.createClusterClient('data', config); - const opensearchNodesCompatibility$ = pollOpenSearchNodesVersion({ - internalClient: this.client.asInternalUser, - optimizedHealthcheck: config.optimizedHealthcheck, - log: this.log, - ignoreVersionMismatch: config.ignoreVersionMismatch, - opensearchVersionCheckInterval: config.healthCheckDelay.asMilliseconds(), - opensearchDashboardsVersion: this.opensearchDashboardsVersion, - }).pipe(takeUntil(this.stop$), shareReplay({ refCount: true, bufferSize: 1 })); + let opensearchNodesCompatibility$; + if (config.hosts.length > 0) { + opensearchNodesCompatibility$ = pollOpenSearchNodesVersion({ + internalClient: this.client.asInternalUser, + optimizedHealthcheck: config.optimizedHealthcheck, + log: this.log, + ignoreVersionMismatch: config.ignoreVersionMismatch, + opensearchVersionCheckInterval: config.healthCheckDelay.asMilliseconds(), + opensearchDashboardsVersion: this.opensearchDashboardsVersion, + }).pipe(takeUntil(this.stop$), shareReplay({ refCount: true, bufferSize: 1 })); + } else { + this.log.debug(`Opensearch is not configured.`); + opensearchNodesCompatibility$ = of({ + isCompatible: true, + message: 'Opensearch is not configured', + incompatibleNodes: [], + warningNodes: [], + opensearchDashboardsVersion: this.opensearchDashboardsVersion, + }); + } this.createLegacyCustomClient = (type, clientConfig = {}) => { const finalConfig = merge({}, config, clientConfig); diff --git a/src/core/server/opensearch/status.ts b/src/core/server/opensearch/status.ts index 6b5d2741b405..87eda3a8893f 100644 --- a/src/core/server/opensearch/status.ts +++ b/src/core/server/opensearch/status.ts @@ -77,7 +77,7 @@ export const calculateStatus$ = ( return { level: ServiceStatusLevels.available, - summary: `OpenSearch is available`, + summary: (message ?? `OpenSearch is available`) || `Unknown`, meta: { warningNodes: [], incompatibleNodes: [],