Skip to main content

rust_supervisor/config/
configurable.rs

1//! Public configuration input model for supervisor users.
2//!
3//! The structs in this module are the single raw configuration surface used for
4//! YAML loading, template rendering, and JSON Schema generation.
5
6use confique::Config;
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9use std::path::PathBuf;
10
11/// Configuration file shape loaded from YAML.
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Config, JsonSchema)]
13pub struct SupervisorConfig {
14    /// Root supervisor declaration values.
15    #[config(nested)]
16    pub supervisor: SupervisorRootConfig,
17    /// Runtime policy values.
18    #[config(nested)]
19    pub policy: PolicyConfig,
20    /// Shutdown budget values.
21    #[config(nested)]
22    pub shutdown: ShutdownConfig,
23    /// Observability switches and capacities.
24    #[config(nested)]
25    pub observability: ObservabilityConfig,
26    /// Optional target-side dashboard IPC configuration.
27    pub ipc: Option<DashboardIpcConfig>,
28}
29
30impl rust_config_tree::ConfigSchema for SupervisorConfig {
31    /// Returns child configuration paths declared by one loaded layer.
32    ///
33    /// # Arguments
34    ///
35    /// - `layer`: Partially loaded supervisor configuration layer.
36    ///
37    /// # Returns
38    ///
39    /// Returns an empty list because official supervisor templates stay in one
40    /// root YAML file unless crate users wrap this type in their own project.
41    fn include_paths(layer: &<Self as Config>::Layer) -> Vec<PathBuf> {
42        let _ = layer;
43        Vec::new()
44    }
45}
46
47/// Root supervisor configuration.
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Config, JsonSchema)]
49pub struct SupervisorRootConfig {
50    /// Restart scope strategy for child failures.
51    pub strategy: crate::spec::supervisor::SupervisionStrategy,
52}
53
54/// Restart, backoff, and fuse configuration.
55#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Config, JsonSchema)]
56pub struct PolicyConfig {
57    /// Maximum child restarts within the child restart window.
58    pub child_restart_limit: u32,
59    /// Child restart window in milliseconds.
60    pub child_restart_window_ms: u64,
61    /// Maximum supervisor failures within the supervisor failure window.
62    pub supervisor_failure_limit: u32,
63    /// Supervisor failure window in milliseconds.
64    pub supervisor_failure_window_ms: u64,
65    /// Initial backoff in milliseconds.
66    pub initial_backoff_ms: u64,
67    /// Maximum backoff in milliseconds.
68    pub max_backoff_ms: u64,
69    /// Jitter ratio expressed as a fraction between zero and one.
70    pub jitter_ratio: f64,
71    /// Heartbeat interval in milliseconds.
72    pub heartbeat_interval_ms: u64,
73    /// Stale heartbeat threshold in milliseconds.
74    pub stale_after_ms: u64,
75}
76
77/// Shutdown coordination configuration.
78#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Config, JsonSchema)]
79pub struct ShutdownConfig {
80    /// Graceful drain timeout in milliseconds.
81    pub graceful_timeout_ms: u64,
82    /// Abort wait timeout in milliseconds.
83    pub abort_wait_ms: u64,
84}
85
86/// Observability configuration.
87#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Config, JsonSchema)]
88pub struct ObservabilityConfig {
89    /// Event journal capacity.
90    pub event_journal_capacity: usize,
91    /// Whether metrics recording is enabled.
92    pub metrics_enabled: bool,
93    /// Whether command audit recording is enabled.
94    pub audit_enabled: bool,
95}
96
97/// Optional target-side dashboard IPC configuration.
98#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Config, JsonSchema)]
99pub struct DashboardIpcConfig {
100    /// Whether the target process opens the local IPC endpoint.
101    pub enabled: bool,
102    /// Stable target process identifier sent to relay and UI.
103    pub target_id: Option<String>,
104    /// Local Unix domain socket path used by the target process.
105    pub path: Option<PathBuf>,
106    /// Socket file permission string such as `0600`.
107    pub permissions: Option<String>,
108    /// Socket bind behavior when the path already exists.
109    pub bind_mode: Option<DashboardIpcBindMode>,
110    /// Dynamic registration settings used after IPC is ready.
111    pub registration: Option<DashboardRegistrationConfig>,
112}
113
114/// Socket bind behavior for target-side dashboard IPC.
115#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
116#[serde(rename_all = "snake_case")]
117pub enum DashboardIpcBindMode {
118    /// Fail when the socket path already exists.
119    CreateNew,
120    /// Remove a stale socket path before binding.
121    ReplaceStale,
122}
123
124/// Dynamic registration settings for a target process.
125#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Config, JsonSchema)]
126pub struct DashboardRegistrationConfig {
127    /// Whether the target process registers with relay after IPC is ready.
128    pub enabled: bool,
129    /// Local relay registration socket path.
130    pub relay_registration_path: Option<PathBuf>,
131    /// Human-readable name shown in the dashboard.
132    pub display_name: Option<String>,
133    /// Registration lease duration in seconds.
134    pub lease_seconds: Option<u64>,
135    /// Registration heartbeat interval in seconds.
136    pub registration_heartbeat_interval_seconds: Option<u64>,
137}