Skip to content

Commit 4ff7891

Browse files
committed
fix(stack): validate runtime policies with canonical families
1 parent 02427af commit 4ff7891

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

‎control_plane/src/physical/compiler.rs‎

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl TransmissionPlan {
11211121

11221122
fn validate_runtime_rule_policy(
11231123
rule: &TransmissionRule,
1124-
family: &asap_types::SummaryKind,
1124+
family: &StateFamilyContract,
11251125
) -> Result<(), TransmissionPlanError> {
11261126
let invalid = |reason: &str| TransmissionPlanError::InvalidRuntimePolicy {
11271127
producer_id: rule.producer_id.clone(),
@@ -1138,11 +1138,17 @@ fn validate_runtime_rule_policy(
11381138
let supported = matches!(
11391139
(family, *estimator),
11401140
(
1141-
asap_types::SummaryKind::Hll,
1142-
SamplingEstimator::HashThreshold
1141+
StateFamilyContract::Sketch {
1142+
algorithm: SketchAlgorithm::Hll,
1143+
..
1144+
},
1145+
SamplingEstimator::HashThreshold,
11431146
) | (
1144-
asap_types::SummaryKind::Cms | asap_types::SummaryKind::CmsWithHeap,
1145-
SamplingEstimator::GeometricAdmission
1147+
StateFamilyContract::Sketch {
1148+
algorithm: SketchAlgorithm::Cms | SketchAlgorithm::CmsWithHeap,
1149+
..
1150+
},
1151+
SamplingEstimator::GeometricAdmission,
11461152
)
11471153
);
11481154
if !supported {
@@ -1163,12 +1169,15 @@ fn validate_runtime_rule_policy(
11631169
}
11641170
if !matches!(
11651171
family,
1166-
asap_types::SummaryKind::DDSketch
1167-
| asap_types::SummaryKind::Hll
1168-
| asap_types::SummaryKind::Cms
1169-
| asap_types::SummaryKind::CmsWithHeap
1170-
| asap_types::SummaryKind::CountSketch
1171-
| asap_types::SummaryKind::CountSketchWithHeap
1172+
StateFamilyContract::Sketch {
1173+
algorithm: SketchAlgorithm::DDSketch
1174+
| SketchAlgorithm::Hll
1175+
| SketchAlgorithm::Cms
1176+
| SketchAlgorithm::CmsWithHeap
1177+
| SketchAlgorithm::CountSketch
1178+
| SketchAlgorithm::CountSketchWithHeap,
1179+
..
1180+
}
11721181
) {
11731182
return Err(invalid(
11741183
"delta transmission is not implemented for the materialization family",
@@ -1177,7 +1186,10 @@ fn validate_runtime_rule_policy(
11771186
if let Some(gos) = &delta.gos {
11781187
if !matches!(
11791188
family,
1180-
asap_types::SummaryKind::CountSketch | asap_types::SummaryKind::CountSketchWithHeap
1189+
StateFamilyContract::Sketch {
1190+
algorithm: SketchAlgorithm::CountSketch | SketchAlgorithm::CountSketchWithHeap,
1191+
..
1192+
}
11811193
) || !gos.epsilon_staleness.is_finite()
11821194
|| !(0.0..=1.0).contains(&gos.epsilon_staleness)
11831195
|| gos.epsilon_staleness == 0.0
@@ -2524,10 +2536,20 @@ mod tests {
25242536
probability: 0.5,
25252537
estimator: SamplingEstimator::HashThreshold,
25262538
};
2527-
validate_runtime_rule_policy(&rule, &asap_types::SummaryKind::Hll)
2528-
.expect("HLL supports hash-threshold sampling");
2539+
let hll = StateFamilyContract::Sketch {
2540+
algorithm: SketchAlgorithm::Hll,
2541+
parameters: SketchParams::Hll { precision: 14 },
2542+
};
2543+
let count_sketch = StateFamilyContract::Sketch {
2544+
algorithm: SketchAlgorithm::CountSketch,
2545+
parameters: SketchParams::CountSketch {
2546+
width: 128,
2547+
depth: 4,
2548+
},
2549+
};
2550+
validate_runtime_rule_policy(&rule, &hll).expect("HLL supports hash-threshold sampling");
25292551
assert!(matches!(
2530-
validate_runtime_rule_policy(&rule, &asap_types::SummaryKind::CountSketch),
2552+
validate_runtime_rule_policy(&rule, &count_sketch),
25312553
Err(TransmissionPlanError::InvalidRuntimePolicy { .. })
25322554
));
25332555

@@ -2542,10 +2564,9 @@ mod tests {
25422564
threshold_mode: GosThresholdMode::Isotropic,
25432565
}),
25442566
});
2545-
validate_runtime_rule_policy(&rule, &asap_types::SummaryKind::CountSketch)
2546-
.expect("CountSketch supports delta GOS");
2567+
validate_runtime_rule_policy(&rule, &count_sketch).expect("CountSketch supports delta GOS");
25472568
assert!(matches!(
2548-
validate_runtime_rule_policy(&rule, &asap_types::SummaryKind::Hll),
2569+
validate_runtime_rule_policy(&rule, &hll),
25492570
Err(TransmissionPlanError::InvalidRuntimePolicy { .. })
25502571
));
25512572
}

‎data_plane/src/drivers/ingest/otel.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ fn preflight_summary_frames(
22032203
.map(|entry| (entry.core.clone_boxed_core(), entry.window_start))
22042204
.or_else(|| {
22052205
empty_accumulator_for_delta_bootstrap(
2206-
dp.kind,
2206+
dp.algorithm.clone(),
22072207
&dp.container_config,
22082208
dp.encoding,
22092209
)
@@ -2215,8 +2215,13 @@ fn preflight_summary_frames(
22152215
if base_window_start != dp.start_time_unix_nano {
22162216
base.reset_to_empty();
22172217
}
2218-
apply_modified_otlp_delta_bytes(dp.kind, dp.encoding, &mut base, &dp.sketch)
2219-
.map_err(|error| format!("invalid delta frame for {metric_name}: {error}"))?;
2218+
apply_modified_otlp_delta_bytes(
2219+
dp.algorithm.clone(),
2220+
dp.encoding,
2221+
&mut base,
2222+
&dp.sketch,
2223+
)
2224+
.map_err(|error| format!("invalid delta frame for {metric_name}: {error}"))?;
22202225
}
22212226

22222227
// Attribute-elided retries can recover the policy from their known

0 commit comments

Comments
 (0)