diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c1eff8df..36850b9bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 instance type of Relay. ([#3938](https://github.com/getsentry/relay/pull/3938)) + ## 24.8.0 **Bug Fixes**: diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 88d9269398..5ad262d7f5 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -222,6 +222,8 @@ trait ConfigObject: DeserializeOwned + Serialize { pub struct OverridableConfig { /// The operation mode of this relay. pub mode: Option, + /// The instance type of this relay. + pub instance: Option, /// The log level of this relay. pub log_level: Option, /// The upstream relay or sentry instance. @@ -352,6 +354,44 @@ impl fmt::Display for RelayMode { } } +/// The instance type of Relay. +#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub enum RelayInstance { + /// This Relay is run as a default instance. + Default, + + /// This Relay is run as a canary instance where experiments can be run. + Canary, +} + +impl RelayInstance { + /// Returns `true` if the [`RelayInstance`] is of type [`RelayInstance::Canary`]. + pub fn is_canary(&self) -> bool { + matches!(self, RelayInstance::Canary) + } +} + +impl fmt::Display for RelayInstance { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + RelayInstance::Default => write!(f, "default"), + RelayInstance::Canary => write!(f, "canary"), + } + } +} + +impl FromStr for RelayInstance { + type Err = fmt::Error; + + fn from_str(s: &str) -> Result { + match s { + "canary" => Ok(RelayInstance::Canary), + _ => Ok(RelayInstance::Default), + } + } +} + /// Error returned when parsing an invalid [`RelayMode`]. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct ParseRelayModeError; @@ -436,6 +476,8 @@ impl Default for ReadinessCondition { pub struct Relay { /// The operation mode of this relay. pub mode: RelayMode, + /// The instance type of this relay. + pub instance: RelayInstance, /// The upstream relay or sentry instance. pub upstream: UpstreamDescriptor<'static>, /// The host the relay should bind to (network interface). @@ -463,6 +505,7 @@ impl Default for Relay { fn default() -> Self { Relay { mode: RelayMode::Managed, + instance: RelayInstance::Default, upstream: "https://sentry.io/".parse().unwrap(), host: default_host(), port: 3000, @@ -1607,6 +1650,12 @@ impl Config { .with_context(|| ConfigError::field("mode"))?; } + if let Some(deployment) = overrides.instance { + relay.instance = deployment + .parse::() + .with_context(|| ConfigError::field("deployment"))?; + } + if let Some(log_level) = overrides.log_level { self.values.logging.level = log_level.parse()?; } @@ -1820,6 +1869,11 @@ impl Config { self.values.relay.mode } + /// Returns the instance type of relay. + pub fn relay_instance(&self) -> RelayInstance { + self.values.relay.instance + } + /// Returns the upstream target as descriptor. pub fn upstream_descriptor(&self) -> &UpstreamDescriptor<'_> { &self.values.relay.upstream diff --git a/relay/src/cli.rs b/relay/src/cli.rs index f26485773f..04671f9e7a 100644 --- a/relay/src/cli.rs +++ b/relay/src/cli.rs @@ -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(), + instance: matches.get_one("instance").cloned(), } } @@ -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(), + instance: env::var("RELAY_INSTANCE").ok(), } } diff --git a/relay/src/cliapp.rs b/relay/src/cliapp.rs index 187d184281..98340c9b8e 100644 --- a/relay/src/cliapp.rs +++ b/relay/src/cliapp.rs @@ -141,6 +141,11 @@ pub fn make_app() -> Command { "Maximum number of seconds to wait for pending envelopes on shutdown.", ), ) + .arg( + Arg::new("instance") + .long("instance") + .help("The instance type of this Relay.") + ) ) .subcommand( Command::new("credentials")