From 2f88cc8cd5489973d4b0244353c551e7bf58a6b4 Mon Sep 17 00:00:00 2001 From: Brandon Kobel Date: Wed, 6 Oct 2021 16:18:58 -0700 Subject: [PATCH] Reverting to legacy ES client behavior where maxSockets = Infinity (#113644) * Reverting to legacy ES client behavior where maxSockets = Infinity * Removing unnused type * Specifying keepAlive: true by default Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../client/client_config.test.ts | 33 ++++++++++++++++--- .../elasticsearch/client/client_config.ts | 9 +++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/core/server/elasticsearch/client/client_config.test.ts b/src/core/server/elasticsearch/client/client_config.test.ts index 7956bcc64ea2f..af8e2d64cb6a2 100644 --- a/src/core/server/elasticsearch/client/client_config.test.ts +++ b/src/core/server/elasticsearch/client/client_config.test.ts @@ -37,6 +37,19 @@ describe('parseClientOptions', () => { ); }); + it('specifies `headers.maxSockets` Infinity and `keepAlive` true by default', () => { + const config = createConfig({}); + + expect(parseClientOptions(config, false)).toEqual( + expect.objectContaining({ + agent: { + keepAlive: true, + maxSockets: Infinity, + }, + }) + ); + }); + describe('basic options', () => { it('`customHeaders` option', () => { const config = createConfig({ @@ -76,11 +89,21 @@ describe('parseClientOptions', () => { ); }); - it('`keepAlive` option', () => { - expect(parseClientOptions(createConfig({ keepAlive: true }), false)).toEqual( - expect.objectContaining({ agent: { keepAlive: true } }) - ); - expect(parseClientOptions(createConfig({ keepAlive: false }), false).agent).toBeUndefined(); + describe('`keepAlive option`', () => { + it('`keepAlive` is true', () => { + const options = parseClientOptions(createConfig({ keepAlive: true }), false); + expect(options.agent).toHaveProperty('keepAlive', true); + }); + + it('`keepAlive` is false', () => { + const options = parseClientOptions(createConfig({ keepAlive: false }), false); + expect(options.agent).toHaveProperty('keepAlive', false); + }); + + it('`keepAlive` is undefined', () => { + const options = parseClientOptions(createConfig({}), false); + expect(options.agent).toHaveProperty('keepAlive', true); + }); }); it('`sniffOnStart` options', () => { diff --git a/src/core/server/elasticsearch/client/client_config.ts b/src/core/server/elasticsearch/client/client_config.ts index a6b0891fc12dd..24c48012346da 100644 --- a/src/core/server/elasticsearch/client/client_config.ts +++ b/src/core/server/elasticsearch/client/client_config.ts @@ -59,6 +59,10 @@ export function parseClientOptions( // do not make assumption on user-supplied data content // fixes https://github.com/elastic/kibana/issues/101944 disablePrototypePoisoningProtection: true, + agent: { + maxSockets: Infinity, + keepAlive: config.keepAlive ?? true, + }, }; if (config.pingTimeout != null) { @@ -73,11 +77,6 @@ export function parseClientOptions( ? config.sniffInterval : getDurationAsMs(config.sniffInterval); } - if (config.keepAlive) { - clientOptions.agent = { - keepAlive: config.keepAlive, - }; - } if (!scoped) { if (config.username && config.password) {