Skip to main content

tael_server/
config.rs

1/// Selected storage backend. `TaelBackend` (the purpose-built tiered engine)
2/// is the default; pass `--storage duckdb` or set `TAEL_STORAGE=duckdb` to use
3/// the legacy embedded-DuckDB backend instead.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum StorageBackend {
6    Duckdb,
7    TaelBackend,
8}
9
10impl StorageBackend {
11    /// Parse a backend name (from the `--storage` flag or `TAEL_STORAGE`).
12    /// Anything that isn't explicitly `duckdb` selects the default tael-backend.
13    pub fn parse(s: &str) -> Self {
14        match s.trim().to_lowercase().as_str() {
15            "duckdb" | "duck" => StorageBackend::Duckdb,
16            _ => StorageBackend::TaelBackend,
17        }
18    }
19}
20
21pub struct ServerConfig {
22    pub otlp_grpc_addr: String,
23    pub rest_api_addr: String,
24    pub data_dir: String,
25    pub storage: StorageBackend,
26}
27
28impl ServerConfig {
29    pub fn from_env() -> Self {
30        let mut config = Self {
31            otlp_grpc_addr: std::env::var("TAEL_OTLP_GRPC_ADDR")
32                .unwrap_or_else(|_| "127.0.0.1:4317".into()),
33            rest_api_addr: std::env::var("TAEL_REST_API_ADDR")
34                .unwrap_or_else(|_| "127.0.0.1:7701".into()),
35            data_dir: std::env::var("TAEL_DATA_DIR").unwrap_or_else(|_| "./data".into()),
36            // Default to the tael-backend engine; `TAEL_STORAGE` can override.
37            storage: std::env::var("TAEL_STORAGE")
38                .map(|s| StorageBackend::parse(&s))
39                .unwrap_or(StorageBackend::TaelBackend),
40        };
41        // A `--storage <duckdb|tael-backend>` flag (or `--storage=…`) takes
42        // precedence over the env var.
43        if let Some(s) = storage_flag() {
44            config.storage = s;
45        }
46        config
47    }
48}
49
50/// Scan the process args for `--storage <value>` / `--storage=<value>`.
51fn storage_flag() -> Option<StorageBackend> {
52    let mut args = std::env::args().skip(1);
53    while let Some(arg) = args.next() {
54        if arg == "--storage" {
55            return args.next().map(|v| StorageBackend::parse(&v));
56        }
57        if let Some(v) = arg.strip_prefix("--storage=") {
58            return Some(StorageBackend::parse(v));
59        }
60    }
61    None
62}