From d2e943b63e6f7e99978a6507fb5459a17e259bbf Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Fri, 17 Jun 2022 11:14:58 +0200 Subject: [PATCH] ES Client: use `ClusterConnectionPool` (#134628) (cherry picked from commit 6decdc3b8216bef54d9c8b7855423d26bb58c071) # Conflicts: # src/core/server/elasticsearch/client/configure_client.ts --- .../client/configure_client.test.ts | 16 ++++++++++++++++ .../elasticsearch/client/configure_client.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/server/elasticsearch/client/configure_client.test.ts b/src/core/server/elasticsearch/client/configure_client.test.ts index b17b308294a20..29750febd72c3 100644 --- a/src/core/server/elasticsearch/client/configure_client.test.ts +++ b/src/core/server/elasticsearch/client/configure_client.test.ts @@ -17,6 +17,7 @@ import { ClientMock, } from './configure_client.test.mocks'; import { loggingSystemMock } from '../../logging/logging_system.mock'; +import { ClusterConnectionPool } from '@elastic/elasticsearch'; import type { ElasticsearchClientConfig } from './client_config'; import { configureClient } from './configure_client'; import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation'; @@ -112,6 +113,21 @@ describe('configureClient', () => { expect(client).toBe(ClientMock.mock.results[0].value); }); + it('constructs a client using `ClusterConnectionPool` for `ConnectionPool` ', () => { + const mockedTransport = { mockTransport: true }; + createTransportMock.mockReturnValue(mockedTransport); + + const client = configureClient(config, { logger, type: 'test', scoped: false }); + + expect(ClientMock).toHaveBeenCalledTimes(1); + expect(ClientMock).toHaveBeenCalledWith( + expect.objectContaining({ + ConnectionPool: ClusterConnectionPool, + }) + ); + expect(client).toBe(ClientMock.mock.results[0].value); + }); + it('calls instrumentEsQueryAndDeprecationLogger', () => { const client = configureClient(config, { logger, type: 'test', scoped: false }); diff --git a/src/core/server/elasticsearch/client/configure_client.ts b/src/core/server/elasticsearch/client/configure_client.ts index e1e4a1846852b..4f67235a3d96a 100644 --- a/src/core/server/elasticsearch/client/configure_client.ts +++ b/src/core/server/elasticsearch/client/configure_client.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { Client, HttpConnection } from '@elastic/elasticsearch'; +import { Client, HttpConnection, ClusterConnectionPool } from '@elastic/elasticsearch'; import { Logger } from '../../logging'; import { parseClientOptions, ElasticsearchClientConfig } from './client_config'; import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation'; @@ -35,6 +35,8 @@ export const configureClient = ( ...clientOptions, Transport: KibanaTransport, Connection: HttpConnection, + // using ClusterConnectionPool until https://github.com/elastic/elasticsearch-js/issues/1714 is addressed + ConnectionPool: ClusterConnectionPool, }); instrumentEsQueryAndDeprecationLogger({ logger, client, type });