|
1 | | -use std::{fmt, path::Path}; |
| 1 | +//! Aquila's top-level configuration: loaded from `aquila.{yaml,toml,json,...}` |
| 2 | +//! (via the `config` crate), overridable by environment variables, and |
| 3 | +//! falling back to the [`Default`] impls below when no file is present. |
| 4 | +//! |
| 5 | +//! See [`display`] for how this renders in the startup log line. |
| 6 | +
|
| 7 | +mod display; |
| 8 | + |
| 9 | +use std::path::Path; |
2 | 10 |
|
3 | 11 | use code0_flow::flow_telemetry::OpenTelemetry; |
4 | 12 | use config::{Config as ConfigLoader, ConfigError, File}; |
@@ -181,87 +189,6 @@ impl Config { |
181 | 189 | } |
182 | 190 | } |
183 | 191 |
|
184 | | -impl fmt::Display for Config { |
185 | | - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
186 | | - writeln!(formatter, "Aquila configuration")?; |
187 | | - writeln!(formatter, " Environment: {}", self.environment)?; |
188 | | - writeln!(formatter, " Mode: {}", self.mode)?; |
189 | | - writeln!(formatter, " Log level: {}", self.log_level)?; |
190 | | - writeln!(formatter, " OpenTelemetry")?; |
191 | | - writeln!(formatter, " Enabled: {}", self.opentelemetry.enabled)?; |
192 | | - writeln!( |
193 | | - formatter, |
194 | | - " Service: {}", |
195 | | - self.opentelemetry.service_name |
196 | | - )?; |
197 | | - writeln!( |
198 | | - formatter, |
199 | | - " Logs: {}", |
200 | | - display_optional_url(&self.opentelemetry.logs_endpoint) |
201 | | - )?; |
202 | | - writeln!( |
203 | | - formatter, |
204 | | - " Metrics: {}", |
205 | | - display_optional_url(&self.opentelemetry.metrics_endpoint) |
206 | | - )?; |
207 | | - writeln!( |
208 | | - formatter, |
209 | | - " Traces: {}", |
210 | | - display_optional_url(&self.opentelemetry.traces_endpoint) |
211 | | - )?; |
212 | | - writeln!(formatter, " NATS")?; |
213 | | - writeln!(formatter, " URL: {}", self.nats.url)?; |
214 | | - writeln!(formatter, " Bucket: {}", self.nats.bucket)?; |
215 | | - writeln!(formatter, " gRPC")?; |
216 | | - writeln!( |
217 | | - formatter, |
218 | | - " Address: {}:{}", |
219 | | - self.grpc.host, self.grpc.port |
220 | | - )?; |
221 | | - writeln!( |
222 | | - formatter, |
223 | | - " Health service: {}", |
224 | | - self.grpc.health_service |
225 | | - )?; |
226 | | - writeln!(formatter, " Static mode")?; |
227 | | - writeln!(formatter, " Flow path: {}", self.static_config.flow_path)?; |
228 | | - writeln!(formatter, " Dynamic mode")?; |
229 | | - writeln!( |
230 | | - formatter, |
231 | | - " Backend URL: {}", |
232 | | - self.dynamic_config.backend_url |
233 | | - )?; |
234 | | - writeln!(formatter, " Backend token: [FILTERED]")?; |
235 | | - writeln!( |
236 | | - formatter, |
237 | | - " Request timeout: {}s", |
238 | | - self.dynamic_config.backend_unary_timeout_secs |
239 | | - )?; |
240 | | - writeln!(formatter, " Runtime status")?; |
241 | | - writeln!( |
242 | | - formatter, |
243 | | - " Not responding after: {}s", |
244 | | - self.runtime_status.not_responding_after_secs |
245 | | - )?; |
246 | | - writeln!( |
247 | | - formatter, |
248 | | - " Stopped after: {}s", |
249 | | - self.runtime_status.stopped_after_not_responding_secs |
250 | | - )?; |
251 | | - write!( |
252 | | - formatter, |
253 | | - " Monitor interval: {}s", |
254 | | - self.runtime_status.monitor_interval_secs |
255 | | - ) |
256 | | - } |
257 | | -} |
258 | | - |
259 | | -fn display_optional_url(url: &Option<String>) -> &str { |
260 | | - url.as_deref() |
261 | | - .filter(|value| !value.trim().is_empty()) |
262 | | - .unwrap_or("<disabled>") |
263 | | -} |
264 | | - |
265 | 192 | #[cfg(test)] |
266 | 193 | mod tests { |
267 | 194 | use std::sync::Mutex; |
@@ -304,22 +231,6 @@ mod tests { |
304 | 231 | assert!(!output.contains("super-secret")); |
305 | 232 | } |
306 | 233 |
|
307 | | - #[test] |
308 | | - fn display_output_is_readable_and_filters_backend_token() { |
309 | | - let mut config = Config::default(); |
310 | | - config.dynamic_config.backend_token = "super-secret".into(); |
311 | | - |
312 | | - let output = config.to_string(); |
313 | | - |
314 | | - assert!(output.starts_with("Aquila configuration\n")); |
315 | | - assert!(output.contains(" Environment: development")); |
316 | | - assert!(output.contains(" Address: 127.0.0.1:8081")); |
317 | | - assert!(output.contains(" Request timeout: 5s")); |
318 | | - assert!(output.contains(" Backend token: [FILTERED]")); |
319 | | - assert!(!output.contains("super-secret")); |
320 | | - assert!(!output.contains("Config {")); |
321 | | - } |
322 | | - |
323 | 234 | #[test] |
324 | 235 | fn opentelemetry_endpoints_are_enabled_by_presence() { |
325 | 236 | let config: OpenTelemetry = ConfigLoader::builder() |
|
0 commit comments