Skip to content

Commit 1c53127

Browse files
duncanistaapiarian-datadogFlorentin Labelle
authored
chore(config): separate config from sources (#709)
# What? Separates the configuration from sources, allowing it to be used in more use cases. # How? Creates new default configuration and separates the environment variables and YAML sources from the default. # Why? Make it easier to track changes in every source, as the field names might be different to what they are used at the configuration level. # Notes I expect to abstract this even more by providing it as a crate which can have features, that way customers can only use the sources and product specific fields they need. --------- Co-authored-by: Aleksandr Pasechnik <aleksandr.pasechnik@datadoghq.com> Co-authored-by: Florentin Labelle <florentin.labelle@outlook.fr>
1 parent 1088157 commit 1c53127

15 files changed

Lines changed: 1987 additions & 571 deletions

File tree

.gitlab/datasources/flavors.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ flavors:
66
needs_layer_publish: true
77
suffix: amd64
88
layer_name_base_suffix: ""
9-
max_layer_compressed_size_mb: 24
9+
max_layer_compressed_size_mb: 25
1010
max_layer_uncompressed_size_mb: 54
1111

1212
- name: arm64

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ fn start_metrics_flushers(
920920
api_key: resolved_api_key,
921921
aggregator: Arc::clone(metrics_aggr),
922922
metrics_intake_url_prefix: metrics_intake_url.expect("can't parse site or override"),
923-
https_proxy: config.https_proxy.clone(),
923+
https_proxy: config.proxy_https.clone(),
924924
timeout: Duration::from_secs(config.flush_timeout),
925925
retry_strategy: DsdRetryStrategy::Immediate(3),
926926
};
@@ -945,7 +945,7 @@ fn start_metrics_flushers(
945945
api_key: api_key.clone(),
946946
aggregator: metrics_aggr.clone(),
947947
metrics_intake_url_prefix: metrics_intake_url.clone(),
948-
https_proxy: config.https_proxy.clone(),
948+
https_proxy: config.proxy_https.clone(),
949949
timeout: Duration::from_secs(config.flush_timeout),
950950
retry_strategy: DsdRetryStrategy::Immediate(3),
951951
};

bottlecap/src/config/env.rs

Lines changed: 664 additions & 188 deletions
Large diffs are not rendered by default.

bottlecap/src/config/log_level.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
use std::str::FromStr;
2+
13
use serde::{Deserialize, Deserializer};
4+
use serde_json::Value;
25
use tracing::error;
36

4-
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Default)]
7+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
58
pub enum LogLevel {
69
/// Designates very serious errors.
710
Error,
@@ -42,20 +45,40 @@ impl LogLevel {
4245
}
4346
}
4447

45-
#[allow(clippy::module_name_repetitions)]
46-
pub fn deserialize_log_level<'de, D>(deserializer: D) -> Result<LogLevel, D::Error>
47-
where
48-
D: Deserializer<'de>,
49-
{
50-
let s: String = Deserialize::deserialize(deserializer)?;
51-
match s.to_lowercase().as_str() {
52-
"error" => Ok(LogLevel::Error),
53-
"warn" => Ok(LogLevel::Warn),
54-
"info" => Ok(LogLevel::Info),
55-
"debug" => Ok(LogLevel::Debug),
56-
"trace" => Ok(LogLevel::Trace),
57-
_ => {
58-
error!("Unknown log level: {}, using warn", s);
48+
impl FromStr for LogLevel {
49+
type Err = String;
50+
51+
fn from_str(s: &str) -> Result<Self, Self::Err> {
52+
match s.to_lowercase().as_str() {
53+
"error" => Ok(LogLevel::Error),
54+
"warn" => Ok(LogLevel::Warn),
55+
"info" => Ok(LogLevel::Info),
56+
"debug" => Ok(LogLevel::Debug),
57+
"trace" => Ok(LogLevel::Trace),
58+
_ => Err(format!(
59+
"Invalid log level: '{s}'. Valid levels are: error, warn, info, debug, trace",
60+
)),
61+
}
62+
}
63+
}
64+
65+
impl<'de> Deserialize<'de> for LogLevel {
66+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67+
where
68+
D: Deserializer<'de>,
69+
{
70+
let value = Value::deserialize(deserializer)?;
71+
72+
if let Value::String(s) = value {
73+
match LogLevel::from_str(&s) {
74+
Ok(level) => Ok(level),
75+
Err(e) => {
76+
error!("{}", e);
77+
Ok(LogLevel::Warn)
78+
}
79+
}
80+
} else {
81+
error!("Expected a string for log level, got {:?}", value);
5982
Ok(LogLevel::Warn)
6083
}
6184
}

0 commit comments

Comments
 (0)