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 relay configuration for detecting canary #3938

Merged
merged 11 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Keep frames from both ends of the stacktrace when trimming frames. ([#3905](https://github.com/getsentry/relay/pull/3905))

**Features**:

- Add configuration option to specify the deployment type of Relay. ([#3938](https://github.com/getsentry/relay/pull/3938))

## 24.8.0

**Bug Fixes**:
Expand Down
54 changes: 54 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ trait ConfigObject: DeserializeOwned + Serialize {
pub struct OverridableConfig {
/// The operation mode of this relay.
pub mode: Option<String>,
/// The deployment of this relay.
pub deployment: Option<String>,
Dav1dde marked this conversation as resolved.
Show resolved Hide resolved
/// The log level of this relay.
pub log_level: Option<String>,
/// The upstream relay or sentry instance.
Expand Down Expand Up @@ -352,6 +354,44 @@ impl fmt::Display for RelayMode {
}
}

/// The deployment type of Relay.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum RelayDeployment {
/// This Relay is run in a default deployment.
Default,

/// This Relay is run in a canary deployment where experiments can be run.
Canary,
}

impl RelayDeployment {
/// Returns `true` if the [`RelayDeployment`] is of type [`RelayDeployment::Canary`].
pub fn is_canary(&self) -> bool {
matches!(self, RelayDeployment::Canary)
}
}

impl fmt::Display for RelayDeployment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RelayDeployment::Default => write!(f, "default"),
RelayDeployment::Canary => write!(f, "canary"),
}
}
}

impl FromStr for RelayDeployment {
type Err = fmt::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"canary" => Ok(RelayDeployment::Canary),
_ => Ok(RelayDeployment::Default),
}
}
}

/// Error returned when parsing an invalid [`RelayMode`].
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ParseRelayModeError;
Expand Down Expand Up @@ -436,6 +476,8 @@ impl Default for ReadinessCondition {
pub struct Relay {
/// The operation mode of this relay.
pub mode: RelayMode,
/// The deployment of this relay.
pub deployment: RelayDeployment,
/// The upstream relay or sentry instance.
pub upstream: UpstreamDescriptor<'static>,
/// The host the relay should bind to (network interface).
Expand Down Expand Up @@ -463,6 +505,7 @@ impl Default for Relay {
fn default() -> Self {
Relay {
mode: RelayMode::Managed,
deployment: RelayDeployment::Default,
upstream: "https://sentry.io/".parse().unwrap(),
host: default_host(),
port: 3000,
Expand Down Expand Up @@ -1607,6 +1650,12 @@ impl Config {
.with_context(|| ConfigError::field("mode"))?;
}

if let Some(deployment) = overrides.deployment {
relay.deployment = deployment
.parse::<RelayDeployment>()
.with_context(|| ConfigError::field("deployment"))?;
}

if let Some(log_level) = overrides.log_level {
self.values.logging.level = log_level.parse()?;
}
Expand Down Expand Up @@ -1820,6 +1869,11 @@ impl Config {
self.values.relay.mode
}

/// Returns the relay deployment.
pub fn relay_deployment(&self) -> RelayDeployment {
self.values.relay.deployment
}

/// Returns the upstream target as descriptor.
pub fn upstream_descriptor(&self) -> &UpstreamDescriptor<'_> {
&self.values.relay.upstream
Expand Down
2 changes: 2 additions & 0 deletions relay/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn extract_config_args(matches: &ArgMatches) -> OverridableConfig {
secret_key: matches.get_one("secret_key").cloned(),
outcome_source: matches.get_one("source_id").cloned(),
shutdown_timeout: matches.get_one("shutdown_timeout").cloned(),
deployment: matches.get_one("deployment").cloned(),
}
}

Expand All @@ -117,6 +118,7 @@ pub fn extract_config_env_vars() -> OverridableConfig {
secret_key: env::var("RELAY_SECRET_KEY").ok(),
outcome_source: None, //already extracted in params
shutdown_timeout: env::var("SHUTDOWN_TIMEOUT").ok(),
deployment: env::var("RELAY_DEPLOYMENT").ok(),
}
}

Expand Down
5 changes: 5 additions & 0 deletions relay/src/cliapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ pub fn make_app() -> Command {
"Maximum number of seconds to wait for pending envelopes on shutdown.",
),
)
.arg(
Arg::new("deployment")
.long("deployment")
.help("The deployment type of this Relay.")
)
)
.subcommand(
Command::new("credentials")
Expand Down
Loading