llm_memory_graph/observatory/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ObservatoryConfig {
8 pub enabled: bool,
10
11 pub batch_size: usize,
13
14 pub flush_interval_ms: u64,
16
17 pub enable_metrics: bool,
19
20 #[serde(default)]
22 pub custom_config: std::collections::HashMap<String, String>,
23}
24
25impl Default for ObservatoryConfig {
26 fn default() -> Self {
27 Self {
28 enabled: false,
29 batch_size: 100,
30 flush_interval_ms: 1000,
31 enable_metrics: true,
32 custom_config: std::collections::HashMap::new(),
33 }
34 }
35}
36
37impl ObservatoryConfig {
38 pub fn new() -> Self {
40 Self::default()
41 }
42
43 pub fn enabled(mut self) -> Self {
45 self.enabled = true;
46 self
47 }
48
49 pub fn with_batch_size(mut self, batch_size: usize) -> Self {
51 self.batch_size = batch_size;
52 self
53 }
54
55 pub fn with_flush_interval(mut self, interval_ms: u64) -> Self {
57 self.flush_interval_ms = interval_ms;
58 self
59 }
60
61 pub fn with_metrics(mut self, enabled: bool) -> Self {
63 self.enable_metrics = enabled;
64 self
65 }
66
67 pub fn with_custom(mut self, key: String, value: String) -> Self {
69 self.custom_config.insert(key, value);
70 self
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 #[test]
79 fn test_default_config() {
80 let config = ObservatoryConfig::default();
81 assert!(!config.enabled);
82 assert_eq!(config.batch_size, 100);
83 assert_eq!(config.flush_interval_ms, 1000);
84 assert!(config.enable_metrics);
85 }
86
87 #[test]
88 fn test_builder_pattern() {
89 let config = ObservatoryConfig::new()
90 .enabled()
91 .with_batch_size(50)
92 .with_flush_interval(500)
93 .with_metrics(false);
94
95 assert!(config.enabled);
96 assert_eq!(config.batch_size, 50);
97 assert_eq!(config.flush_interval_ms, 500);
98 assert!(!config.enable_metrics);
99 }
100
101 #[test]
102 fn test_custom_config() {
103 let config = ObservatoryConfig::new()
104 .with_custom("kafka_brokers".to_string(), "localhost:9092".to_string())
105 .with_custom("topic".to_string(), "events".to_string());
106
107 assert_eq!(config.custom_config.len(), 2);
108 assert_eq!(
109 config.custom_config.get("kafka_brokers"),
110 Some(&"localhost:9092".to_string())
111 );
112 }
113}