Skip to content

Commit c976121

Browse files
zzylolclaude
andcommitted
fix: price installed retention and shared source maintenance consistently
Price derived maintenance lookbacks and native retained candidates from installed window layouts. Use optional fresh per-metric sample-rate evidence for both retained updates and raw folds, and charge generated shared Sum panes once across logical lookbacks while preserving each read cost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e899d10 commit c976121

5 files changed

Lines changed: 394 additions & 18 deletions

File tree

‎control_plane/src/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ fn compile_physical_plan_request(
661661
planner_selection_trace: planner_selection_trace.into(),
662662
query_workload: Some(query_workload),
663663
data_workload: Some(request.data_workload),
664+
source_ingestion_rates: Default::default(),
664665
canonical_roots,
665666
queries,
666667
allow_mixed_summary_and_exact_execution: request.target

‎control_plane/src/physical/compiler.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ pub struct PhysicalCompilationRequest {
216216
pub query_workload: Option<QueryWorkload>,
217217
/// Source evidence supplied independently from query demand.
218218
pub data_workload: Option<DataWorkload>,
219+
/// Per-metric samples/second used to price raw selector folds.
220+
pub source_ingestion_rates: BTreeMap<String, Evidence<Rate>>,
219221
/// Workload-lowered roots retained across physical candidate enumeration.
220222
pub canonical_roots: Vec<Rc<QueryExpr>>,
221223
pub queries: Vec<QueryCompilationInput>,
@@ -438,6 +440,10 @@ pub struct BackendLocalPhysicalInputs {
438440
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
439441
pub require_backend_local_execution: bool,
440442
pub lifecycle_costs: LifecycleUnitCosts,
443+
/// Samples/second by metric, before label filtering. Missing or stale
444+
/// evidence falls back to the conservative workload-wide ingestion rate.
445+
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
446+
pub source_ingestion_rates: BTreeMap<String, Evidence<Rate>>,
441447
pub evidence_observed_at_unix_ms: u64,
442448
pub evidence_valid_for_ms: u64,
443449
pub horizon_seconds: f64,
@@ -855,6 +861,18 @@ impl BackendLocalPlanningInput {
855861
"compatibility workload requires backend_local_remote_write target".into(),
856862
));
857863
}
864+
for (metric, evidence) in &self.physical_inputs.source_ingestion_rates {
865+
if metric.trim().is_empty()
866+
|| evidence
867+
.value
868+
.is_some_and(|rate| !rate.0.is_finite() || rate.0 < 0.0)
869+
{
870+
return Err(CompileError::Snapshot(
871+
"source_ingestion_rates requires named metrics and finite nonnegative rates"
872+
.into(),
873+
));
874+
}
875+
}
858876
let workload = self.query_workload;
859877
let mut data_workload = self.data_workload.clone();
860878
let scoped_snapshot_id = self
@@ -1168,6 +1186,7 @@ impl BackendLocalPlanningInput {
11681186
require_backend_local_execution: self.physical_inputs.require_backend_local_execution,
11691187
query_workload: Some(workload),
11701188
data_workload: Some(data_workload),
1189+
source_ingestion_rates: self.physical_inputs.source_ingestion_rates,
11711190
canonical_roots,
11721191
queries,
11731192
topk_membership_evidence_by_query_id: topk_evidence_by_id,
@@ -6026,6 +6045,7 @@ pub(crate) mod tests {
60266045
require_backend_local_execution: false,
60276046
query_workload: None,
60286047
data_workload: None,
6048+
source_ingestion_rates: BTreeMap::new(),
60296049
queries: vec![QueryCompilationInput {
60306050
query_id: query_id.into(),
60316051
query_string: promql.into(),
@@ -8927,6 +8947,7 @@ pub(crate) mod tests {
89278947
physical_inputs: BackendLocalPhysicalInputs {
89288948
require_backend_local_execution: false,
89298949
lifecycle_costs: template.summary_lifecycle_inputs.costs,
8950+
source_ingestion_rates: BTreeMap::new(),
89308951
evidence_observed_at_unix_ms: 9_500,
89318952
evidence_valid_for_ms: 60_000,
89328953
horizon_seconds: 300.0,

0 commit comments

Comments
 (0)