From 371bbeb0a888a6f513b438290f917d2a9a5481cf Mon Sep 17 00:00:00 2001 From: zz_y Date: Fri, 15 May 2026 10:44:08 -0600 Subject: [PATCH] =?UTF-8?q?refactor(types):=20drop=20BackendCollectorConfi?= =?UTF-8?q?g=20=E2=80=94=20pure=20shadow=20state=20of=20AgentCollectorConf?= =?UTF-8?q?ig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that the legacy backend-collector emitter is retired (#241), the `BackendCollectorConfig { merge_sketch_type, group_by }` struct on `CollectionPlan` has no real consumers — both fields are derivative of `AgentCollectorConfig`: - `merge_sketch_type` was always set to `agent_config.sketch_type.clone()` (literally — see the deleted `let backend_sketch = sketch_type.clone();` line in RulesPlanner, and the deleted `backend_config_matches_sketch_type` test that asserted the equality as an invariant). - `group_by` was always `agent_config.aggregate_by.clone()` when set, else `vec![]`. The shadow was a true field-by-field duplicate. Only one site read these fields: the `metrics_exposer` plan-id hash, which already includes `agent_config.sketch_type`. Replaced `backend_config.group_by` with `agent_config.aggregate_by` in the hash (option (b) from review) to preserve the "plan_id changes when grouping changes" observability semantic. Removes: - `pub struct BackendCollectorConfig` + the `pub backend_config` field - 8 initializer sites (store, replan, optimizer/{rules×2, cost test, cost/delta test, cost/mod test}, emit/asapquery_backend test, metrics_exposer test) - 3 mutation sites in the optimizer's sketch-type tuning loops (cost/mod ×2, pareto) - The redundant `backend_config_matches_sketch_type` test in rules/mod.rs - One import of `BackendCollectorConfig` in emit/asapquery_backend.rs Plan-id hash values shift on this release — they're opaque per-plan identifiers, so anyone alerting on specific values was already on shaky ground. The semantics (changes-on-replan, stable-on-refresh) are preserved. Build clean. 686 lib tests + 27 binary tests pass (1 less than before this PR — the deleted redundant-invariant test). Co-Authored-By: Claude Opus 4.7 (1M context) --- control_plane/src/emit/asapquery_backend.rs | 8 ++------ control_plane/src/metrics_exposer.rs | 13 ++++--------- control_plane/src/optimizer/cost/delta.rs | 4 ---- control_plane/src/optimizer/cost/mod.rs | 6 ------ control_plane/src/optimizer/cost/pareto.rs | 1 - control_plane/src/optimizer/rules/mod.rs | 20 -------------------- control_plane/src/replan.rs | 4 ---- control_plane/src/store/mod.rs | 4 ---- control_plane/src/types.rs | 7 ------- 9 files changed, 6 insertions(+), 61 deletions(-) diff --git a/control_plane/src/emit/asapquery_backend.rs b/control_plane/src/emit/asapquery_backend.rs index d306f351e..27c639300 100644 --- a/control_plane/src/emit/asapquery_backend.rs +++ b/control_plane/src/emit/asapquery_backend.rs @@ -166,8 +166,8 @@ fn _type_check(_: &AgentCollectorConfig) {} mod tests { use super::*; use crate::types::{ - AgentDataSink, BackendCollectorConfig, CollectionPlan, DeltaDecision, - GatewayCollectorConfig, OutputMode, ProcessorMode, SketchParams, TransmissionCostSummary, + AgentDataSink, CollectionPlan, DeltaDecision, GatewayCollectorConfig, OutputMode, + ProcessorMode, SketchParams, TransmissionCostSummary, }; use std::time::Duration; @@ -191,10 +191,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: sketch_type, - group_by: vec![], - }, precompute: vec![], valid_until: chrono::Utc::now() + chrono::Duration::seconds(300), delta_decision: DeltaDecision::default(), diff --git a/control_plane/src/metrics_exposer.rs b/control_plane/src/metrics_exposer.rs index 94e332dff..72d337300 100644 --- a/control_plane/src/metrics_exposer.rs +++ b/control_plane/src/metrics_exposer.rs @@ -206,16 +206,15 @@ impl MetricsRegistry { // a label value, doesn't need to be cryptographic. let mut hasher = DefaultHasher::new(); // Cover the fields the planner actually changes per - // re-plan: agent sketch+mode+delta, backend merge+group_by, - // and valid_until (to catch refresh-only re-plans). + // re-plan: agent sketch+mode+delta+grouping, and valid_until + // (to catch refresh-only re-plans). format!( - "{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}", + "{:?}|{:?}|{:?}|{:?}|{:?}|{:?}", plan.agent_config.sketch_type, plan.agent_config.mode, plan.agent_config.delta_transmission, plan.agent_config.window_duration, - plan.backend_config.merge_sketch_type, - plan.backend_config.group_by, + plan.agent_config.aggregate_by, plan.valid_until, ) .hash(&mut hasher); @@ -451,10 +450,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: sketch, - group_by: vec![], - }, precompute: vec![], valid_until: Utc::now() + chrono::Duration::seconds(valid_secs), delta_decision: Default::default(), diff --git a/control_plane/src/optimizer/cost/delta.rs b/control_plane/src/optimizer/cost/delta.rs index 09c37fbed..10025c567 100644 --- a/control_plane/src/optimizer/cost/delta.rs +++ b/control_plane/src/optimizer/cost/delta.rs @@ -516,10 +516,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: st, - group_by: vec![], - }, precompute: vec![], valid_until: Utc::now(), delta_decision: DeltaDecision::default(), diff --git a/control_plane/src/optimizer/cost/mod.rs b/control_plane/src/optimizer/cost/mod.rs index 3d5bc8984..e8322f0a1 100644 --- a/control_plane/src/optimizer/cost/mod.rs +++ b/control_plane/src/optimizer/cost/mod.rs @@ -248,7 +248,6 @@ impl CostModelPlanner { plan.agent_config.sketch_params = params; plan.agent_config.mode = mode; plan.agent_config.window_duration = window_duration; - plan.backend_config.merge_sketch_type = st.clone(); apply_delta_decision_with(&mut plan, w, wc, &table); return plan; } @@ -269,7 +268,6 @@ impl CostModelPlanner { trial.agent_config.sketch_params = params; trial.agent_config.mode = mode; trial.agent_config.window_duration = window_duration; - trial.backend_config.merge_sketch_type = st; let s = score_with(&trial, w, &table); if !s.meets_sla { @@ -1041,10 +1039,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: st, - group_by: vec![], - }, precompute: vec![], valid_until: Utc::now(), delta_decision: DeltaDecision::default(), diff --git a/control_plane/src/optimizer/cost/pareto.rs b/control_plane/src/optimizer/cost/pareto.rs index 2c1d1e3c7..80624aa4d 100644 --- a/control_plane/src/optimizer/cost/pareto.rs +++ b/control_plane/src/optimizer/cost/pareto.rs @@ -116,7 +116,6 @@ pub fn pareto_frontier( plan.agent_config.sketch_params = params; plan.agent_config.mode = mode; plan.agent_config.window_duration = window_duration; - plan.backend_config.merge_sketch_type = st.clone(); // Apply delta decision using the cost table. apply_delta(st.clone(), &mut plan, workload, wc, &table); diff --git a/control_plane/src/optimizer/rules/mod.rs b/control_plane/src/optimizer/rules/mod.rs index 89306fa9d..543f24dd5 100644 --- a/control_plane/src/optimizer/rules/mod.rs +++ b/control_plane/src/optimizer/rules/mod.rs @@ -344,9 +344,6 @@ impl RulesPlanner { .collect(); label_matchers.sort(); - let backend_sketch = sketch_type.clone(); - let group_by = aggregate_by.clone(); - let valid_until = Utc::now() + chrono::Duration::seconds(self.valid_for.as_secs() as i64); CollectionPlan { @@ -371,10 +368,6 @@ impl RulesPlanner { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: backend_sketch, - group_by, - }, precompute: vec![], valid_until, delta_decision: DeltaDecision::default(), @@ -414,10 +407,6 @@ impl RulesPlanner { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: SketchType::DDSketch, - group_by: vec![], - }, precompute: vec![], valid_until, delta_decision: DeltaDecision::default(), @@ -583,15 +572,6 @@ mod tests { ); } - #[test] - fn backend_config_matches_sketch_type() { - let plan = RulesPlanner::new().plan(&workload(vec![AggType::Quantile])); - assert_eq!( - plan.backend_config.merge_sketch_type, - plan.agent_config.sketch_type - ); - } - #[test] fn gateway_passthrough() { let plan = RulesPlanner::new().plan(&workload(vec![AggType::Quantile])); diff --git a/control_plane/src/replan.rs b/control_plane/src/replan.rs index e77e911ae..070a4801c 100644 --- a/control_plane/src/replan.rs +++ b/control_plane/src/replan.rs @@ -509,10 +509,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: SketchType::DDSketch, - group_by: vec![], - }, precompute: vec![], valid_until: Utc::now() + chrono::Duration::seconds(3600), delta_decision: DeltaDecision::default(), diff --git a/control_plane/src/store/mod.rs b/control_plane/src/store/mod.rs index 140185a1c..bf292f181 100644 --- a/control_plane/src/store/mod.rs +++ b/control_plane/src/store/mod.rs @@ -177,10 +177,6 @@ mod tests { data_sink: AgentDataSink::default(), }, gateway_config: GatewayCollectorConfig { passthrough: true }, - backend_config: BackendCollectorConfig { - merge_sketch_type: SketchType::DDSketch, - group_by: vec![], - }, precompute: vec![], valid_until, delta_decision: DeltaDecision::default(), diff --git a/control_plane/src/types.rs b/control_plane/src/types.rs index c20523d07..dd67ff625 100644 --- a/control_plane/src/types.rs +++ b/control_plane/src/types.rs @@ -518,12 +518,6 @@ pub struct GatewayCollectorConfig { pub passthrough: bool, } -#[derive(Debug, Clone)] -pub struct BackendCollectorConfig { - pub merge_sketch_type: SketchType, - pub group_by: Vec, -} - #[derive(Debug, Clone)] pub struct PrecomputeJob { pub query_expr: String, @@ -570,7 +564,6 @@ impl StageResourceBudgets { pub struct CollectionPlan { pub agent_config: AgentCollectorConfig, pub gateway_config: GatewayCollectorConfig, - pub backend_config: BackendCollectorConfig, pub precompute: Vec, pub valid_until: DateTime, /// Resolved delta transmission decision and rationale.