refactor(self-hosting): forward every setting, drop dead config (#3047)

This commit is contained in:
Hampus
2026-09-30 00:58:43 +02:00
committed by GitHub
parent 39f9beda5a
commit 2b8a743dc5
96 changed files with 1743 additions and 2391 deletions
+28 -9
View File
@@ -20,7 +20,6 @@ pub struct ServiceConfig {
pub nats_auth_token: Option<String>,
pub cache_max_entries: u64,
pub cache_ttl: Duration,
pub cache_hard_ttl: Duration,
pub max_concurrent_requests: usize,
pub scylla_hosts: Vec<String>,
pub scylla_keyspace: String,
@@ -114,12 +113,6 @@ impl ServiceConfig {
.transpose()?
.unwrap_or(30_000);
let cache_hard_ttl_ms = optional_from(&get, "FLUXER_SVC_CACHE_HARD_TTL_MS")
.map(|v| v.parse::<u64>())
.transpose()?
.unwrap_or(600_000)
.max(cache_ttl_ms);
let cassandra_port = optional_from(&get, "FLUXER_CASSANDRA_PORT")
.map(|v| v.parse::<u16>())
.transpose()?
@@ -175,7 +168,6 @@ impl ServiceConfig {
.transpose()?
.unwrap_or(100_000),
cache_ttl: Duration::from_millis(cache_ttl_ms),
cache_hard_ttl: Duration::from_millis(cache_hard_ttl_ms),
max_concurrent_requests,
scylla_hosts,
scylla_keyspace: optional_from(&get, "FLUXER_CASSANDRA_KEYSPACE")
@@ -218,7 +210,7 @@ fn optional_from<F>(get: &F, name: &str) -> Option<String>
where
F: Fn(&str) -> Option<String>,
{
get(name).filter(|v| !v.is_empty())
get(name).filter(|v| !v.trim().is_empty())
}
pub fn parse_hosts(hosts: &str) -> Vec<String> {
@@ -359,6 +351,33 @@ mod tests {
assert!(cfg.postgres_prepared_statements);
}
#[test]
fn blank_values_fall_back_to_the_defaults() {
let cfg = config_from_pairs(&[
("FLUXER_SVC_NAME", "messages"),
("FLUXER_SVC_MODE", ""),
("FLUXER_SVC_PORT", " "),
("FLUXER_SVC_MAX_CONCURRENT_REQUESTS", ""),
("FLUXER_NATS_AUTH_TOKEN", " "),
("FLUXER_POSTGRES_HOST", ""),
("FLUXER_POSTGRES_PASSWORD", " "),
("FLUXER_POSTGRES_MAX_CONNECTIONS", ""),
("FLUXER_POSTGRES_PREPARED_STATEMENTS", " "),
]);
assert_eq!(Mode::Router, cfg.mode);
assert_eq!(8090, cfg.listen_addr.port());
assert_eq!(
MESSAGES_MAX_CONCURRENT_REQUESTS,
cfg.max_concurrent_requests
);
assert_eq!(None, cfg.nats_auth_token);
assert_eq!("127.0.0.1", cfg.postgres_host);
assert_eq!(Some("fluxer".to_owned()), cfg.postgres_password);
assert_eq!(20, cfg.postgres_max_connections);
assert!(cfg.postgres_prepared_statements);
}
#[test]
fn reads_postgres_database_env() {
let cfg = config_from_pairs(&[
+3 -1
View File
@@ -20,7 +20,9 @@ pub fn init_tracing() {
tracing_subscriber::fmt()
.json()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
config::optional_env("RUST_LOG")
.and_then(|filter| EnvFilter::try_new(filter).ok())
.unwrap_or_else(|| EnvFilter::new("info")),
)
.try_init()
.ok();
-1
View File
@@ -942,7 +942,6 @@ mod tests {
nats_auth_token: None,
cache_max_entries: 100,
cache_ttl: Duration::from_secs(30),
cache_hard_ttl: Duration::from_secs(600),
max_concurrent_requests,
scylla_hosts: Vec::new(),
scylla_keyspace: "fluxer".to_owned(),
+1 -4
View File
@@ -81,10 +81,7 @@ fn build_version() -> &'static str {
static BUILD_VERSION: OnceLock<String> = OnceLock::new();
BUILD_VERSION
.get_or_init(|| {
std::env::var("BUILD_VERSION")
.ok()
.filter(|v| !v.trim().is_empty())
.unwrap_or_else(|| "dev".to_owned())
crate::config::optional_env("BUILD_VERSION").unwrap_or_else(|| "dev".to_owned())
})
.as_str()
}
-1
View File
@@ -436,7 +436,6 @@ mod tests {
nats_auth_token: None,
cache_max_entries: 100,
cache_ttl: Duration::from_secs(30),
cache_hard_ttl: Duration::from_secs(600),
max_concurrent_requests,
scylla_hosts: Vec::new(),
scylla_keyspace: "fluxer".to_owned(),