From e3b9e8ffd12f7242a5a02494d782fde3b9a3a8f2 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Mon, 8 Apr 2024 11:11:02 +0000 Subject: [PATCH 1/3] [OE] Support compression for requests Support compressing traffic with `opensearch.compression: true`. Also, set compression in the Node server and OpenSearch traffic for CI. Issue resolved: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5296 Signed-off-by: Kawika Avilla --- .github/workflows/cypress_workflow.yml | 2 +- src/core/server/opensearch/client/client_config.ts | 5 +++++ src/core/server/opensearch/opensearch_config.test.ts | 1 + src/core/server/opensearch/opensearch_config.ts | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cypress_workflow.yml b/.github/workflows/cypress_workflow.yml index ac5d54bb7a2d..a4507d8bff55 100644 --- a/.github/workflows/cypress_workflow.yml +++ b/.github/workflows/cypress_workflow.yml @@ -30,7 +30,7 @@ env: TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || 'opensearch-project/opensearch-dashboards-functional-test' }} TEST_BRANCH: "${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}" FTR_PATH: 'ftr' - START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false' + START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false --server.compression.enabled=true --opensearch.compression=true' OPENSEARCH_SNAPSHOT_CMD: 'node ../scripts/opensearch snapshot -E cluster.routing.allocation.disk.threshold_enabled=false' CYPRESS_BROWSER: 'chromium' CYPRESS_VISBUILDER_ENABLED: true diff --git a/src/core/server/opensearch/client/client_config.ts b/src/core/server/opensearch/client/client_config.ts index 0432bb8ddfd6..f53c9529a741 100644 --- a/src/core/server/opensearch/client/client_config.ts +++ b/src/core/server/opensearch/client/client_config.ts @@ -53,6 +53,7 @@ export type OpenSearchClientConfig = Pick< | 'username' | 'password' | 'disablePrototypePoisoningProtection' + | 'compression' > & { memoryCircuitBreaker?: | OpenSearchConfig['memoryCircuitBreaker'] @@ -120,6 +121,10 @@ export function parseClientOptions(config: OpenSearchClientConfig, scoped: boole clientOptions.disablePrototypePoisoningProtection = config.disablePrototypePoisoningProtection; } + if (config.compression) { + clientOptions.compression = 'gzip'; + } + return clientOptions; } diff --git a/src/core/server/opensearch/opensearch_config.test.ts b/src/core/server/opensearch/opensearch_config.test.ts index d7a17c12d293..9d25a95b3028 100644 --- a/src/core/server/opensearch/opensearch_config.test.ts +++ b/src/core/server/opensearch/opensearch_config.test.ts @@ -71,6 +71,7 @@ test('set correct defaults', () => { expect(configValue).toMatchInlineSnapshot(` OpenSearchConfig { "apiVersion": "7.x", + "compression": undefined, "customHeaders": Object {}, "disablePrototypePoisoningProtection": undefined, "healthCheckDelay": "PT2.5S", diff --git a/src/core/server/opensearch/opensearch_config.ts b/src/core/server/opensearch/opensearch_config.ts index ba63e7350753..20800b8646fd 100644 --- a/src/core/server/opensearch/opensearch_config.ts +++ b/src/core/server/opensearch/opensearch_config.ts @@ -131,6 +131,7 @@ export const configSchema = schema.object({ healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), ignoreVersionMismatch: schema.boolean({ defaultValue: false }), disablePrototypePoisoningProtection: schema.maybe(schema.boolean({ defaultValue: false })), + compression: schema.maybe(schema.boolean({ defaultValue: false })), }); const deprecations: ConfigDeprecationProvider = ({ renameFromRoot, renameFromRootWithoutMap }) => [ @@ -313,6 +314,12 @@ export class OpenSearchConfig { */ public readonly disablePrototypePoisoningProtection?: boolean; + /** + * Specifies whether the client should use compression to engine + * or not. + */ + public readonly compression?: boolean; + constructor(rawConfig: OpenSearchConfigType) { this.ignoreVersionMismatch = rawConfig.ignoreVersionMismatch; this.apiVersion = rawConfig.apiVersion; @@ -334,6 +341,7 @@ export class OpenSearchConfig { this.password = rawConfig.password; this.customHeaders = rawConfig.customHeaders; this.disablePrototypePoisoningProtection = rawConfig.disablePrototypePoisoningProtection; + this.compression = rawConfig.compression; const { alwaysPresentCertificate, verificationMode } = rawConfig.ssl; const { key, keyPassphrase, certificate, certificateAuthorities } = readKeyAndCerts(rawConfig); From 0b166e89ee24ed2c1ac906a7c88e9ebca1696988 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Thu, 2 May 2024 03:28:52 +0000 Subject: [PATCH 2/3] address comments Signed-off-by: Kawika Avilla --- .../server/opensearch/client/client_config.ts | 2 +- src/core/server/opensearch/opensearch_config.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/server/opensearch/client/client_config.ts b/src/core/server/opensearch/client/client_config.ts index f53c9529a741..7fff839c4d97 100644 --- a/src/core/server/opensearch/client/client_config.ts +++ b/src/core/server/opensearch/client/client_config.ts @@ -122,7 +122,7 @@ export function parseClientOptions(config: OpenSearchClientConfig, scoped: boole } if (config.compression) { - clientOptions.compression = 'gzip'; + clientOptions.compression = config.compression; } return clientOptions; diff --git a/src/core/server/opensearch/opensearch_config.ts b/src/core/server/opensearch/opensearch_config.ts index 20800b8646fd..55b62c845696 100644 --- a/src/core/server/opensearch/opensearch_config.ts +++ b/src/core/server/opensearch/opensearch_config.ts @@ -32,12 +32,14 @@ import { schema, TypeOf } from '@osd/config-schema'; import { Duration } from 'moment'; import { readFileSync } from 'fs'; import { ConfigDeprecationProvider } from 'src/core/server'; +import { ClientOptions } from '@opensearch-project/opensearch'; import { readPkcs12Keystore, readPkcs12Truststore } from '../utils'; import { ServiceConfigDescriptor } from '../internal_types'; const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); export const DEFAULT_API_VERSION = '7.x'; +export const DEFAULT_COMPRESSION = 'gzip'; export type OpenSearchConfigType = TypeOf; type SslConfigSchema = OpenSearchConfigType['ssl']; @@ -131,7 +133,9 @@ export const configSchema = schema.object({ healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), ignoreVersionMismatch: schema.boolean({ defaultValue: false }), disablePrototypePoisoningProtection: schema.maybe(schema.boolean({ defaultValue: false })), - compression: schema.maybe(schema.boolean({ defaultValue: false })), + compression: schema.maybe( + schema.oneOf([schema.literal(DEFAULT_COMPRESSION), schema.boolean({ defaultValue: false })]) + ), }); const deprecations: ConfigDeprecationProvider = ({ renameFromRoot, renameFromRootWithoutMap }) => [ @@ -318,7 +322,7 @@ export class OpenSearchConfig { * Specifies whether the client should use compression to engine * or not. */ - public readonly compression?: boolean; + public readonly compression?: ClientOptions['compression']; constructor(rawConfig: OpenSearchConfigType) { this.ignoreVersionMismatch = rawConfig.ignoreVersionMismatch; @@ -341,7 +345,12 @@ export class OpenSearchConfig { this.password = rawConfig.password; this.customHeaders = rawConfig.customHeaders; this.disablePrototypePoisoningProtection = rawConfig.disablePrototypePoisoningProtection; - this.compression = rawConfig.compression; + this.compression = + typeof rawConfig.compression === 'boolean' && rawConfig.compression + ? DEFAULT_COMPRESSION + : typeof rawConfig.compression === 'string' + ? rawConfig.compression + : undefined; const { alwaysPresentCertificate, verificationMode } = rawConfig.ssl; const { key, keyPassphrase, certificate, certificateAuthorities } = readKeyAndCerts(rawConfig); From 840f186a7443b3c833ef8b9a672a2018648be4aa Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Thu, 2 May 2024 03:32:53 +0000 Subject: [PATCH 3/3] Changeset file for PR #6366 created/updated --- changelogs/fragments/6366.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/6366.yml diff --git a/changelogs/fragments/6366.yml b/changelogs/fragments/6366.yml new file mode 100644 index 000000000000..31543d235258 --- /dev/null +++ b/changelogs/fragments/6366.yml @@ -0,0 +1,2 @@ +feat: +- Support compressing traffic with `opensearch.compression: true` or `opensearch.compress: 'gzip'` ([#6366](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6366)) \ No newline at end of file