use std::time::Duration;
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct ObservabilityConfig {
pub slow_query_threshold: Option<Duration>,
}
impl ObservabilityConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_slow_query_threshold(mut self, threshold: Duration) -> Self {
self.slow_query_threshold = Some(threshold);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tools::ToolsBuilder;
#[test]
fn builder_sets_threshold() {
let cfg = ObservabilityConfig::new().with_slow_query_threshold(Duration::from_millis(500));
assert_eq!(cfg.slow_query_threshold, Some(Duration::from_millis(500)));
}
#[test]
fn default_disables_slow_query_log() {
let cfg = ObservabilityConfig::new();
assert_eq!(cfg.slow_query_threshold, None);
}
#[test]
fn config_slot_roundtrip_via_tools() {
let threshold = Duration::from_millis(200);
let tools = ToolsBuilder::new()
.config(ObservabilityConfig::new().with_slow_query_threshold(threshold))
.build()
.expect("注册可观测性配置后应构建成功");
let retrieved = tools
.config::<ObservabilityConfig>()
.expect("已注册的配置应可读回");
assert_eq!(retrieved.slow_query_threshold, Some(threshold));
}
}