Skip to content

Commit e867851

Browse files
committed
chore(config): migrate autoscaling failover to typed config
Build the autoscaling failover component from its translated shared configuration and keep source parsing at the configuration boundary. (cherry picked from commit 80c8c20)
1 parent 53f9087 commit e867851

3 files changed

Lines changed: 35 additions & 123 deletions

File tree

bin/agent-data-plane/src/cli/run.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ async fn create_topology(
410410
}
411411

412412
if dp_config.metrics_pipeline_required() {
413-
add_baseline_metrics_pipeline_to_blueprint(&mut blueprint, config, dp_config, env_provider).await?;
413+
add_baseline_metrics_pipeline_to_blueprint(&mut blueprint, config, config_system, dp_config, env_provider)
414+
.await?;
414415
}
415416

416417
if dp_config.logs_pipeline_required() {
@@ -464,8 +465,8 @@ async fn add_checks_pipeline_to_blueprint(
464465
}
465466

466467
async fn add_baseline_metrics_pipeline_to_blueprint(
467-
blueprint: &mut TopologyBlueprint, config: &GenericConfiguration, dp_config: &DataPlaneConfiguration,
468-
env_provider: &ADPEnvironmentProvider,
468+
blueprint: &mut TopologyBlueprint, config: &GenericConfiguration, config_system: &ConfigurationSystem,
469+
dp_config: &DataPlaneConfiguration, env_provider: &ADPEnvironmentProvider,
469470
) -> Result<(), GenericError> {
470471
// Create the back half of the metrics processing pipeline.
471472
let host_enrichment_config = HostEnrichmentConfiguration::from_environment_provider(env_provider.clone());
@@ -490,7 +491,8 @@ async fn add_baseline_metrics_pipeline_to_blueprint(
490491
.connect_components_in_order(["metrics_enrich", "dd_metrics_encode", "dd_out"])?;
491492

492493
add_mrf_metrics_pipeline_to_blueprint(blueprint, config)?;
493-
add_autoscaling_failover_metrics_pipeline_to_blueprint(blueprint, config)?;
494+
let saluki = config_system.config();
495+
add_autoscaling_failover_metrics_pipeline_to_blueprint(blueprint, config, &saluki.shared.autoscaling_failover)?;
494496

495497
Ok(())
496498
}
@@ -544,8 +546,9 @@ fn add_mrf_metrics_pipeline_to_blueprint(
544546

545547
fn add_autoscaling_failover_metrics_pipeline_to_blueprint(
546548
blueprint: &mut TopologyBlueprint, config: &GenericConfiguration,
549+
autoscaling_failover: &agent_data_plane_config::shared::AutoscalingFailover,
547550
) -> Result<(), GenericError> {
548-
let af_config = AutoscalingFailoverConfiguration::from_configuration(config)
551+
let af_config = AutoscalingFailoverConfiguration::from_configuration(autoscaling_failover)
549552
.error_context("Failed to configure autoscaling failover metrics pipeline.")?;
550553
let ca_config = ClusterAgentConfiguration::from_configuration(config)
551554
.error_context("Failed to configure Cluster Agent metrics forwarding.")?;
Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
//! Autoscaling failover configuration.
22
3-
use saluki_config::GenericConfiguration;
3+
use agent_data_plane_config::shared::AutoscalingFailover;
44
use saluki_error::GenericError;
55

6-
fn default_metrics() -> Vec<String> {
7-
vec!["container.memory.usage".to_string(), "container.cpu.usage".to_string()]
8-
}
9-
106
/// Autoscaling failover configuration for the metrics pipeline.
117
#[derive(Clone, Debug, Eq, PartialEq)]
128
pub struct AutoscalingFailoverConfiguration {
@@ -15,13 +11,11 @@ pub struct AutoscalingFailoverConfiguration {
1511
}
1612

1713
impl AutoscalingFailoverConfiguration {
18-
/// Creates a new `AutoscalingFailoverConfiguration` from the given configuration.
19-
pub fn from_configuration(config: &GenericConfiguration) -> Result<Self, GenericError> {
14+
/// Builds an `AutoscalingFailoverConfiguration` from the translated failover settings.
15+
pub fn from_configuration(config: &AutoscalingFailover) -> Result<Self, GenericError> {
2016
Ok(Self {
21-
enabled: config.try_get_typed("autoscaling.failover.enabled")?.unwrap_or(false),
22-
metrics: config
23-
.try_get_typed("autoscaling.failover.metrics")?
24-
.unwrap_or_else(default_metrics),
17+
enabled: config.enabled,
18+
metrics: config.metrics.clone(),
2519
})
2620
}
2721

@@ -35,60 +29,3 @@ impl AutoscalingFailoverConfiguration {
3529
&self.metrics
3630
}
3731
}
38-
39-
#[cfg(test)]
40-
mod tests {
41-
use saluki_config::ConfigurationLoader;
42-
use serde_json::json;
43-
44-
use super::*;
45-
46-
async fn autoscaling_config_from(value: serde_json::Value) -> AutoscalingFailoverConfiguration {
47-
let (config, _) = ConfigurationLoader::for_tests(Some(value), None, false).await;
48-
AutoscalingFailoverConfiguration::from_configuration(&config)
49-
.expect("autoscaling failover configuration should deserialize")
50-
}
51-
52-
#[tokio::test]
53-
async fn defaults_to_disabled_with_default_metric_allowlist() {
54-
let config = autoscaling_config_from(json!({})).await;
55-
56-
assert!(!config.is_branch_requested());
57-
assert_eq!(
58-
config.metrics(),
59-
["container.memory.usage".to_string(), "container.cpu.usage".to_string()]
60-
);
61-
}
62-
63-
#[tokio::test]
64-
async fn branch_is_requested_when_enabled_with_non_empty_metrics() {
65-
let config = autoscaling_config_from(json!({
66-
"autoscaling": {
67-
"failover": {
68-
"enabled": true,
69-
"metrics": ["custom.metric"]
70-
}
71-
}
72-
}))
73-
.await;
74-
75-
assert!(config.is_branch_requested());
76-
assert_eq!(config.metrics(), ["custom.metric".to_string()]);
77-
}
78-
79-
#[tokio::test]
80-
async fn empty_metric_allowlist_disables_branch() {
81-
let config = autoscaling_config_from(json!({
82-
"autoscaling": {
83-
"failover": {
84-
"enabled": true,
85-
"metrics": []
86-
}
87-
}
88-
}))
89-
.await;
90-
91-
assert!(!config.is_branch_requested());
92-
assert!(config.metrics().is_empty());
93-
}
94-
}

lib/saluki-components/src/transforms/autoscaling_failover_gateway/mod.rs

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -169,60 +169,40 @@ impl Transform for AutoscalingFailoverGateway {
169169
mod tests {
170170
use std::time::Duration;
171171

172-
use saluki_config::ConfigurationLoader;
172+
use agent_data_plane_config::shared::AutoscalingFailover;
173173
use saluki_core::data_model::event::{metric::Metric, Event};
174-
use serde_json::json;
175174

176175
use super::*;
177176

178-
async fn gateway_from_config(value: serde_json::Value) -> AutoscalingFailoverGateway {
179-
let (config, _) = ConfigurationLoader::for_tests(Some(value), None, false).await;
180-
let failover_config = AutoscalingFailoverConfiguration::from_configuration(&config)
181-
.expect("autoscaling failover configuration should deserialize");
177+
fn gateway_from_config(enabled: bool, metrics: Vec<&str>) -> AutoscalingFailoverGateway {
178+
let failover_config = AutoscalingFailoverConfiguration::from_configuration(&AutoscalingFailover {
179+
enabled,
180+
metrics: metrics.into_iter().map(String::from).collect(),
181+
})
182+
.expect("autoscaling failover configuration should build");
182183
AutoscalingFailoverGateway::new(failover_config)
183184
}
184185

185-
#[tokio::test]
186-
async fn inactive_gateway_drops_everything() {
187-
let gw = gateway_from_config(json!({
188-
"autoscaling": {
189-
"failover": {
190-
"enabled": false,
191-
"metrics": ["allowed.metric"]
192-
}
193-
}
194-
}))
195-
.await;
186+
#[test]
187+
fn inactive_gateway_drops_everything() {
188+
let gw = gateway_from_config(false, vec!["allowed.metric"]);
196189

197190
assert!(!gw.should_forward(&Event::Metric(Metric::counter("allowed.metric", 1.0))));
198191
}
199192

200-
#[tokio::test]
201-
async fn empty_metric_allowlist_drops_everything() {
202-
let gw = gateway_from_config(json!({
203-
"autoscaling": {
204-
"failover": {
205-
"enabled": true,
206-
"metrics": []
207-
}
208-
}
209-
}))
210-
.await;
193+
#[test]
194+
fn empty_metric_allowlist_drops_everything() {
195+
let gw = gateway_from_config(true, vec![]);
211196

212197
assert!(!gw.should_forward(&Event::Metric(Metric::counter("allowed.metric", 1.0))));
213198
}
214199

215-
#[tokio::test]
216-
async fn active_gateway_forwards_only_allowed_series_metrics() {
217-
let gw = gateway_from_config(json!({
218-
"autoscaling": {
219-
"failover": {
220-
"enabled": true,
221-
"metrics": ["allowed.counter", "allowed.gauge", "allowed.rate", "allowed.set"]
222-
}
223-
}
224-
}))
225-
.await;
200+
#[test]
201+
fn active_gateway_forwards_only_allowed_series_metrics() {
202+
let gw = gateway_from_config(
203+
true,
204+
vec!["allowed.counter", "allowed.gauge", "allowed.rate", "allowed.set"],
205+
);
226206

227207
assert!(gw.should_forward(&Event::Metric(Metric::counter("allowed.counter", 1.0))));
228208
assert!(gw.should_forward(&Event::Metric(Metric::gauge("allowed.gauge", 1.0))));
@@ -235,17 +215,9 @@ mod tests {
235215
assert!(!gw.should_forward(&Event::Metric(Metric::counter("blocked.counter", 1.0))));
236216
}
237217

238-
#[tokio::test]
239-
async fn active_gateway_drops_sketch_metrics_even_when_allowed() {
240-
let gw = gateway_from_config(json!({
241-
"autoscaling": {
242-
"failover": {
243-
"enabled": true,
244-
"metrics": ["allowed.histogram", "allowed.distribution"]
245-
}
246-
}
247-
}))
248-
.await;
218+
#[test]
219+
fn active_gateway_drops_sketch_metrics_even_when_allowed() {
220+
let gw = gateway_from_config(true, vec!["allowed.histogram", "allowed.distribution"]);
249221

250222
assert!(!gw.should_forward(&Event::Metric(Metric::histogram("allowed.histogram", [1.0, 2.0, 3.0]))));
251223
assert!(!gw.should_forward(&Event::Metric(Metric::distribution(

0 commit comments

Comments
 (0)