Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES Client: use ClusterConnectionPool instead of WeightedConnectionPool #134628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 type { Logger } from '@kbn/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,
Comment on lines +38 to +39
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add an integration test here because:

  • Ihmo we shouldn't be testing the @elastic/elasticsearch behavior from Kibana tests
  • The test would be quite long (starting multiple ES nodes at least twice), and by nature, likely flaky

If we really want, I can add one though

});

instrumentEsQueryAndDeprecationLogger({ logger, client, type });
Expand Down