From 2073b12686723f43685301a8b48f713199105bbc Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 16 Aug 2024 14:57:12 +0200 Subject: [PATCH 01/10] feat(config): Add relay environment configuration --- relay-config/src/config.rs | 59 ++++++++++++++++++++++++++++++++------ relay/src/cli.rs | 2 ++ relay/src/cliapp.rs | 5 ++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 88d9269398..73cb1e61a9 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -1,12 +1,3 @@ -use std::collections::{BTreeMap, HashMap}; -use std::error::Error; -use std::io::Write; -use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; -use std::path::{Path, PathBuf}; -use std::str::FromStr; -use std::time::Duration; -use std::{env, fmt, fs, io}; - use anyhow::Context; use relay_auth::{generate_key_pair, generate_relay_id, PublicKey, RelayId, SecretKey}; use relay_common::Dsn; @@ -18,6 +9,15 @@ use relay_metrics::aggregator::{AggregatorConfig, FlushBatching}; use relay_metrics::MetricNamespace; use serde::de::{DeserializeOwned, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use std::collections::{BTreeMap, HashMap}; +use std::error::Error; +use std::io::Write; +use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; +use std::os::unix::raw::mode_t; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::time::Duration; +use std::{env, fmt, fs, io}; use uuid::Uuid; use crate::aggregator::{AggregatorServiceConfig, ScopedAggregatorConfig}; @@ -222,6 +222,8 @@ trait ConfigObject: DeserializeOwned + Serialize { pub struct OverridableConfig { /// The operation mode of this relay. pub mode: Option, + /// The environment in which Relay is run. + pub environment: Option, /// The log level of this relay. pub log_level: Option, /// The upstream relay or sentry instance. @@ -352,6 +354,37 @@ impl fmt::Display for RelayMode { } } +/// The environment of a Relay. +#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub enum RelayEnvironment { + /// This Relay is run in a production environment. + Production, + + /// This Relay is run in a canary environment where experiments can be run. + Canary, +} + +impl fmt::Display for RelayEnvironment { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + RelayEnvironment::Production => write!(f, "production"), + RelayEnvironment::Canary => write!(f, "canary"), + } + } +} + +impl FromStr for RelayEnvironment { + type Err = fmt::Error; + + fn from_str(s: &str) -> Result { + match s { + "canary" => Ok(RelayEnvironment::Canary), + _ => Ok(RelayEnvironment::Production), + } + } +} + /// Error returned when parsing an invalid [`RelayMode`]. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct ParseRelayModeError; @@ -436,6 +469,8 @@ impl Default for ReadinessCondition { pub struct Relay { /// The operation mode of this relay. pub mode: RelayMode, + /// The environment of this relay. + pub environment: RelayEnvironment, /// The upstream relay or sentry instance. pub upstream: UpstreamDescriptor<'static>, /// The host the relay should bind to (network interface). @@ -1607,6 +1642,12 @@ impl Config { .with_context(|| ConfigError::field("mode"))?; } + if let Some(environment) = overrides.environment { + relay.environment = environment + .parse::() + .with_context(|| ConfigError::field("environment"))?; + } + if let Some(log_level) = overrides.log_level { self.values.logging.level = log_level.parse()?; } diff --git a/relay/src/cli.rs b/relay/src/cli.rs index f26485773f..a2203bccff 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(), + environment: matches.get_one("environment").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(), + environment: env::var("RELAY_ENVIRONMENT").ok(), } } diff --git a/relay/src/cliapp.rs b/relay/src/cliapp.rs index 187d184281..70ced02b28 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("environment") + .long("environment") + .help("The environment in which Relay is run.") + ) ) .subcommand( Command::new("credentials") From e4b17b6f7fbd45deec4fb192787cd367b045cc6e Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 16 Aug 2024 15:00:18 +0200 Subject: [PATCH 02/10] Fix --- relay-config/src/config.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 73cb1e61a9..d00c2c8014 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -358,8 +358,8 @@ impl fmt::Display for RelayMode { #[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub enum RelayEnvironment { - /// This Relay is run in a production environment. - Production, + /// This Relay is run in a default environment. + Default, /// This Relay is run in a canary environment where experiments can be run. Canary, @@ -368,7 +368,7 @@ pub enum RelayEnvironment { impl fmt::Display for RelayEnvironment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - RelayEnvironment::Production => write!(f, "production"), + RelayEnvironment::Default => write!(f, "default"), RelayEnvironment::Canary => write!(f, "canary"), } } @@ -380,7 +380,7 @@ impl FromStr for RelayEnvironment { fn from_str(s: &str) -> Result { match s { "canary" => Ok(RelayEnvironment::Canary), - _ => Ok(RelayEnvironment::Production), + _ => Ok(RelayEnvironment::Default), } } } From c290f121f5f867009cf4e72c15ddd572142f6d9a Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 16 Aug 2024 15:01:44 +0200 Subject: [PATCH 03/10] Fix --- relay-config/src/config.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index d00c2c8014..215909b227 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -1,3 +1,12 @@ +use std::collections::{BTreeMap, HashMap}; +use std::error::Error; +use std::io::Write; +use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::time::Duration; +use std::{env, fmt, fs, io}; + use anyhow::Context; use relay_auth::{generate_key_pair, generate_relay_id, PublicKey, RelayId, SecretKey}; use relay_common::Dsn; @@ -9,15 +18,6 @@ use relay_metrics::aggregator::{AggregatorConfig, FlushBatching}; use relay_metrics::MetricNamespace; use serde::de::{DeserializeOwned, Unexpected, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::collections::{BTreeMap, HashMap}; -use std::error::Error; -use std::io::Write; -use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; -use std::os::unix::raw::mode_t; -use std::path::{Path, PathBuf}; -use std::str::FromStr; -use std::time::Duration; -use std::{env, fmt, fs, io}; use uuid::Uuid; use crate::aggregator::{AggregatorServiceConfig, ScopedAggregatorConfig}; @@ -498,6 +498,7 @@ impl Default for Relay { fn default() -> Self { Relay { mode: RelayMode::Managed, + environment: RelayEnvironment::Default, upstream: "https://sentry.io/".parse().unwrap(), host: default_host(), port: 3000, From b04d5d4bef3b7b1e6db711280d0120e671cd94e9 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 26 Aug 2024 12:43:55 +0200 Subject: [PATCH 04/10] Add method --- relay-config/src/config.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 215909b227..a0c17ff258 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -1862,6 +1862,11 @@ impl Config { self.values.relay.mode } + /// Returns the relay environment. + pub fn relay_environment(&self) -> RelayEnvironment { + self.values.relay.environment + } + /// Returns the upstream target as descriptor. pub fn upstream_descriptor(&self) -> &UpstreamDescriptor<'_> { &self.values.relay.upstream From fbe0b8b04b0d53e9fc10317aec16e2bb67f703e2 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 26 Aug 2024 13:51:18 +0200 Subject: [PATCH 05/10] Rename --- relay-config/src/config.rs | 44 +++++++++++++++++++------------------- relay/src/cli.rs | 4 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index a0c17ff258..cb940639e7 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -222,8 +222,8 @@ trait ConfigObject: DeserializeOwned + Serialize { pub struct OverridableConfig { /// The operation mode of this relay. pub mode: Option, - /// The environment in which Relay is run. - pub environment: Option, + /// The deployment of this relay. + pub deployment: Option, /// The log level of this relay. pub log_level: Option, /// The upstream relay or sentry instance. @@ -354,33 +354,33 @@ impl fmt::Display for RelayMode { } } -/// The environment of a Relay. +/// The deployment type of Relay. #[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub enum RelayEnvironment { - /// This Relay is run in a default environment. +pub enum RelayDeployment { + /// This Relay is run in a default deployment. Default, - /// This Relay is run in a canary environment where experiments can be run. + /// This Relay is run in a canary deployment where experiments can be run. Canary, } -impl fmt::Display for RelayEnvironment { +impl fmt::Display for RelayDeployment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - RelayEnvironment::Default => write!(f, "default"), - RelayEnvironment::Canary => write!(f, "canary"), + RelayDeployment::Default => write!(f, "default"), + RelayDeployment::Canary => write!(f, "canary"), } } } -impl FromStr for RelayEnvironment { +impl FromStr for RelayDeployment { type Err = fmt::Error; fn from_str(s: &str) -> Result { match s { - "canary" => Ok(RelayEnvironment::Canary), - _ => Ok(RelayEnvironment::Default), + "canary" => Ok(RelayDeployment::Canary), + _ => Ok(RelayDeployment::Default), } } } @@ -469,8 +469,8 @@ impl Default for ReadinessCondition { pub struct Relay { /// The operation mode of this relay. pub mode: RelayMode, - /// The environment of this relay. - pub environment: RelayEnvironment, + /// 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). @@ -498,7 +498,7 @@ impl Default for Relay { fn default() -> Self { Relay { mode: RelayMode::Managed, - environment: RelayEnvironment::Default, + deployment: RelayDeployment::Default, upstream: "https://sentry.io/".parse().unwrap(), host: default_host(), port: 3000, @@ -1643,10 +1643,10 @@ impl Config { .with_context(|| ConfigError::field("mode"))?; } - if let Some(environment) = overrides.environment { - relay.environment = environment - .parse::() - .with_context(|| ConfigError::field("environment"))?; + if let Some(deployment) = overrides.deployment { + relay.deployment = deployment + .parse::() + .with_context(|| ConfigError::field("deployment"))?; } if let Some(log_level) = overrides.log_level { @@ -1862,9 +1862,9 @@ impl Config { self.values.relay.mode } - /// Returns the relay environment. - pub fn relay_environment(&self) -> RelayEnvironment { - self.values.relay.environment + /// Returns the relay deployment. + pub fn relay_deployment(&self) -> RelayDeployment { + self.values.relay.deployment } /// Returns the upstream target as descriptor. diff --git a/relay/src/cli.rs b/relay/src/cli.rs index a2203bccff..6040e93e78 100644 --- a/relay/src/cli.rs +++ b/relay/src/cli.rs @@ -97,7 +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(), - environment: matches.get_one("environment").cloned(), + deployment: matches.get_one("environment").cloned(), } } @@ -118,7 +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(), - environment: env::var("RELAY_ENVIRONMENT").ok(), + deployment: env::var("RELAY_DEPLOYMENT").ok(), } } From eadd1ef54f7d8da06f0b9e113f9d341a08c6d99f Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 26 Aug 2024 13:52:09 +0200 Subject: [PATCH 06/10] Rename --- relay/src/cli.rs | 2 +- relay/src/cliapp.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/relay/src/cli.rs b/relay/src/cli.rs index 6040e93e78..012f20056b 100644 --- a/relay/src/cli.rs +++ b/relay/src/cli.rs @@ -97,7 +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("environment").cloned(), + deployment: matches.get_one("deployment").cloned(), } } diff --git a/relay/src/cliapp.rs b/relay/src/cliapp.rs index 70ced02b28..fc596efbe5 100644 --- a/relay/src/cliapp.rs +++ b/relay/src/cliapp.rs @@ -142,9 +142,9 @@ pub fn make_app() -> Command { ), ) .arg( - Arg::new("environment") - .long("environment") - .help("The environment in which Relay is run.") + Arg::new("deployment") + .long("deployment") + .help("The deployment type of this Relay.") ) ) .subcommand( From cd90965c1fc2c19853b31c8a3c663f9613a6623b Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 26 Aug 2024 13:53:33 +0200 Subject: [PATCH 07/10] Rename --- relay-config/src/config.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index cb940639e7..53406d0def 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -365,6 +365,13 @@ pub enum RelayDeployment { 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 { From 357602c2b081d68520d6a6d3fc4c4127b37eec10 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 26 Aug 2024 13:54:58 +0200 Subject: [PATCH 08/10] Rename --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c1eff8df..ac31a03749 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 deployment type of Relay. ([#3938](https://github.com/getsentry/relay/pull/3938)) + ## 24.8.0 **Bug Fixes**: From c694bc7365e4bcd1a4c01fbef44d92cf34490587 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Tue, 27 Aug 2024 10:23:09 +0200 Subject: [PATCH 09/10] Rename --- relay-config/src/config.rs | 48 +++++++++++++++++++------------------- relay/src/cli.rs | 4 ++-- relay/src/cliapp.rs | 6 ++--- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index 53406d0def..5ad262d7f5 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -222,8 +222,8 @@ trait ConfigObject: DeserializeOwned + Serialize { pub struct OverridableConfig { /// The operation mode of this relay. pub mode: Option, - /// The deployment of this relay. - pub deployment: 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. @@ -354,40 +354,40 @@ impl fmt::Display for RelayMode { } } -/// The deployment type of Relay. +/// The instance 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. +pub enum RelayInstance { + /// This Relay is run as a default instance. Default, - /// This Relay is run in a canary deployment where experiments can be run. + /// This Relay is run as a canary instance where experiments can be run. Canary, } -impl RelayDeployment { - /// Returns `true` if the [`RelayDeployment`] is of type [`RelayDeployment::Canary`]. +impl RelayInstance { + /// Returns `true` if the [`RelayInstance`] is of type [`RelayInstance::Canary`]. pub fn is_canary(&self) -> bool { - matches!(self, RelayDeployment::Canary) + matches!(self, RelayInstance::Canary) } } -impl fmt::Display for RelayDeployment { +impl fmt::Display for RelayInstance { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - RelayDeployment::Default => write!(f, "default"), - RelayDeployment::Canary => write!(f, "canary"), + RelayInstance::Default => write!(f, "default"), + RelayInstance::Canary => write!(f, "canary"), } } } -impl FromStr for RelayDeployment { +impl FromStr for RelayInstance { type Err = fmt::Error; fn from_str(s: &str) -> Result { match s { - "canary" => Ok(RelayDeployment::Canary), - _ => Ok(RelayDeployment::Default), + "canary" => Ok(RelayInstance::Canary), + _ => Ok(RelayInstance::Default), } } } @@ -476,8 +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 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). @@ -505,7 +505,7 @@ impl Default for Relay { fn default() -> Self { Relay { mode: RelayMode::Managed, - deployment: RelayDeployment::Default, + instance: RelayInstance::Default, upstream: "https://sentry.io/".parse().unwrap(), host: default_host(), port: 3000, @@ -1650,9 +1650,9 @@ impl Config { .with_context(|| ConfigError::field("mode"))?; } - if let Some(deployment) = overrides.deployment { - relay.deployment = deployment - .parse::() + if let Some(deployment) = overrides.instance { + relay.instance = deployment + .parse::() .with_context(|| ConfigError::field("deployment"))?; } @@ -1869,9 +1869,9 @@ impl Config { self.values.relay.mode } - /// Returns the relay deployment. - pub fn relay_deployment(&self) -> RelayDeployment { - self.values.relay.deployment + /// Returns the instance type of relay. + pub fn relay_instance(&self) -> RelayInstance { + self.values.relay.instance } /// Returns the upstream target as descriptor. diff --git a/relay/src/cli.rs b/relay/src/cli.rs index 012f20056b..04671f9e7a 100644 --- a/relay/src/cli.rs +++ b/relay/src/cli.rs @@ -97,7 +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(), + instance: matches.get_one("instance").cloned(), } } @@ -118,7 +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(), + instance: env::var("RELAY_INSTANCE").ok(), } } diff --git a/relay/src/cliapp.rs b/relay/src/cliapp.rs index fc596efbe5..98340c9b8e 100644 --- a/relay/src/cliapp.rs +++ b/relay/src/cliapp.rs @@ -142,9 +142,9 @@ pub fn make_app() -> Command { ), ) .arg( - Arg::new("deployment") - .long("deployment") - .help("The deployment type of this Relay.") + Arg::new("instance") + .long("instance") + .help("The instance type of this Relay.") ) ) .subcommand( From aae1f6b5d07f45c1d0fa98fbe2af7bbcbb844b01 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Tue, 27 Aug 2024 10:24:36 +0200 Subject: [PATCH 10/10] Rename --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac31a03749..36850b9bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ **Features**: -- Add configuration option to specify the deployment type of Relay. ([#3938](https://github.com/getsentry/relay/pull/3938)) +- Add configuration option to specify the instance type of Relay. ([#3938](https://github.com/getsentry/relay/pull/3938)) ## 24.8.0