Skip to content

Commit

Permalink
[Elasticsearch Client] Limit Kibana's internal client's maxSockets
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Feb 21, 2023
1 parent 64a5b97 commit 0b8a573
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const configSchema = schema.object({
defaultValue: 'http://localhost:9200',
}),
maxSockets: schema.number({ defaultValue: Infinity, min: 1 }),
internalClientMaxSockets: schema.number({ defaultValue: 500, min: 1 }),
maxIdleSockets: schema.number({ defaultValue: 256, min: 1 }),
idleSocketTimeout: schema.duration({ defaultValue: '60s' }),
compression: schema.boolean({ defaultValue: false }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,19 @@ export class ElasticsearchService
this.log.debug('Setting up elasticsearch service');

const config = await firstValueFrom(this.config$);
const internalClientMaxSockets = await firstValueFrom(
this.coreContext.configService
.atPath<ElasticsearchConfigType>('elasticsearch')
.pipe(map((rawConfig) => rawConfig.internalClientMaxSockets))
);

this.authHeaders = deps.http.authRequestHeaders;
this.executionContextClient = deps.executionContext;
this.client = this.createClusterClient('data', config);
this.client = this.createClusterClient('data', {
...config,
maxSockets:
config.maxSockets > internalClientMaxSockets ? internalClientMaxSockets : config.maxSockets,
});

const esNodesCompatibility$ = pollEsNodesVersion({
internalClient: this.client.asInternalUser,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('config schema', () => {
},
"idleSocketTimeout": "PT1M",
"ignoreVersionMismatch": false,
"internalClientMaxSockets": 500,
"logFetchCount": 10,
"logQueries": false,
"maxIdleSockets": 256,
Expand Down

0 comments on commit 0b8a573

Please sign in to comment.