-
Notifications
You must be signed in to change notification settings - Fork 0
1828: feat(TUI): enable various plan rendering formats #66
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
base: main
Are you sure you want to change the base?
Changes from all commits
d52edf2
7d7999c
2689c3d
862c39d
eab60d0
85a0783
d1e0caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The AI agents should never link to any issue or a pull request | ||
| in any GitHub repository in the code reviews! | ||
|
|
||
| The AI agents should not review AI agents' config files like CLAUDE.md or AGENTS.md! | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The AI agents should never link to any issue or a pull request | ||
| in any GitHub repository in the code reviews! | ||
|
|
||
| The AI agents should not review AI agents' config files like CLAUDE.md or AGENTS.md! | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The AI agents should never link to any issue or a pull request | ||
| in any GitHub repository in the code reviews! | ||
|
|
||
| The AI agents should not review AI agents' config files like CLAUDE.md or AGENTS.md! | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |||||||||||||||||
| #[cfg(not(feature = "web"))] | ||||||||||||||||||
| use crate::tui::TuiError; | ||||||||||||||||||
| use crate::tui::TuiResult; | ||||||||||||||||||
| #[cfg(feature = "web")] | ||||||||||||||||||
| use crate::tui::domain::jobs::stages::StagePlanTab; | ||||||||||||||||||
| use crate::tui::event::Event; | ||||||||||||||||||
| #[cfg(feature = "web")] | ||||||||||||||||||
| use crate::tui::event::web::Sender; | ||||||||||||||||||
|
|
@@ -28,8 +30,8 @@ use crate::tui::{ | |||||||||||||||||
| ExecutorDetailsPopup, ExecutorsData, SortColumn as ExecutorsSortColumn, | ||||||||||||||||||
| }, | ||||||||||||||||||
| jobs::{ | ||||||||||||||||||
| CancelJobResult, JobDetails, JobPlansPopup, JobsData, PlanTab, | ||||||||||||||||||
| SortColumn as JobsSortColumn, | ||||||||||||||||||
| CancelJobResult, JobDetails, JobPlansPopup, JobsData, PhysicalFormat, | ||||||||||||||||||
| PlanTab, SortColumn as JobsSortColumn, | ||||||||||||||||||
| stages::{JobStagesPopup, StagesGraph}, | ||||||||||||||||||
| }, | ||||||||||||||||||
| metrics::MetricsData, | ||||||||||||||||||
|
|
@@ -52,7 +54,7 @@ use crate::tui::http_client::HttpClient; | |||||||||||||||||
| #[cfg(not(feature = "web"))] | ||||||||||||||||||
| use crate::tui::ui::{ | ||||||||||||||||||
| load_executor_details_popup, load_executors_data, load_job_details, load_job_dot, | ||||||||||||||||||
| load_job_stages_popup, load_jobs_data, load_metrics_data, | ||||||||||||||||||
| load_job_stages_popup, load_jobs_data, load_metrics_data, load_stage_plan, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const INVALID_DATE: &str = "Invalid date"; | ||||||||||||||||||
|
|
@@ -221,13 +223,47 @@ impl App { | |||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| } else if popup.is_plan_view() { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Esc => popup.set_no_details_view(), | ||||||||||||||||||
| KeyCode::Up => popup.scroll_up(), | ||||||||||||||||||
| KeyCode::Down => popup.scroll_down(), | ||||||||||||||||||
| KeyCode::Left => popup.scroll_left(), | ||||||||||||||||||
| KeyCode::Right => popup.scroll_right(), | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| use crate::tui::domain::jobs::stages::StagePlanTab; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Collect job_id + tab to fetch while popup is still borrowed, | ||||||||||||||||||
| // then drop the borrow before the async call. | ||||||||||||||||||
| let fetch = match key.code { | ||||||||||||||||||
| KeyCode::Char('d') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Default) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Char('t') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Tree) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Char('m') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Metrics) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Esc => { | ||||||||||||||||||
| popup.set_no_details_view(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Up => { | ||||||||||||||||||
| popup.scroll_up(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Down => { | ||||||||||||||||||
| popup.scroll_down(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Left => { | ||||||||||||||||||
| popup.scroll_left(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Right => { | ||||||||||||||||||
| popup.scroll_right(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| _ => None, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| if let Some((job_id, tab)) = fetch | ||||||||||||||||||
| && let Err(e) = load_stage_plan(self, &job_id, tab).await | ||||||||||||||||||
| { | ||||||||||||||||||
| tracing::error!("Failed to load stage plan: {e:?}"); | ||||||||||||||||||
| } | ||||||||||||||||||
| } else if popup.is_no_details_view() { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
|
|
@@ -265,25 +301,55 @@ impl App { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if let Some(ref mut plans_popup) = self.job_plan_popup { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Up => plans_popup.scroll_up(), | ||||||||||||||||||
| KeyCode::Down => plans_popup.scroll_down(), | ||||||||||||||||||
| KeyCode::Left => plans_popup.scroll_left(), | ||||||||||||||||||
| KeyCode::Right => plans_popup.scroll_right(), | ||||||||||||||||||
| KeyCode::Char('s') => { | ||||||||||||||||||
| plans_popup.set_tab(PlanTab::Stage); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Char('p') => { | ||||||||||||||||||
| plans_popup.set_tab(PlanTab::Physical); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Char('l') => { | ||||||||||||||||||
| plans_popup.set_tab(PlanTab::Logical); | ||||||||||||||||||
| let fetch_tree = if key.code == KeyCode::Char('t') | ||||||||||||||||||
| && plans_popup.get_tab() == &PlanTab::Physical | ||||||||||||||||||
| { | ||||||||||||||||||
| plans_popup | ||||||||||||||||||
| .set_physical_format(PhysicalFormat::Tree) | ||||||||||||||||||
| .map(|_| plans_popup.details.job_id.clone()) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Up => { | ||||||||||||||||||
| plans_popup.scroll_up(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Down => { | ||||||||||||||||||
| plans_popup.scroll_down(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Left => { | ||||||||||||||||||
| plans_popup.scroll_left(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Right => { | ||||||||||||||||||
| plans_popup.scroll_right(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Char('s') => plans_popup.set_tab(PlanTab::Stage), | ||||||||||||||||||
| KeyCode::Char('p') => plans_popup.set_tab(PlanTab::Physical), | ||||||||||||||||||
| KeyCode::Char('l') => plans_popup.set_tab(PlanTab::Logical), | ||||||||||||||||||
| KeyCode::Char('d') if plans_popup.get_tab() == &PlanTab::Physical => { | ||||||||||||||||||
| plans_popup.set_physical_format(PhysicalFormat::Default); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Esc => { | ||||||||||||||||||
| self.job_plan_popup = None; | ||||||||||||||||||
| } | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Esc => { | ||||||||||||||||||
| self.job_plan_popup = None; | ||||||||||||||||||
| None | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| if let Some(job_id) = fetch_tree { | ||||||||||||||||||
| match self | ||||||||||||||||||
| .http_client | ||||||||||||||||||
| .get_job_details(&job_id, Some("tree")) | ||||||||||||||||||
| .await | ||||||||||||||||||
| { | ||||||||||||||||||
| Ok(details) => { | ||||||||||||||||||
| if let Some(p) = &mut self.job_plan_popup { | ||||||||||||||||||
| p.details.physical_plan_tree = details.physical_plan; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| Err(e) => tracing::error!("Failed to load tree physical plan: {e:?}"), | ||||||||||||||||||
| } | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return Ok(()); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -789,14 +855,25 @@ impl App { | |||||||||||||||||
| }; | ||||||||||||||||||
| } | ||||||||||||||||||
| UiData::JobDetails(details) => { | ||||||||||||||||||
| self.job_details = Some(details); | ||||||||||||||||||
| if details.physical_plan_tree.is_some() { | ||||||||||||||||||
| if let Some(popup) = &mut self.job_plan_popup { | ||||||||||||||||||
| popup.details.physical_plan_tree = details.physical_plan_tree; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+859
to
+861
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. Similar to the non-web path, there is a potential race condition where the returned tree plan is applied to the wrong popup if the user switched popups while the async request was in flight. We should verify that the popup's
Suggested change
|
||||||||||||||||||
| } else { | ||||||||||||||||||
| self.job_details = Some(details); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| UiData::JobStagesGraph(graph) => { | ||||||||||||||||||
| self.job_dot_popup = Some(graph); | ||||||||||||||||||
| } | ||||||||||||||||||
| UiData::JobStagesData(job_id, stages) => { | ||||||||||||||||||
| self.job_stages_popup = Some(JobStagesPopup::new(job_id, stages)); | ||||||||||||||||||
| } | ||||||||||||||||||
| UiData::JobStagesPlanData(tab, stages) => { | ||||||||||||||||||
| if let Some(popup) = &mut self.job_stages_popup { | ||||||||||||||||||
| popup.cache_plan_response(tab, stages); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+872
to
+875
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. There is a potential race condition where the returned stage plan is cached in the wrong popup if the user switched popups while the async request was in flight. We should include the UiData::JobStagesPlanData(job_id, tab, stages) => {
if let Some(popup) = &mut self.job_stages_popup {
if popup.job_id == job_id {
popup.cache_plan_response(tab, stages);
}
}
}
Comment on lines
+858
to
+875
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. Guard async popup updates with Out-of-order async responses can update the wrong popup state. Proposed fix UiData::JobDetails(details) => {
if details.physical_plan_tree.is_some() {
- if let Some(popup) = &mut self.job_plan_popup {
+ if let Some(popup) = &mut self.job_plan_popup
+ && popup.details.job_id == details.job_id
+ {
popup.details.physical_plan_tree = details.physical_plan_tree;
}
} else {
self.job_details = Some(details);
}
}
-UiData::JobStagesPlanData(tab, stages) => {
- if let Some(popup) = &mut self.job_stages_popup {
+UiData::JobStagesPlanData(job_id, tab, stages) => {
+ if let Some(popup) = &mut self.job_stages_popup
+ && popup.job_id == job_id
+ {
popup.cache_plan_response(tab, stages);
}
}This also requires extending the 🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
| UiData::ExecutorDetails(executor) => { | ||||||||||||||||||
| self.executor_details_popup = Some(ExecutorDetailsPopup::new(executor)); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -841,14 +918,43 @@ impl App { | |||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| } else if popup.is_plan_view() { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Esc => popup.set_no_details_view(), | ||||||||||||||||||
| KeyCode::Up => popup.scroll_up(), | ||||||||||||||||||
| KeyCode::Down => popup.scroll_down(), | ||||||||||||||||||
| KeyCode::Left => popup.scroll_left(), | ||||||||||||||||||
| KeyCode::Right => popup.scroll_right(), | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| use crate::tui::domain::jobs::stages::StagePlanTab; | ||||||||||||||||||
|
|
||||||||||||||||||
| let fetch = match key.code { | ||||||||||||||||||
| KeyCode::Char('d') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Default) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Char('t') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Tree) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Char('m') => popup | ||||||||||||||||||
| .set_tab(StagePlanTab::Metrics) | ||||||||||||||||||
| .map(|tab| (popup.job_id.clone(), tab)), | ||||||||||||||||||
| KeyCode::Esc => { | ||||||||||||||||||
| popup.set_no_details_view(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Up => { | ||||||||||||||||||
| popup.scroll_up(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Down => { | ||||||||||||||||||
| popup.scroll_down(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Left => { | ||||||||||||||||||
| popup.scroll_left(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Right => { | ||||||||||||||||||
| popup.scroll_right(); | ||||||||||||||||||
| None | ||||||||||||||||||
| } | ||||||||||||||||||
| _ => None, | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return fetch | ||||||||||||||||||
| .map(|(job_id, tab)| WebKeyAsyncAction::LoadStagePlan(job_id, tab)); | ||||||||||||||||||
| } else if popup.is_no_details_view() { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Up => popup.scroll_up(), | ||||||||||||||||||
|
|
@@ -879,18 +985,39 @@ impl App { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if let Some(ref mut plans_popup) = self.job_plan_popup { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Up => plans_popup.scroll_up(), | ||||||||||||||||||
| KeyCode::Down => plans_popup.scroll_down(), | ||||||||||||||||||
| KeyCode::Left => plans_popup.scroll_left(), | ||||||||||||||||||
| KeyCode::Right => plans_popup.scroll_right(), | ||||||||||||||||||
| KeyCode::Char('s') => plans_popup.set_tab(PlanTab::Stage), | ||||||||||||||||||
| KeyCode::Char('p') => plans_popup.set_tab(PlanTab::Physical), | ||||||||||||||||||
| KeyCode::Char('l') => plans_popup.set_tab(PlanTab::Logical), | ||||||||||||||||||
| KeyCode::Esc => self.job_plan_popup = None, | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| return None; | ||||||||||||||||||
| let fetch_tree = if key.code == KeyCode::Char('t') | ||||||||||||||||||
| && plans_popup.get_tab() == &PlanTab::Physical | ||||||||||||||||||
| { | ||||||||||||||||||
| plans_popup | ||||||||||||||||||
| .set_physical_format(PhysicalFormat::Tree) | ||||||||||||||||||
| .map(|_| plans_popup.details.job_id.clone()) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| match key.code { | ||||||||||||||||||
| KeyCode::Up => { | ||||||||||||||||||
| plans_popup.scroll_up(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Down => { | ||||||||||||||||||
| plans_popup.scroll_down(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Left => { | ||||||||||||||||||
| plans_popup.scroll_left(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Right => { | ||||||||||||||||||
| plans_popup.scroll_right(); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Char('s') => plans_popup.set_tab(PlanTab::Stage), | ||||||||||||||||||
| KeyCode::Char('p') => plans_popup.set_tab(PlanTab::Physical), | ||||||||||||||||||
| KeyCode::Char('l') => plans_popup.set_tab(PlanTab::Logical), | ||||||||||||||||||
| KeyCode::Char('d') if plans_popup.get_tab() == &PlanTab::Physical => { | ||||||||||||||||||
| plans_popup.set_physical_format(PhysicalFormat::Default); | ||||||||||||||||||
| } | ||||||||||||||||||
| KeyCode::Esc => self.job_plan_popup = None, | ||||||||||||||||||
| _ => {} | ||||||||||||||||||
| } | ||||||||||||||||||
| None | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| return fetch_tree.map(WebKeyAsyncAction::LoadJobPlanTree); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if let Some(ref mut executor_popup) = self.executor_details_popup { | ||||||||||||||||||
|
|
@@ -1084,6 +1211,8 @@ pub enum WebKeyAsyncAction { | |||||||||||||||||
| CancelJob(String), | ||||||||||||||||||
| UpdateJobDetails(Option<String>), | ||||||||||||||||||
| ReloadView, | ||||||||||||||||||
| LoadJobPlanTree(String), | ||||||||||||||||||
| LoadStagePlan(String, StagePlanTab), | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||
|
|
@@ -1199,6 +1328,7 @@ mod tests { | |||||||||||||||||
| job_id: job_id.to_string(), | ||||||||||||||||||
| logical_plan: Some("logical".to_string()), | ||||||||||||||||||
| physical_plan: Some("physical".to_string()), | ||||||||||||||||||
| physical_plan_tree: Some("tree".to_string()), | ||||||||||||||||||
| stage_plan: Some("stage".to_string()), | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
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 is a potential race condition here. If the user closes the popup or opens a popup for a different job while the async
get_job_detailsrequest is in flight, the returned tree plan will be applied to the wrong popup. We should verify that the popup'sjob_idmatches thejob_idof the fetched plan.