-
Notifications
You must be signed in to change notification settings - Fork 24
Fix metrics collection bug: preserve PartitionIsolatorExec in plan #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sundinesh1
wants to merge
6
commits into
datafusion-contrib:main
Choose a base branch
from
sundinesh1:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd417fd
Fix metrics collection bug: preserve PartitionIsolatorExec in plan
sundinesh1 1256f56
test: add test for PartitionIsolatorExec metrics collection
sundinesh1 2065f96
refactor: simplify PartitionIsolatorExec metrics test and use transfo…
sundinesh1 d083cf3
restore the empty line
sundinesh1 8523799
Fix formatting and remove unused import in task_metrics_collector
sundinesh1 a66fafa
Remove PartitionIsolatorExec special-case handling in metrics tests
sundinesh1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -132,10 +132,13 @@ pub fn stage_metrics_rewriter( | |||||||||||||
| stage: &Stage, | ||||||||||||||
| metrics_collection: Arc<HashMap<StageKey, Vec<MetricsSetProto>>>, | ||||||||||||||
| ) -> Result<Arc<dyn ExecutionPlan>> { | ||||||||||||||
| let mut node_idx = 0; | ||||||||||||||
|
|
||||||||||||||
| let plan = stage.plan.decoded()?; | ||||||||||||||
|
|
||||||||||||||
| // First, collect all node metrics in pre-order traversal to match the order | ||||||||||||||
| // used by TaskMetricsCollector | ||||||||||||||
| let mut node_metrics_vec = Vec::new(); | ||||||||||||||
| let mut node_idx = 0; | ||||||||||||||
|
|
||||||||||||||
| plan.clone().transform_down(|plan| { | ||||||||||||||
| // Stop at network boundaries. | ||||||||||||||
| if plan.as_network_boundary().is_some() { | ||||||||||||||
|
|
@@ -151,8 +154,9 @@ pub fn stage_metrics_rewriter( | |||||||||||||
| Some(task_metrics) => { | ||||||||||||||
| if node_idx >= task_metrics.len() { | ||||||||||||||
| return internal_err!( | ||||||||||||||
| "not enough metrics provided to rewrite task: {} metrics provided", | ||||||||||||||
| task_metrics.len() | ||||||||||||||
| "not enough metrics provided to rewrite task: {} metrics provided, node_idx={}", | ||||||||||||||
| task_metrics.len(), | ||||||||||||||
| node_idx | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| let node_metrics = task_metrics[node_idx].clone(); | ||||||||||||||
|
|
@@ -170,12 +174,32 @@ pub fn stage_metrics_rewriter( | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| node_metrics_vec.push(metrics_set_proto_to_df(&stage_metrics)?); | ||||||||||||||
| node_idx += 1; | ||||||||||||||
| Ok(Transformed::no(plan)) | ||||||||||||||
| })?; | ||||||||||||||
|
|
||||||||||||||
| // Now rewrite the plan with the collected metrics | ||||||||||||||
| let mut node_idx = 0; | ||||||||||||||
| plan.clone().transform_down(|plan| { | ||||||||||||||
| // Stop at network boundaries. | ||||||||||||||
| if plan.as_network_boundary().is_some() { | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| return Ok(Transformed::new(plan, false, TreeNodeRecursion::Jump)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if node_idx >= node_metrics_vec.len() { | ||||||||||||||
| return internal_err!( | ||||||||||||||
| "mismatch between plan nodes and collected metrics: {} metrics collected, node_idx={}", | ||||||||||||||
| node_metrics_vec.len(), | ||||||||||||||
| node_idx | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| let wrapped_plan_node: Arc<dyn ExecutionPlan> = Arc::new(MetricsWrapperExec::new( | ||||||||||||||
| plan.clone(), | ||||||||||||||
| metrics_set_proto_to_df(&stage_metrics)?, | ||||||||||||||
| node_metrics_vec[node_idx].clone(), | ||||||||||||||
| )); | ||||||||||||||
| node_idx += 1; | ||||||||||||||
| Ok(Transformed::yes(wrapped_plan_node)) | ||||||||||||||
| }).map(|v| v.data) | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -445,18 +469,20 @@ mod tests { | |||||||||||||
|
|
||||||||||||||
| // Assert every plan node has at least one metric except partition isolators, network boundary nodes, and the root DistributedExec node. | ||||||||||||||
| fn assert_metrics_present_in_plan(plan: &Arc<dyn ExecutionPlan>) { | ||||||||||||||
| // Check if this is a PartitionIsolatorExec (possibly wrapped in MetricsWrapperExec) | ||||||||||||||
| // For MetricsWrapperExec, we check the name() which delegates to the inner plan | ||||||||||||||
| let is_partition_isolator = plan.name() == "PartitionIsolatorExec" | ||||||||||||||
| || plan | ||||||||||||||
| .as_any() | ||||||||||||||
| .downcast_ref::<PartitionIsolatorExec>() | ||||||||||||||
| .is_some(); | ||||||||||||||
|
Comment on lines
+474
to
+478
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even simpler:
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| if let Some(metrics) = plan.metrics() { | ||||||||||||||
| assert!(metrics.iter().count() > 0); | ||||||||||||||
| // PartitionIsolatorExec nodes are allowed to have empty metrics | ||||||||||||||
| if !is_partition_isolator { | ||||||||||||||
| assert!(metrics.iter().count() > 0); | ||||||||||||||
| } | ||||||||||||||
| } else { | ||||||||||||||
| let is_partition_isolator = | ||||||||||||||
| if let Some(metrics_wrapper) = plan.as_any().downcast_ref::<MetricsWrapperExec>() { | ||||||||||||||
| metrics_wrapper | ||||||||||||||
| .as_any() | ||||||||||||||
| .downcast_ref::<PartitionIsolatorExec>() | ||||||||||||||
| .is_some() | ||||||||||||||
| } else { | ||||||||||||||
| false | ||||||||||||||
| }; | ||||||||||||||
| assert!( | ||||||||||||||
| plan.is_network_boundary() | ||||||||||||||
| || is_partition_isolator | ||||||||||||||
|
|
@@ -469,7 +495,6 @@ mod tests { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[tokio::test] | ||||||||||||||
| #[ignore] // https://github.com/datafusion-contrib/datafusion-distributed/issues/260 | ||||||||||||||
| async fn test_executed_distributed_plan_has_metrics() { | ||||||||||||||
| let ctx = make_test_distributed_ctx().await; | ||||||||||||||
| let plan = ctx | ||||||||||||||
|
|
||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 there's a comment here... but no code honor the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment was meant to go above the
assert_eq!instead of below it.