enable conf serde and test the toml format with our current schema

This commit is contained in:
Chris Beck
2025-12-06 03:26:30 -07:00
parent 0de84bcd60
commit 64bc606201
15 changed files with 170 additions and 25 deletions
-6
View File
@@ -153,12 +153,6 @@ where
}
}
impl<K, V> std::fmt::Debug for LazyMap<K, V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LazyMap").finish_non_exhaustive()
}
}
#[cfg(test)]
mod tests {
use super::*;
+2 -1
View File
@@ -49,9 +49,10 @@ impl fmt::Display for SuppressionReason {
/// Config options related to the log handler, and what log messages it chooses to alert on.
#[derive(Clone, Conf, Debug)]
#[conf(serde)]
pub struct LogHandlerConfig {
/// Routes for matching and rate-limiting log messages.
#[conf(long, env, value_parser = serde_json::from_str, default_value = "[]")]
#[conf(long, env, value_parser = serde_json::from_str, default_value = "[]", serde(alias = "route"))]
pub routes: Vec<Route>,
/// Overall rate limits applied after route checks pass.
#[conf(long, env, value_parser = serde_json::from_str, default_value = "[]")]
+5 -1
View File
@@ -49,6 +49,7 @@ pub use crate::rate_limiter::{Limiter, RateThreshold};
/// Configuration for the gateway.
#[derive(Conf, Debug)]
#[conf(serde)]
#[cfg_attr(unix, conf(one_of_fields(signal_cli_tcp_addr, signal_cli_socket_path)))]
#[cfg_attr(not(unix), conf(one_of_fields(signal_cli_tcp_addr)))]
pub struct GatewayConfig {
@@ -62,6 +63,9 @@ pub struct GatewayConfig {
/// The phone number or UUID of the Signal account to use.
#[conf(long, env)]
pub signal_account: String,
/// Delay before retrying connection to signal-cli after an error.
#[conf(long, env, default_value = "5s", value_parser = conf_extra::parse_duration, serde(use_value_parser))]
pub signal_cli_retry_delay: Duration,
/// Admin UUIDs mapped to their safety numbers (can be empty).
/// Example: `{"uuid1": ["12345...", "67890..."], "uuid2": []}`
#[conf(long, env, value_parser = serde_json::from_str)]
@@ -279,7 +283,7 @@ impl Gateway {
if let Err(err) = self.connect_and_run(&mut alert_rx).await {
error!("Error with signal-cli, reconnecting: {err}");
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(self.config.signal_cli_retry_delay).await;
}
}
}
+8 -8
View File
@@ -64,13 +64,13 @@ pub struct Route {
/// Rate limits applied per-origin for messages matching this route.
/// Each limit specifies a filter and threshold for suppressing repeated alerts.
#[serde(default)]
pub limit: Vec<Limit>,
#[serde(default, alias = "limit")]
pub limits: Vec<Limit>,
/// Global rate limits applied across all origins for this route.
/// Each limit specifies a filter and threshold for suppressing repeated alerts.
#[serde(default)]
pub global_limit: Vec<Limit>,
#[serde(default, alias = "global_limit")]
pub global_limits: Vec<Limit>,
}
fn default_alert_level() -> Level {
@@ -80,8 +80,8 @@ fn default_alert_level() -> Level {
impl Route {
/// Create a limiter set from this route's limit configurations.
pub fn make_limiter_set(&self) -> LimiterSet {
let limits = self.limit.clone();
let global_limiters = self.global_limit.iter().map(|l| l.make_limiter()).collect();
let limits = self.limits.clone();
let global_limiters = self.global_limits.iter().map(|l| l.make_limiter()).collect();
LimiterSet::new(
move || limits.iter().map(|l| l.make_limiter()).collect(),
global_limiters,
@@ -95,8 +95,8 @@ impl Default for Route {
alert_level: default_alert_level(),
filter: LogFilter::default(),
destination: None,
limit: Vec::new(),
global_limit: Vec::new(),
limits: Vec::new(),
global_limits: Vec::new(),
}
}
}
+1
View File
@@ -11,6 +11,7 @@ use tracing::error;
/// Configuration for log message formatting.
#[derive(Clone, Conf, Debug, Default)]
#[conf(serde)]
pub struct LogFormatConfig {
/// Include the module path in formatted output.
#[conf(long, env)]
+1
View File
@@ -22,6 +22,7 @@ use std::{path::PathBuf, str::FromStr, time::Duration};
/// Configures our prometheus API client
#[derive(Clone, Conf, Debug)]
#[conf(serde)]
pub struct PrometheusConfig {
/// Address of prometheus host. Should start with http and usually indicate port 9090
#[conf(long, env)]
+3 -3
View File
@@ -14,7 +14,7 @@ pub use prometheus_http_client::{
/// Configuration for plots generated from prometheus data
#[derive(Clone, Conf, Debug)]
#[conf(at_most_one_of_fields(utc_offset, timezone))]
#[conf(serde, at_most_one_of_fields(utc_offset, timezone))]
pub struct PlotConfig {
/// Working directory for temporary plot files
#[conf(long, env, default_value = "/tmp")]
@@ -24,11 +24,11 @@ pub struct PlotConfig {
age_limit: Duration,
/// Fixed timezone offset for plot timestamps, e.g. "+05:30" or "-08:00".
/// Mutually exclusive with --timezone.
#[conf(long, env)]
#[conf(long, env, serde(use_value_parser))]
utc_offset: Option<FixedOffset>,
/// Timezone name for plot timestamps, e.g. "US/Mountain" or "Europe/Paris".
/// Mutually exclusive with --utc-offset.
#[conf(long, env)]
#[conf(long, env, serde(use_value_parser))]
timezone: Option<Tz>,
/// Stroke width for plot lines
#[conf(long, env, default_value = "2")]