Skip to content

Commit 1a54071

Browse files
authored
ref(relay): Switch default envelope compression to zstd (#4531)
Relay supports accepting zstd for a while now, let's switch the default. This makes sending envelopes much more CPU efficient.
1 parent ad04adf commit 1a54071

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
**Features**:
66

7+
- Switch default envelope compression from gzip to zstd. ([#4531](https://github.com/getsentry/relay/pull/4531))
78
- Update release to include an aarch64 binary. ([#4514](https://github.com/getsentry/relay/pull/4514))
89
- Support span `category` inference from span attributes. ([#4509](https://github.com/getsentry/relay/pull/4509))
910
- Add option to control ourlogs ingestion. ([#4518](https://github.com/getsentry/relay/pull/4518))

relay-config/src/config.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,14 @@ pub struct Routing {
722722
}
723723

724724
/// Http content encoding for both incoming and outgoing web requests.
725-
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
725+
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
726726
#[serde(rename_all = "lowercase")]
727727
pub enum HttpEncoding {
728728
/// Identity function without no compression.
729729
///
730730
/// This is the default encoding and does not require the presence of the `content-encoding`
731731
/// HTTP header.
732+
#[default]
732733
Identity,
733734
/// Compression using a [zlib](https://en.wikipedia.org/wiki/Zlib) structure with
734735
/// [deflate](https://en.wikipedia.org/wiki/DEFLATE) encoding.
@@ -780,12 +781,6 @@ impl HttpEncoding {
780781
}
781782
}
782783

783-
impl Default for HttpEncoding {
784-
fn default() -> Self {
785-
Self::Identity
786-
}
787-
}
788-
789784
/// Controls authentication with upstream.
790785
#[derive(Serialize, Deserialize, Debug)]
791786
#[serde(default)]
@@ -830,7 +825,7 @@ pub struct Http {
830825
pub project_failure_interval: u64,
831826
/// Content encoding to apply to upstream store requests.
832827
///
833-
/// By default, Relay applies `gzip` content encoding to compress upstream requests. Compression
828+
/// By default, Relay applies `zstd` content encoding to compress upstream requests. Compression
834829
/// can be disabled to reduce CPU consumption, but at the expense of increased network traffic.
835830
///
836831
/// This setting applies to all store requests of SDK data, including events, transactions,
@@ -842,6 +837,7 @@ pub struct Http {
842837
/// - `deflate`: Compression using a zlib header with deflate encoding.
843838
/// - `gzip` (default): Compression using gzip.
844839
/// - `br`: Compression using the brotli algorithm.
840+
/// - `zstd`: Compression using the zstd algorithm.
845841
pub encoding: HttpEncoding,
846842
/// Submit metrics globally through a shared endpoint.
847843
///
@@ -863,7 +859,7 @@ impl Default for Http {
863859
outage_grace_period: DEFAULT_NETWORK_OUTAGE_GRACE_PERIOD,
864860
retry_delay: default_retry_delay(),
865861
project_failure_interval: default_project_failure_interval(),
866-
encoding: HttpEncoding::Gzip,
862+
encoding: HttpEncoding::Zstd,
867863
global_metrics: false,
868864
}
869865
}

tests/integration/fixtures/mini_sentry.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import copy
3-
import gzip
3+
import zstandard
44
import json
55
import os
66
import re
@@ -318,9 +318,13 @@ def store_internal_error_event():
318318
@app.route("/api/42/envelope/", methods=["POST"])
319319
def store_event():
320320
assert (
321-
flask_request.headers.get("Content-Encoding", "") == "gzip"
321+
flask_request.headers.get("Content-Encoding", "") == "zstd"
322322
), "Relay should always compress store requests"
323-
data = gzip.decompress(flask_request.data)
323+
324+
with zstandard.ZstdDecompressor().stream_reader(
325+
flask_request.data
326+
) as decompressor:
327+
data = decompressor.read()
324328

325329
assert (
326330
flask_request.headers.get("Content-Type") == "application/x-sentry-envelope"
@@ -454,8 +458,11 @@ def global_metrics():
454458
abort(403, "relay not registered")
455459

456460
encoding = flask_request.headers.get("Content-Encoding", "")
457-
assert encoding == "gzip", "Relay should always compress store requests"
458-
data = gzip.decompress(flask_request.data)
461+
assert encoding == "zstd", "Relay should always compress store requests"
462+
with zstandard.ZstdDecompressor().stream_reader(
463+
flask_request.data
464+
) as decompressor:
465+
data = decompressor.read()
459466

460467
metrics_batch = json.loads(data)["buckets"]
461468
sentry.captured_metrics.put(metrics_batch)

0 commit comments

Comments
 (0)