diff --git a/src/promql/src/native/execute/tests.rs b/src/promql/src/native/execute/tests.rs index d091ee834f5..1efe50d9eaa 100644 --- a/src/promql/src/native/execute/tests.rs +++ b/src/promql/src/native/execute/tests.rs @@ -988,7 +988,6 @@ fn deep_native_tree_executes_after_fused_series_round_trip() { let output_schema = Arc::new(DFSchema::try_from(output_schema.as_ref().clone()).unwrap()); let node = FusedSeries::try_new_with_format( - Arc::from("deep"), tree, FusedSeriesBinding { grid: Arc::clone(&grid), diff --git a/src/query/src/promql/native_compile/tests.rs b/src/query/src/promql/native_compile/tests.rs index 6210d60465b..0bf16ead737 100644 --- a/src/query/src/promql/native_compile/tests.rs +++ b/src/query/src/promql/native_compile/tests.rs @@ -4353,12 +4353,12 @@ fn absent_over_time_binds_absent_over_a_presence_read() { let tree = compile(&eval_stmt(query), raw_schema(), SeriesOrdering::KeyThenTime) .unwrap_or_else(|error| panic!("`{query}` was refused: {error}")); let display = tree.to_string(); - let root = display.lines().nth(1).expect("a compiled tree has a root"); - assert_eq!(root, format!(" root Vector {op}"), "`{query}`"); + let root = display.lines().next().expect("a compiled tree has a root"); + assert_eq!(root, format!("Vector: {op}"), "`{query}`"); // The fold that reports presence keeps the metric name, so two discovered metrics that // share their ordinary labels stay two series on the way up: `present_over_time` drops it. assert!( - display.contains("input Window last_over_time [300000ms]"), + display.contains(" Window: last_over_time [300000ms]"), "`{query}` does not read its window through the presence fold: {display}" ); } diff --git a/src/query/src/promql/planner/native.rs b/src/query/src/promql/planner/native.rs index 37fdccc3999..bd210bf09a1 100644 --- a/src/query/src/promql/planner/native.rs +++ b/src/query/src/promql/planner/native.rs @@ -3112,12 +3112,8 @@ fn plan_split_aggregate( }, ..binding.clone() }; - let partial = FusedSeries::try_new_state_export( - partial, - partial_binding, - vec![rawinput], - ) - .context(DataFusionPlanningSnafu)?; + let partial = FusedSeries::try_new_state_export(partial, partial_binding, vec![rawinput]) + .context(DataFusionPlanningSnafu)?; let output_schema = match format { FusedOutputFormat::PlainRows => value_schema, // The final node's output is the frame its own evaluated root declares, so it is derived diff --git a/src/query/src/promql/planner/test.rs b/src/query/src/promql/planner/test.rs index 88c95306905..ba31797058a 100644 --- a/src/query/src/promql/planner/test.rs +++ b/src/query/src/promql/planner/test.rs @@ -2508,14 +2508,14 @@ async fn native_absent_over_time_plans_over_discovered_metrics() { let fused = find_fused_series(&plan).expect("fused plan"); let tree = fused.tree().to_string(); assert!( - tree.contains(r#"root Vector absent {no_such_label="x", tag_0="api"}"#), + tree.contains(r#"Vector: absent {no_such_label="x", tag_0="api"}"#), "the labels are the selector's matchers: {tree}" ); // A statement whose window runs where its samples are is planned as one tree per stage, so the // presence read is asserted across the plan rather than under the root node the frontend holds. let trees = fused_trees(&plan).join("\n"); assert!( - trees.contains("Window last_over_time [300000ms]"), + trees.contains("Window: last_over_time [300000ms]"), "the presence read folds the window: {trees}" ); // The metric name is not a label of an `absent` answer, so the output has none. @@ -2547,7 +2547,7 @@ async fn native_absent_over_time_plans_over_discovered_metrics() { let fused = find_fused_series(&plan).expect("fused plan"); let tree = fused.tree().to_string(); assert!( - tree.contains(r#"root Vector absent {no_such_label="x", tag_0="api"}"#), + tree.contains(r#"Vector: absent {no_such_label="x", tag_0="api"}"#), "a selector that matched no table still answers its matchers: {tree}" ); @@ -2585,7 +2585,7 @@ async fn native_absent_over_time_plans_over_discovered_metrics() { let fused = find_fused_series(&plan).expect("fused plan"); let tree = fused.tree().to_string(); assert!( - tree.contains(r#"root Vector absent {tag_0="x"}"#), + tree.contains(r#"Vector: absent {tag_0="x"}"#), "a named metric is not a label of the answer: {tree}" ); } diff --git a/tests-integration/src/tests/native_aggregate_test.rs b/tests-integration/src/tests/native_aggregate_test.rs index f4c466b8f0d..4301ac3cd12 100644 --- a/tests-integration/src/tests/native_aggregate_test.rs +++ b/tests-integration/src/tests/native_aggregate_test.rs @@ -1286,9 +1286,14 @@ fn fused_node_count_per_partition( ) -> Vec> { let mut per_partition = vec![None; SCAN_PARTITIONS]; let plan = displayable(fused.as_ref()).indent(false).to_string(); + // The tree's registrations live in the node's own set: `ExecutionPlan::metrics` leaves them + // out, since a flat set cannot say which node recorded what. let metrics = fused - .metrics() - .unwrap_or_else(|| panic!("{context}: the fused producer reports no metrics:\n{plan}")); + .downcast_ref::() + .unwrap_or_else(|| { + panic!("{context}: the fused producer is not a FusedSeriesExec:\n{plan}") + }) + .node_metric_set(); for metric in metrics.iter() { let MetricValue::Count { count, .. } = metric.value() else { continue; @@ -1335,8 +1340,9 @@ fn final_input_samples_per_partition(capture: &NativeCapture, context: &str) -> for finalize in &capture.finalize { let plan = displayable(finalize.as_ref()).indent(false).to_string(); let metrics = finalize - .metrics() - .unwrap_or_else(|| panic!("{context}: Final reports no metrics:\n{plan}")); + .downcast_ref::() + .unwrap_or_else(|| panic!("{context}: Final is not a FusedSeriesExec:\n{plan}")) + .node_metric_set(); for metric in metrics.iter() { let MetricValue::Count { count, .. } = metric.value() else { continue; @@ -1543,13 +1549,17 @@ fn assert_finalize_reads_region_state( "{context}: Final input must preserve the Partial state-frame schema:\n{plan}" ); let producer_plan = NodeDisplay(producer.as_ref()).to_string(); + // The node's own line, then `native_tree=[`, then the tree: the first line inside the brackets + // is the root of the tree it runs, unindented and without a path prefix. let root_line = producer_plan .lines() .map(str::trim) - .find(|line| line.starts_with("root ") || line.starts_with("root:")) + .find(|line| { + !line.starts_with("FusedSeriesExec") && !matches!(*line, "native_tree=[" | "]") + }) .unwrap_or_default(); assert!( - root_line.contains("Aggregate") && root_line.contains("partial"), + root_line.starts_with("Aggregate:") && root_line.contains(" partial"), "{context}: captured region producer must have a Partial root, got `{root_line}`:\n{producer_plan}" ); let declaration = @@ -2117,19 +2127,26 @@ async fn native_aggregate_topk_over_global_partitions() { expected.sort_by(|a, b| (a.ts_millis, &a.labels).cmp(&(b.ts_millis, &b.labels))); assert_native_schema(&native, "v", &expected, &sql); assert_rows(&native.rows, &expected, &format!("expected `{sql}`")); - // `topk` above a global aggregate is not split, so the scan side folds per series and the - // ranking runs above it. A plan may hold several fused nodes (the frontend root and the region - // producers), so select them by what they do instead of counting nodes. + // `topk` above a global aggregate is not split, so the scan side answers the rate it reads and + // the ranking runs above the merged groups. A plan may hold several fused nodes (the frontend + // root and the region producers), so select them by what they do instead of counting nodes: a + // producer's tree reads raw samples, and only the node above them ranks. let plan_text = |node: &Arc| displayable(node.as_ref()).indent(false).to_string(); let producers: Vec<_> = capture .fused .iter() - .filter(|node| plan_text(node).contains("segment")) + .filter(|node| plan_text(node).contains("Input: raw samples")) .collect(); assert!( !producers.is_empty(), - "a segmented producer answers the fold" + "a segmented producer answers the scan it was given; fused nodes:\n{}", + capture + .fused + .iter() + .map(|node| plan_text(node)) + .collect::>() + .join("\n=====\n") ); for producer in &producers { assert!( @@ -2145,6 +2162,13 @@ async fn native_aggregate_topk_over_global_partitions() { .filter(|node| plan_text(node).to_ascii_lowercase().contains("topk")) .collect(); assert_eq!(1, ranked.len(), "topk runs once, above the merged groups"); + let ranked_text = plan_text(ranked[0]); + assert!( + ranked_text.contains("Vector: topk 10 by []") + && ranked_text.contains("Aggregate: sum by [hostname] complete") + && ranked_text.contains("Input: evaluated samples source=0, contiguous"), + "the fold answers the merged sources whole, with the ranking above it:\n{ranked_text}" + ); // The cross-producer requirement lives in the deterministic fixtures instead, which pin which // suffixes the split accepts above the cut and which it declines // (`native_fused_split_declines_a_whole_vector_suffix`). diff --git a/tests-integration/src/tests/promql_test.rs b/tests-integration/src/tests/promql_test.rs index fe16368b425..b22e39a1ea1 100644 --- a/tests-integration/src/tests/promql_test.rs +++ b/tests-integration/src/tests/promql_test.rs @@ -2405,6 +2405,18 @@ fn assert_two_source_native_plan( assert_eq!(display.matches("source=1").count(), 1, "{display}"); } +/// The registrations the fused node's tree made, exactly as they were recorded. +/// +/// [`datafusion::physical_plan::ExecutionPlan::metrics`] leaves them out: a flat set cannot say +/// which tree node recorded what, so the node keeps its own set for readers that key by name. +fn fused_metric_set( + plan: &Arc, +) -> datafusion::physical_plan::metrics::MetricsSet { + plan.downcast_ref::() + .unwrap_or_else(|| panic!("the plan is a FusedSeriesExec, not {}", plan.name())) + .node_metric_set() +} + fn output_values_per_partition( plan: &Arc, ) -> Option> { @@ -2414,7 +2426,7 @@ fn output_values_per_partition( return None; } let partition_count = plan.output_partitioning().partition_count(); - let metrics = plan.metrics()?; + let metrics = fused_metric_set(plan); let mut values_by_partition = vec![0_u64; partition_count]; let mut found_metric = false; for metric in metrics.iter() { @@ -2705,9 +2717,7 @@ fn nonempty_partitions( use datafusion::physical_plan::metrics::MetricValue; let partition_count = plan.output_partitioning().partition_count(); - let metrics = plan - .metrics() - .unwrap_or_else(|| panic!("the plan reports metrics: {}", display_plan_tree(plan))); + let metrics = fused_metric_set(plan); let mut recorded = vec![0_u64; partition_count]; let mut found = false; for entry in metrics.iter() { @@ -4881,7 +4891,17 @@ async fn distributed_native_promql_zero_match_or_real() { "{}", datafusion::physical_plan::displayable(fused.as_ref()).one_line() ); - assert!(display.contains("root Set or"), "{expression}: {display}"); + // The node draws the tree it runs, one line per node: no query string, no path prefix and + // no `segment` wording, and the set names its own operator and matching labels. + assert!( + display.contains("native_tree=[\nSet: or ignoring []"), + "{expression}: {display}" + ); + assert!( + display.contains("\n Input: evaluated samples source=0, contiguous") + && display.contains("\n Input: evaluated samples source=1, contiguous"), + "{expression}: {display}" + ); let children = fused.children(); assert_eq!(children.len(), 2, "{expression}: {display}"); assert!( @@ -5518,9 +5538,7 @@ async fn native_promql_label_rewrites_reach_the_native_route_and_keep_prometheus let split_rows = native_result_rows(split_parts).await; assert_eq!(split_rows.len(), 2, "{split_rows:?}"); let split_plan = observer.take(); - let nonempty = split_plan - .metrics() - .expect("fused plan metrics") + let nonempty = fused_metric_set(&split_plan) .iter() .filter(|metric| metric.value().name() == "native.root.output_values") .filter_map(|metric| match metric.value() { @@ -6830,9 +6848,7 @@ async fn native_promql_instant_at_uses_sample_time_and_anchor() { let native_rows = native_result_rows(native).await; let plan = observer.take(); assert_eq!(plan.name(), "FusedSeriesExec", "{expr}"); - let output_count = plan - .metrics() - .unwrap() + let output_count = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -7085,9 +7101,7 @@ async fn native_promql_binary_join_uses_two_independent_scans() { let plan = observer.take(); assert_eq!(plan.name(), "FusedSeriesExec"); assert_two_source_native_plan(&observer, &plan, true); - let input_samples = plan - .metrics() - .expect("fused metrics") + let input_samples = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -7107,9 +7121,7 @@ async fn native_promql_binary_join_uses_two_independent_scans() { ("native.root.left.input_samples", HOSTS * 4), ("native.root.right.input_samples", HOSTS * 2), ] { - let source_samples = plan - .metrics() - .expect("fused metrics") + let source_samples = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -9403,9 +9415,7 @@ async fn native_promql_repeated_selector_binary_uses_independent_scans() { scan_frame_rows, 1, "the anchored range returns one packed raw-series frame" ); - let root_values = bounded_plan - .metrics() - .expect("fused metrics") + let root_values = fused_metric_set(&bounded_plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -9417,9 +9427,7 @@ async fn native_promql_repeated_selector_binary_uses_independent_scans() { }) .sum::(); assert_eq!(root_values, 1, "the bounded native result was executed"); - let root_input_samples = bounded_plan - .metrics() - .expect("fused metrics") + let root_input_samples = fused_metric_set(&bounded_plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -9779,9 +9787,7 @@ async fn native_promql_explain_and_analyze_execute_fused_plan() { assert!(text.contains("FusedSeriesExec")); assert!(text.contains("output_values")); let plan = observer.take(); - let output_values = plan - .metrics() - .expect("fused plan metrics") + let output_values = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -11777,9 +11783,7 @@ async fn native_promql_columnar_fused_series_matches_legacy() { .all(|entry| entry["artifact"]["format"] == "columnar-series") ); // One value per series: the node ran, rather than being merely planned. - let output_values = plan - .metrics() - .expect("fused plan metrics") + let output_values = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -11875,9 +11879,7 @@ async fn native_promql_columnar_unindexed_float64_matches_legacy( // fused node to have run. let plan = observer.take(); assert_eq!(native_rows, expected, "{stage}: fused route must answer"); - let output_values = plan - .metrics() - .expect("fused plan metrics") + let output_values = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } @@ -11964,9 +11966,7 @@ async fn native_promql_columnar_partial_index_float64_matches_legacy( // fused node to have run. let plan = observer.take(); assert_eq!(native_rows, expected, "{stage}: fused route must answer"); - let output_values = plan - .metrics() - .expect("fused plan metrics") + let output_values = fused_metric_set(&plan) .iter() .filter_map(|metric| match metric.value() { datafusion::physical_plan::metrics::MetricValue::Count { name, count } diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs index a4b7cbdd58d..dd98c664a56 100644 --- a/tests-integration/tests/http.rs +++ b/tests-integration/tests/http.rs @@ -1681,16 +1681,95 @@ fn executes_fused_series(plan: &Arc) -> bool { !plan_nodes_named(plan, "FusedSeriesExec").is_empty() } +/// The registrations the fused node's tree made, exactly as they were recorded. +/// +/// [`ExecutionPlan::metrics`] leaves them out: a flat set cannot say which tree node recorded what, +/// so the node keeps its own set for readers that key by name. +fn fused_metric_set( + fused: &Arc, +) -> datafusion::physical_plan::metrics::MetricsSet { + fused + .downcast_ref::() + .unwrap_or_else(|| panic!("the plan is a FusedSeriesExec, not {}", fused.name())) + .node_metric_set() +} + /// One row of a PromQL result: its tag columns in schema order, its timestamp and its value. type PromqlRow = (Vec<(String, String)>, i64, f64); +/// The tree a fused node runs, as `ANALYZE` reports it: one root node, everything below it nested +/// as that node's own children. +/// +/// A node publishes the tree it computes ahead of the physical inputs the plan gives it, so the +/// inputs are the trailing children of `fused`, one per input `executed` reads. +fn fused_tree<'a>( + fused: &'a Value, + executed: &Arc, + context: &str, +) -> &'a [Value] { + let children = fused["children"] + .as_array() + .map(Vec::as_slice) + .unwrap_or(&[]); + let inputs = executed.children(); + assert_eq!( + children.len(), + inputs.len() + 1, + "`{context}`: the fused node publishes {} children for {} inputs, not its tree and its \ + inputs: {fused}", + children.len(), + inputs.len() + ); + let (tree, planned) = children.split_at(1); + for (node, input) in planned.iter().zip(inputs) { + assert_eq!( + node["name"].as_str(), + Some(input.name()), + "`{context}`: the fused node publishes {node} where the plan has a {}", + input.name() + ); + } + tree +} + +/// Every node of a tree, depth first, the nodes given included. +fn tree_nodes<'a>(nodes: &'a [Value]) -> Vec<&'a Value> { + let mut all = Vec::new(); + let mut stack: Vec<&'a Value> = nodes.iter().collect(); + while let Some(node) = stack.pop() { + all.push(node); + if let Some(children) = node["children"].as_array() { + stack.extend(children); + } + } + all +} + +/// How many times the tree says `needle`, e.g. which source an input reads. +fn tree_mentions(tree: &[Value], needle: &str) -> usize { + tree_nodes(tree) + .iter() + .filter_map(|node| node["param"].as_str()) + .map(|param| param.matches(needle).count()) + .sum() +} + +/// Whether the tree binds any input, i.e. reads a frame rather than a constant's own values. +fn tree_binds_input(tree: &[Value]) -> bool { + tree_nodes(tree).iter().any(|node| node["name"] == "Input") +} + /// Checks that a native result reads no scan for a constant, and one real scan over -/// `scan_partitions` non-empty partitions for a vector, and returns the fused node it ran. +/// `scan_partitions` non-empty partitions for a vector. +/// +/// `executed` is the fused node the request ran: its tree's figures are only in the node's own +/// set, which [`ExecutionPlan::metrics`] leaves out. fn assert_native_plan( plan: &Arc, + executed: &Arc, scan_partitions: Option, context: &str, -) -> Value { +) { let fused = { let mut nodes = plan_nodes_named(plan, "FusedSeriesExec"); assert_eq!( @@ -1700,30 +1779,34 @@ fn assert_native_plan( ); nodes.remove(0) }; - // The tree the node will run, rendered the way `EXPLAIN` renders it: one line per node. - let tree = fused["param"].as_str().unwrap_or_default(); + // The node's parameter is no longer the tree: a plain-rows node carries none, and a + // frame-emitting one only names the frame it emits. + let param = fused["param"] + .as_str() + .unwrap_or_else(|| panic!("{context}: the fused node has no parameter: {fused}")); + assert!( + param.is_empty() || param == "(output: series_frame)", + "{context}: the fused node's parameter is not what it emits: {param}" + ); + // The tree the node will run, one node per node, published as the node's own children. + let tree = fused_tree(&fused, executed, context); let scans = plan_nodes_named(plan, "SeriesScanExec"); let Some(partitions) = scan_partitions else { // A constant reads no frame: its one value per grid point comes from the tree alone, so the - // node has no child, plans no scan and binds no source. + // node has no child but its tree, plans no scan and binds no source. assert!( scans.is_empty(), "{context}: a constant planned a scan: {scans:?}" ); - assert_eq!( - fused["children"].as_array().map(Vec::len), - Some(0), - "{context}: a constant's fused node has children: {fused}" - ); assert!( - !tree.contains("Input"), - "{context}: a constant's tree binds an input: {tree}" + !tree_binds_input(tree), + "{context}: a constant's tree binds an input: {fused}" ); - return fused; + return; }; assert_eq!( - fused["children"].as_array().map(Vec::len), - Some(1), + executed.children().len(), + 1, "{context}: a vector must read exactly one child: {fused}" ); assert_eq!( @@ -1731,7 +1814,7 @@ fn assert_native_plan( 1, "{context}: a vector must read exactly one scan: {scans:?}" ); - let mut scan = &fused["children"][0]; + let mut scan = &fused["children"][1]; // An observed optional transparent wrapper that preserves the scan's partition layout; any // other node between the fused node and its scan is rejected. if scan["name"] == "CooperativeExec" { @@ -1758,40 +1841,39 @@ fn assert_native_plan( // Both inputs of one selector name the one source, so a tree that reads two sources or none // would have had to pair or gather them. assert_eq!( - tree.matches("source=0").count(), + tree_mentions(tree, "source=0"), 1, - "{context}: the tree does not read the one source: {tree}" + "{context}: the tree does not read the one source: {fused}" ); - assert!( - !tree.contains("source=1"), - "{context}: the tree reads a second source: {tree}" + assert_eq!( + tree_mentions(tree, "source=1"), + 0, + "{context}: the tree reads a second source: {fused}" ); // Every partition the scan exposes did its own work: a gather of the raw input would leave the // partitions without the input figure, and a partition that never ran would leave both at zero. - // These are input figures: the JSON drops `metric.partition()`, so it cannot say which partition - // produced which values. - let metrics = fused["metrics"] - .as_object() - .unwrap_or_else(|| panic!("{context}: the fused node reports no metrics: {fused}")); + // A peak is registered per partition on the node's own set, which `ExecutionPlan::metrics` + // leaves out: a flat set cannot say which tree node recorded what. + let metrics = fused_metric_set(executed); for partition in 0..partitions { let root_peak = format!("native.p{partition}.root.peak_reserved_bytes"); assert!( metrics - .get(&root_peak) - .and_then(Value::as_u64) - .unwrap_or_default() - > 0, - "partition {partition} of `{context}` did no native work: {fused}" + .iter() + .any(|metric| metric.value().name() == root_peak && metric.value().as_usize() > 0), + "partition {partition} of `{context}` did no native work: {metrics:?}" ); let prefix = format!("native.p{partition}.root."); assert!( - metrics.iter().any(|(name, value)| name.starts_with(&prefix) - && name.ends_with(".input.peak_reserved_bytes") - && value.as_u64().unwrap_or_default() > 0), - "partition {partition} of `{context}` read no input: {fused}" + metrics.iter().any(|metric| { + let name = metric.value().name(); + name.starts_with(&prefix) + && name.ends_with(".input.peak_reserved_bytes") + && metric.value().as_usize() > 0 + }), + "partition {partition} of `{context}` read no input: {metrics:?}" ); } - fused } /// Checks that the fused node that actually ran answered the whole result, one partition at a time. @@ -1826,9 +1908,9 @@ fn assert_native_partition_output( {partitions}" ); } - let metrics = fused - .metrics() - .unwrap_or_else(|| panic!("{context}: the executed fused node reports no metrics")); + // The tree's registrations live in the node's own set: `ExecutionPlan::metrics` leaves them out, + // since a flat set cannot say which node recorded what. + let metrics = fused_metric_set(fused); let mut values_by_partition = vec![0_usize; partitions]; for metric in metrics.iter() { if metric.value().name() != "native.root.output_values" { @@ -2681,19 +2763,26 @@ pub async fn test_native_promql_route_plans_the_query(store_type: StorageType) { let (plan, schema, rows) = promql_output(frontend, query, true, start, end).await; assert_rows_eq(&rows, &expected, query); assert_native_result_schema(&schema, tags, query); - let fused = assert_native_plan(&plan, scan_partitions, query); + // The body is drained, so every partition has finished. + let executed = observer.take(query); + assert_native_plan(&plan, &executed, scan_partitions, query); + let output_values = fused_metric_set(&executed) + .iter() + .filter_map(|metric| match metric.value() { + MetricValue::Count { name, count } + if name.as_ref() == "native.root.output_values" => + { + Some(count.value()) + } + _ => None, + }) + .sum::(); assert_eq!( - fused["metrics"]["native.root.output_values"].as_u64(), - Some(expected.len() as u64), + output_values, + expected.len(), "`{query}`: the tree reported a different number of values than the result holds" ); - // The body is drained, so every partition has finished. - assert_native_partition_output( - &observer.take(query), - scan_partitions, - expected.len(), - query, - ); + assert_native_partition_output(&executed, scan_partitions, expected.len(), query); // Without the per-query hint the same statement runs the legacy pipeline, which must answer // with the same rows. @@ -2736,10 +2825,12 @@ pub async fn test_native_promql_route_plans_the_query(store_type: StorageType) { "`{query}`: expected one fused node: {fused_nodes:?}" ); let fused = &fused_nodes[0]; - let tree = fused["param"].as_str().unwrap_or_default(); + // The body is drained, so the one fused node the request ran has finished. + let executed = observer.take(query); + let tree = fused_tree(fused, &executed, query); assert_eq!( - fused["children"].as_array().map(Vec::len), - Some(1), + executed.children().len(), + 1, "`{query}`: an empty vector must read exactly one child: {fused}" ); let scans = plan_nodes_named(&plan, "SeriesScanExec"); @@ -2750,20 +2841,19 @@ pub async fn test_native_promql_route_plans_the_query(store_type: StorageType) { ); // The tree binds the one source instead of answering as a constant, whose tree binds no input. assert!( - tree.contains("Input"), - "`{query}`: the empty vector planned no input: {tree}" + tree_binds_input(tree), + "`{query}`: the empty vector planned no input: {fused}" ); assert_eq!( - tree.matches("source=0").count(), + tree_mentions(tree, "source=0"), 1, - "`{query}`: the tree does not read the one source: {tree}" + "`{query}`: the tree does not read the one source: {fused}" ); - assert!( - !tree.contains("source=1"), - "`{query}`: the tree reads a second source: {tree}" + assert_eq!( + tree_mentions(tree, "source=1"), + 0, + "`{query}`: the tree reads a second source: {fused}" ); - // The body is drained, so the one fused node the request ran has finished. - observer.take(query); // Without the per-query hint the same statement runs the legacy pipeline, which must answer // with the same empty typed result. @@ -5596,7 +5686,7 @@ pub async fn test_remote_write_v2_histogram_native_partitions(store_type: Storag } let fused = observer.take("histogram partitions"); assert_eq!(fused.name(), "FusedSeriesExec"); - let metrics = fused.metrics().expect("fused metrics"); + let metrics = fused_metric_set(&fused); let mut partitions = BTreeMap::new(); for metric in metrics.iter() { if metric.value().name() == "native.root.output_values"