Skip to content

Commit

Permalink
Revert "Add zstd encoding support (#533)" (#543)
Browse files Browse the repository at this point in the history
This reverts commit 692dda6.
  • Loading branch information
andre-statsig authored Jan 28, 2025
1 parent 87b1f68 commit 6d55b5a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 471 deletions.
394 changes: 8 additions & 386 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"homepage": "https://www.statsig.com",
"dependencies": {
"@mongodb-js/zstd": "^2.0.0",
"ip3country": "^5.0.0",
"node-fetch": "^2.6.13",
"ua-parser-js": "^1.0.2",
Expand All @@ -53,11 +52,11 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"sha.js": "^2.4.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdoc-to-markdown": "^7.1.1",
"prettier": "^3.1.1",
"sha.js": "^2.4.11",
"typescript": "^4.7.4"
},
"importSort": {
Expand Down
27 changes: 3 additions & 24 deletions src/LogEventProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ import ErrorBoundary from './ErrorBoundary';
import { EvaluationDetails } from './EvaluationDetails';
import LogEvent, { LogEventData, SecondaryExposure } from './LogEvent';
import OutputLogger from './OutputLogger';
import SDKConfigs from './SDKConfigs';
import SDKFlags from './SDKFlags';
import { ExplicitStatsigOptions, StatsigOptions } from './StatsigOptions';
import { StatsigUser } from './StatsigUser';
import { getStatsigMetadata, poll } from './utils/core';
import {
CompressionType,
isValidCompressionType,
} from './utils/getEncodedBody';
import { GlobalContext, StatsigContext } from './utils/StatsigContext';
import StatsigFetcher from './utils/StatsigFetcher';

Expand Down Expand Up @@ -120,7 +115,9 @@ export default class LogEventProcessor {
retries: fireAndForget ? 0 : this.explicitOptions.postLogsRetryLimit,
backoff: this.explicitOptions.postLogsRetryBackoff,
signal: abortSignal,
compression: this.getLogEventCompression(),
compress:
!GlobalContext.isEdgeEnvironment &&
SDKFlags.on('stop_log_event_compression') === false,
additionalHeaders: {
'STATSIG-EVENT-COUNT': String(oldQueue.length),
},
Expand Down Expand Up @@ -509,22 +506,4 @@ export default class LogEventProcessor {
}
Diagnostics.instance.clearMarker(context);
}

private getLogEventCompression(): CompressionType {
if (
GlobalContext.isEdgeEnvironment ||
SDKFlags.on('stop_log_event_compression') === true
) {
return 'none';
}

// Validation of dynamic config value
const config = SDKConfigs.get('event_content_encoding');
if (isValidCompressionType(config)) {
return config;
}

// Default value
return 'gzip';
}
}
13 changes: 0 additions & 13 deletions src/SDKConfigs.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/SpecStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
IDataAdapter,
} from './interfaces/IDataAdapter';
import OutputLogger from './OutputLogger';
import SDKConfigs from './SDKConfigs';
import SDKFlags from './SDKFlags';
import {
ExplicitStatsigOptions,
Expand Down Expand Up @@ -571,7 +570,6 @@ export default class SpecStore {
}

SDKFlags.setFlags(specsJSON?.sdk_flags);
SDKConfigs.setConfigs(specsJSON?.sdk_configs);

const updatedExpToLayer: Record<string, string> =
this._reverseLayerExperimentMapping(layerToExperimentMap);
Expand Down
23 changes: 0 additions & 23 deletions src/__tests__/SDKConfigs.test.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/utils/StatsigFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../StatsigOptions';
import { getSDKType, getSDKVersion } from './core';
import Dispatcher from './Dispatcher';
import { CompressionType, getEncodedBody } from './getEncodedBody';
import { getEncodedBody } from './getEncodedBody';
import { djb2Hash } from './Hashing';
import safeFetch from './safeFetch';
import { StatsigContext } from './StatsigContext';
Expand All @@ -27,7 +27,7 @@ type RequestOptions = Partial<{
backoff: number | RetryBackoffFunc;
isRetrying: boolean;
signal: AbortSignal;
compression?: CompressionType;
compress?: boolean;
additionalHeaders?: Record<string, string>;
}>;

Expand Down Expand Up @@ -133,7 +133,7 @@ export default class StatsigFetcher {
backoff = 1000,
isRetrying = false,
signal,
compression = 'none',
compress = false,
} = options ?? {};
const markDiagnostic = this.getDiagnosticFromURL(url);
if (this.localMode) {
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class StatsigFetcher {

const { contents, contentEncoding } = await getEncodedBody(
body,
compression,
compress ? 'gzip' : 'none',
this.errorBoundry,
);

Expand Down
18 changes: 1 addition & 17 deletions src/utils/getEncodedBody.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import ErrorBoundary from '../ErrorBoundary';
import { StatsigContext } from './StatsigContext';

export function isValidCompressionType(
input: unknown,
): input is CompressionType {
return (
typeof input === 'string' &&
(VALID_COMPRESSION_TYPES as ReadonlyArray<string>).includes(input)
);
}

const VALID_COMPRESSION_TYPES = ['gzip', 'zstd', 'none'] as const;
export type CompressionType = (typeof VALID_COMPRESSION_TYPES)[number];
export type CompressionType = 'gzip' | 'none';

export async function getEncodedBody(
body: Record<string, unknown> | undefined,
Expand All @@ -34,12 +24,6 @@ export async function getEncodedBody(
});
return { contents: compressed, contentEncoding: 'gzip' };
}

if (compression === 'zstd') {
const { compress } = await import('@mongodb-js/zstd');
const compressed = await compress(Buffer.from(bodyString, 'utf8'));
return { contents: compressed, contentEncoding: 'zstd' };
}
} catch (e) {
errorBoundry.logError(
e,
Expand Down

0 comments on commit 6d55b5a

Please sign in to comment.