1use std::collections::HashMap;
4use serde::{Deserialize, Serialize};
5
6pub type ResourceId = String;
8
9pub type MetricValue = f64;
11
12pub type Timestamp = u64;
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct ResourceMetrics {
18 pub resource_id: ResourceId,
20 pub resource_type: String,
22 pub timestamp: Timestamp,
24 pub metrics: HashMap<String, MetricValue>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
31pub enum ScaleDirection {
32 Up,
34 Down,
36 Maintain,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct ScaleAction {
43 pub resource_id: ResourceId,
45 pub resource_type: String,
47 pub direction: ScaleDirection,
49 pub target_capacity: Option<u32>,
51 pub scale_factor: Option<f64>,
53 pub reason: String,
55 pub confidence: f64,
57 pub timestamp: Timestamp,
59 pub metadata: HashMap<String, String>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ScalingThreshold {
66 pub metric_name: String,
68 pub scale_up_threshold: MetricValue,
70 pub scale_down_threshold: MetricValue,
72 pub scale_factor: f64,
74 pub cooldown_seconds: u64,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct ScalingPolicy {
81 pub name: String,
83 pub thresholds: Vec<ScalingThreshold>,
85 pub min_capacity: Option<u32>,
87 pub max_capacity: Option<u32>,
89 pub enabled: bool,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct ResourceConfig {
96 pub resource_type: String,
98 pub policies: Vec<ScalingPolicy>,
100 pub default_policy: Option<String>,
102 pub settings: HashMap<String, String>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct LighthouseConfig {
109 pub evaluation_interval_seconds: u64,
111 pub resource_configs: HashMap<String, ResourceConfig>,
113 pub global_settings: HashMap<String, String>,
115 pub enable_logging: bool,
117}
118
119impl Default for LighthouseConfig {
120 fn default() -> Self {
121 Self {
122 evaluation_interval_seconds: 30,
123 resource_configs: HashMap::new(),
124 global_settings: HashMap::new(),
125 enable_logging: true,
126 }
127 }
128}
129
130impl LighthouseConfig {
132 pub fn builder() -> LighthouseConfigBuilder {
133 LighthouseConfigBuilder::new()
134 }
135}
136
137#[derive(Debug)]
139pub struct LighthouseConfigBuilder {
140 config: LighthouseConfig,
141}
142
143impl LighthouseConfigBuilder {
144 pub fn new() -> Self {
145 Self {
146 config: LighthouseConfig::default(),
147 }
148 }
149
150 pub fn evaluation_interval(mut self, seconds: u64) -> Self {
151 self.config.evaluation_interval_seconds = seconds;
152 self
153 }
154
155 pub fn add_resource_config(mut self, resource_type: &str, config: ResourceConfig) -> Self {
156 self.config.resource_configs.insert(resource_type.to_string(), config);
157 self
158 }
159
160 pub fn global_setting(mut self, key: &str, value: &str) -> Self {
161 self.config.global_settings.insert(key.to_string(), value.to_string());
162 self
163 }
164
165 pub fn enable_logging(mut self, enabled: bool) -> Self {
166 self.config.enable_logging = enabled;
167 self
168 }
169
170 pub fn build(self) -> LighthouseConfig {
171 self.config
172 }
173}