Skip to content

Commit

Permalink
Reverting to legacy ES client behavior where maxSockets = Infinity (e…
Browse files Browse the repository at this point in the history
…lastic#113644)

* Reverting to legacy ES client behavior where maxSockets = Infinity

* Removing unnused type

* Specifying keepAlive: true by default

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
kobelb and kibanamachine committed Oct 6, 2021
1 parent ea79572 commit 2f88cc8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
33 changes: 28 additions & 5 deletions src/core/server/elasticsearch/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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', () => {
Expand Down
9 changes: 4 additions & 5 deletions src/core/server/elasticsearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 2f88cc8

Please sign in to comment.