saluki_components/config/
autoscaling_failover.rs1#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct AutoscalingFailoverConfiguration {
6 enabled: bool,
7 metrics: Vec<String>,
8}
9
10impl AutoscalingFailoverConfiguration {
11 pub fn new(enabled: bool, metrics: Vec<String>) -> Self {
17 Self { enabled, metrics }
18 }
19
20 pub fn is_branch_requested(&self) -> bool {
22 self.enabled && !self.metrics.is_empty()
23 }
24
25 pub fn metrics(&self) -> &[String] {
27 &self.metrics
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn branch_is_not_requested_when_disabled() {
37 let config = AutoscalingFailoverConfiguration::new(false, vec!["custom.metric".to_string()]);
38
39 assert!(!config.is_branch_requested());
40 assert_eq!(config.metrics(), ["custom.metric".to_string()]);
41 }
42
43 #[test]
44 fn branch_is_requested_when_enabled_with_non_empty_metrics() {
45 let config = AutoscalingFailoverConfiguration::new(true, vec!["custom.metric".to_string()]);
46
47 assert!(config.is_branch_requested());
48 assert_eq!(config.metrics(), ["custom.metric".to_string()]);
49 }
50
51 #[test]
52 fn empty_metric_allowlist_disables_branch() {
53 let config = AutoscalingFailoverConfiguration::new(true, Vec::new());
54
55 assert!(!config.is_branch_requested());
56 assert!(config.metrics().is_empty());
57 }
58}