Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Add an option for upstream content encoding #771

Merged
merged 2 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(config): Add an option for upstream content encoding
  • Loading branch information
jan-auer committed Sep 11, 2020
commit 73a9766c571a6d6f0e44154c51f67f01ed8dbb59
35 changes: 35 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,20 @@ impl Default for Limits {
}
}

/// Http content encoding for upstream store requests.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum HttpEncoding {
/// Identity function, no compression.
Identity,
/// Compression using a zlib header with deflate encoding.
Deflate,
/// Compression using gzip.
Gzip,
/// Compression using the brotli algorithm.
Br,
}

/// Controls authentication with upstream.
#[derive(Serialize, Deserialize, Debug)]
#[serde(default)]
Expand Down Expand Up @@ -539,6 +553,21 @@ struct Http {
/// attempts persist beyond the grace period, Relay suspends event submission and reverts into
/// authentication mode.
auth_grace_period: u64,
/// Content encoding to apply to upstream store requests.
///
/// By default, Relay applies `gzip` content encoding to compress upstream requests. Compression
/// can be disabled to reduce CPU consumption, but at the expense of increased network traffic.
///
/// This setting applies to all store requests of SDK data, including events, transactions,
/// envelopes and sessions. At the moment, this does not apply to Relay's internal queries.
///
/// Available options are:
///
/// - `identity`: Disables compression.
/// - `deflate`: Compression using a zlib header with deflate encoding.
/// - `gzip` (default): Compression using gzip.
/// - `br`: Compression using the brotli algorithm.
encoding: HttpEncoding,
}

impl Default for Http {
Expand All @@ -550,6 +579,7 @@ impl Default for Http {
host_header: None,
auth_interval: Some(600), // 10 minutes
auth_grace_period: 10,
encoding: HttpEncoding::Gzip,
}
}
}
Expand Down Expand Up @@ -1138,6 +1168,11 @@ impl Config {
Duration::from_secs(self.values.http.auth_grace_period)
}

/// Content encoding of upstream requests.
pub fn http_encoding(&self) -> HttpEncoding {
self.values.http.encoding
}

/// Returns whether this Relay should emit outcomes.
///
/// This is `true` either if `outcomes.emit_outcomes` is explicitly enabled, or if this Relay is
Expand Down
12 changes: 10 additions & 2 deletions relay-server/src/actors/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use parking_lot::RwLock;
use serde_json::Value as SerdeValue;

use relay_common::{clone, metric, LogError};
use relay_config::{Config, RelayMode};
use relay_config::{Config, HttpEncoding, RelayMode};
use relay_general::pii::{PiiAttachmentsProcessor, PiiProcessor};
use relay_general::processor::{process_value, ProcessingState};
use relay_general::protocol::{
Expand Down Expand Up @@ -1331,6 +1331,7 @@ impl Handler<HandleEnvelope> for EventManager {
let outcome_producer = self.outcome_producer.clone();
let captured_events = self.captured_events.clone();
let capture = self.config.relay_mode() == RelayMode::Capture;
let http_encoding = self.config.http_encoding();

#[cfg(feature = "processing")]
let store_forwarder = self.store_forwarder.clone();
Expand Down Expand Up @@ -1452,11 +1453,18 @@ impl Handler<HandleEnvelope> for EventManager {
builder.header("User-Agent", user_agent);
}

let content_encoding = match http_encoding {
HttpEncoding::Identity => ContentEncoding::Identity,
HttpEncoding::Deflate => ContentEncoding::Deflate,
HttpEncoding::Gzip => ContentEncoding::Gzip,
HttpEncoding::Br => ContentEncoding::Br,
};

builder
.content_encoding(content_encoding)
.header("X-Sentry-Auth", meta.auth_header())
.header("X-Forwarded-For", meta.forwarded_for())
.header("Content-Type", envelope::CONTENT_TYPE)
.content_encoding(ContentEncoding::Gzip)
.body(envelope.to_vec().map_err(failure::Error::from)?)
},
);
Expand Down