Skip to main content

otelite_api/
config.rs

1//! Dashboard configuration
2
3use serde::{Deserialize, Serialize};
4use std::net::SocketAddr;
5
6/// Configuration for the dashboard server
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct DashboardConfig {
9    /// Address to bind the dashboard server to
10    pub bind_address: SocketAddr,
11
12    /// Enable CORS (for development)
13    pub enable_cors: bool,
14
15    /// Path to storage database
16    pub storage_path: String,
17
18    /// Maximum number of items to return per page
19    pub max_page_size: usize,
20
21    /// Default page size for queries
22    pub default_page_size: usize,
23
24    /// Cache size in MB for query results
25    pub cache_size_mb: usize,
26
27    /// Auto-refresh interval in seconds (0 = disabled)
28    pub auto_refresh_interval_secs: u64,
29
30    /// OTLP gRPC receiver port (shown in the web UI status popover)
31    pub otlp_grpc_port: u16,
32
33    /// OTLP HTTP receiver port (shown in the web UI status popover)
34    pub otlp_http_port: u16,
35}
36
37impl Default for DashboardConfig {
38    fn default() -> Self {
39        Self {
40            bind_address: "127.0.0.1:3000".parse().unwrap(),
41            enable_cors: false,
42            storage_path: "otelite.db".to_string(),
43            max_page_size: 1000,
44            default_page_size: 100,
45            cache_size_mb: 10,
46            auto_refresh_interval_secs: 1,
47            otlp_grpc_port: 4317,
48            otlp_http_port: 4318,
49        }
50    }
51}
52
53impl DashboardConfig {
54    /// Create a new configuration with custom bind address
55    pub fn with_bind_address(mut self, addr: SocketAddr) -> Self {
56        self.bind_address = addr;
57        self
58    }
59
60    /// Enable CORS for development
61    pub fn with_cors(mut self, enable: bool) -> Self {
62        self.enable_cors = enable;
63        self
64    }
65
66    /// Set storage path
67    pub fn with_storage_path(mut self, path: impl Into<String>) -> Self {
68        self.storage_path = path.into();
69        self
70    }
71
72    /// Set the OTLP receiver ports (shown in the web UI status popover)
73    pub fn with_otlp_ports(mut self, grpc_port: u16, http_port: u16) -> Self {
74        self.otlp_grpc_port = grpc_port;
75        self.otlp_http_port = http_port;
76        self
77    }
78}