Skip to content

Commit

Permalink
ES Client: use ClusterConnectionPool (elastic#134628)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6decdc3)

# Conflicts:
#	src/core/server/elasticsearch/client/configure_client.ts
  • Loading branch information
pgayvallet committed Jun 17, 2022
1 parent 962d241 commit a3d8b40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/core/server/elasticsearch/client/configure_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });

Expand Down
4 changes: 3 additions & 1 deletion src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit a3d8b40

Please sign in to comment.