saluki_components/config/
autoscaling_failover.rs

1//! Autoscaling failover configuration.
2
3/// Autoscaling failover configuration for the metrics pipeline.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct AutoscalingFailoverConfiguration {
6    enabled: bool,
7    metrics: Vec<String>,
8}
9
10impl AutoscalingFailoverConfiguration {
11    /// Creates a new `AutoscalingFailoverConfiguration`.
12    ///
13    /// `enabled` is whether autoscaling failover is requested (`is_branch_requested` also requires a non-empty
14    /// `metrics`), and `metrics` is the allowlist of metric names eligible for the failover branch. Both values arrive
15    /// already resolved: the configuration layer owns their defaults, so this constructor applies none of its own.
16    pub fn new(enabled: bool, metrics: Vec<String>) -> Self {
17        Self { enabled, metrics }
18    }
19
20    /// Returns whether the autoscaling failover branch is requested by configuration.
21    pub fn is_branch_requested(&self) -> bool {
22        self.enabled && !self.metrics.is_empty()
23    }
24
25    /// Returns the metric name allowlist.
26    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}