Skip to content

Commit

Permalink
Allow to enable compression for communications with ES (#124009)
Browse files Browse the repository at this point in the history
* Allow to enable compression for communications with ES

* update generated doc

* fix types in test

* update another snapshot
  • Loading branch information
pgayvallet authored Feb 1, 2022
1 parent 4c826f2 commit 1eea7a3
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
# must be a positive integer.
#elasticsearch.requestTimeout: 30000

# Specifies whether Kibana should use compression for communications with elasticsearch
# Defaults to `false`.
#elasticsearch.compression: false

# List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
# headers, set this value to [] (an empty list).
#elasticsearch.requestHeadersWhitelist: [ authorization ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Configuration options to be used to create a [cluster client](./kibana-plugin-co
<b>Signature:</b>

```typescript
export declare type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
export declare type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'compression' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
pingTimeout?: ElasticsearchConfig['pingTimeout'] | ClientOptions['pingTimeout'];
requestTimeout?: ElasticsearchConfig['requestTimeout'] | ClientOptions['requestTimeout'];
ssl?: Partial<ElasticsearchConfig['ssl']>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [ElasticsearchConfig](./kibana-plugin-core-server.elasticsearchconfig.md) &gt; [compression](./kibana-plugin-core-server.elasticsearchconfig.compression.md)

## ElasticsearchConfig.compression property

Whether to use compression for communications with elasticsearch.

<b>Signature:</b>

```typescript
readonly compression: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export declare class ElasticsearchConfig
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [apiVersion](./kibana-plugin-core-server.elasticsearchconfig.apiversion.md) | | string | Version of the Elasticsearch (6.7, 7.1 or <code>master</code>) client will be connecting to. |
| [compression](./kibana-plugin-core-server.elasticsearchconfig.compression.md) | | boolean | Whether to use compression for communications with elasticsearch. |
| [customHeaders](./kibana-plugin-core-server.elasticsearchconfig.customheaders.md) | | ElasticsearchConfigType\['customHeaders'\] | Header names and values to send to Elasticsearch with every request. These headers cannot be overwritten by client-side headers and aren't affected by <code>requestHeadersWhitelist</code> configuration. |
| [healthCheckDelay](./kibana-plugin-core-server.elasticsearchconfig.healthcheckdelay.md) | | Duration | The interval between health check requests Kibana sends to the Elasticsearch. |
| [hosts](./kibana-plugin-core-server.elasticsearchconfig.hosts.md) | | string\[\] | Hosts that the client will connect to. If sniffing is enabled, this list will be used as seeds to discover the rest of your cluster. |
Expand Down
3 changes: 3 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ This value must be a positive integer. *Default: `30000`*
| Time in milliseconds for {es} to wait for responses from shards.
Set to 0 to disable. *Default: `30000`*

| `elasticsearch.compression:`
| Specifies whether {kib} should use compression for communications with {es}. *Default: `false`*

| `elasticsearch.sniffInterval:`
| Time in milliseconds between requests to check {es} for an updated list of
nodes. *Default: `false`*
Expand Down
15 changes: 14 additions & 1 deletion src/core/server/elasticsearch/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const createConfig = (
): ElasticsearchClientConfig => {
return {
customHeaders: {},
compression: false,
sniffOnStart: false,
sniffOnConnectionFault: false,
sniffInterval: false,
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('parseClientOptions', () => {
);
});

describe('`keepAlive option`', () => {
describe('`keepAlive` option', () => {
it('`keepAlive` is true', () => {
const options = parseClientOptions(createConfig({ keepAlive: true }), false);
expect(options.agent).toHaveProperty('keepAlive', true);
Expand All @@ -106,6 +107,18 @@ describe('parseClientOptions', () => {
});
});

describe('`compression` option', () => {
it('`compression` is true', () => {
const options = parseClientOptions(createConfig({ compression: true }), false);
expect(options.compression).toBe(true);
});

it('`compression` is false', () => {
const options = parseClientOptions(createConfig({ compression: false }), false);
expect(options.compression).toBe(false);
});
});

it('`sniffOnStart` options', () => {
expect(
parseClientOptions(
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/elasticsearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DEFAULT_HEADERS } from '../default_headers';
export type ElasticsearchClientConfig = Pick<
ElasticsearchConfig,
| 'customHeaders'
| 'compression'
| 'sniffOnStart'
| 'sniffOnConnectionFault'
| 'requestHeadersWhitelist'
Expand Down Expand Up @@ -63,6 +64,7 @@ export function parseClientOptions(
maxSockets: Infinity,
keepAlive: config.keepAlive ?? true,
},
compression: config.compression,
};

if (config.pingTimeout != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const createConfig = (
sniffOnStart: false,
sniffOnConnectionFault: false,
sniffInterval: false,
compression: false,
requestHeadersWhitelist: ['authorization'],
customHeaders: {},
hosts: ['http://localhost'],
Expand Down
1 change: 1 addition & 0 deletions src/core/server/elasticsearch/elasticsearch_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('set correct defaults', () => {
expect(configValue).toMatchInlineSnapshot(`
ElasticsearchConfig {
"apiVersion": "master",
"compression": false,
"customHeaders": Object {},
"healthCheckDelay": "PT2.5S",
"hosts": Array [
Expand Down
7 changes: 7 additions & 0 deletions src/core/server/elasticsearch/elasticsearch_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const configSchema = schema.object({
hosts: schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })], {
defaultValue: 'http://localhost:9200',
}),
compression: schema.boolean({ defaultValue: false }),
username: schema.maybe(
schema.string({
validate: (rawConfig) => {
Expand Down Expand Up @@ -297,6 +298,11 @@ export class ElasticsearchConfig {
*/
public readonly apiVersion: string;

/**
* Whether to use compression for communications with elasticsearch.
*/
public readonly compression: boolean;

/**
* Hosts that the client will connect to. If sniffing is enabled, this list will
* be used as seeds to discover the rest of your cluster.
Expand Down Expand Up @@ -399,6 +405,7 @@ export class ElasticsearchConfig {
this.password = rawConfig.password;
this.serviceAccountToken = rawConfig.serviceAccountToken;
this.customHeaders = rawConfig.customHeaders;
this.compression = rawConfig.compression;
this.skipStartupConnectionCheck = rawConfig.skipStartupConnectionCheck;

const { alwaysPresentCertificate, verificationMode } = rawConfig.ssl;
Expand Down
4 changes: 3 additions & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const config: {
sniffInterval: Type<false | Duration>;
sniffOnConnectionFault: Type<boolean>;
hosts: Type<string | string[]>;
compression: Type<boolean>;
username: Type<string | undefined>;
password: Type<string | undefined>;
serviceAccountToken: Type<string | undefined>;
Expand Down Expand Up @@ -878,7 +879,7 @@ export type ElasticsearchClient = Omit<KibanaClient, 'connectionPool' | 'transpo
};

// @public
export type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
export type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders' | 'compression' | 'sniffOnStart' | 'sniffOnConnectionFault' | 'requestHeadersWhitelist' | 'sniffInterval' | 'hosts' | 'username' | 'password' | 'serviceAccountToken'> & {
pingTimeout?: ElasticsearchConfig['pingTimeout'] | ClientOptions['pingTimeout'];
requestTimeout?: ElasticsearchConfig['requestTimeout'] | ClientOptions['requestTimeout'];
ssl?: Partial<ElasticsearchConfig['ssl']>;
Expand All @@ -890,6 +891,7 @@ export type ElasticsearchClientConfig = Pick<ElasticsearchConfig, 'customHeaders
export class ElasticsearchConfig {
constructor(rawConfig: ElasticsearchConfigType);
readonly apiVersion: string;
readonly compression: boolean;
// Warning: (ae-forgotten-export) The symbol "ElasticsearchConfigType" needs to be exported by the entry point index.d.ts
readonly customHeaders: ElasticsearchConfigType['customHeaders'];
readonly healthCheckDelay: Duration;
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 @@ -70,6 +70,7 @@ describe('config schema', () => {
"debug_mode": false,
"elasticsearch": Object {
"apiVersion": "master",
"compression": false,
"customHeaders": Object {},
"healthCheck": Object {
"delay": "PT2.5S",
Expand Down

0 comments on commit 1eea7a3

Please sign in to comment.