Skip to content

Commit

Permalink
[OE] Support compression for requests
Browse files Browse the repository at this point in the history
Support compressing traffic with `opensearch.compression: true`.

Also, set compression in the Node server and OpenSearch traffic for
CI.

Issue resolved:
#5296

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
  • Loading branch information
kavilla committed Apr 8, 2024
1 parent a0eaf84 commit fdc842b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/core/server/opensearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type OpenSearchClientConfig = Pick<
| 'username'
| 'password'
| 'disablePrototypePoisoningProtection'
| 'compression'
> & {
memoryCircuitBreaker?:
| OpenSearchConfig['memoryCircuitBreaker']
Expand Down Expand Up @@ -120,6 +121,10 @@ export function parseClientOptions(config: OpenSearchClientConfig, scoped: boole
clientOptions.disablePrototypePoisoningProtection = config.disablePrototypePoisoningProtection;
}

if (config.compression) {
clientOptions.compression = 'gzip';
}

return clientOptions;
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/server/opensearch/opensearch_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => [
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit fdc842b

Please sign in to comment.