-
Notifications
You must be signed in to change notification settings - Fork 301
feat(scheduler): Redirect '/' to nighlies.a.o WebTUI #2059
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
f68f138
467b4e5
a9f4b9f
e5dabcc
d99f33f
b0d9056
a7900b4
fce4b63
1c81a45
6638879
327979a
aed9569
b342c1f
a820cc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ use crate::state::execution_graph_dot::ExecutionGraphDot; | |
| use crate::state::execution_stage::TaskInfo; | ||
| use crate::{api::SchedulerErrorResponse, scheduler_server::SchedulerServer}; | ||
| use axum::extract::Query; | ||
| use axum::response::Redirect; | ||
| use axum::{ | ||
| Json, | ||
| extract::{Path, State}, | ||
|
|
@@ -46,8 +47,9 @@ use graphviz_rust::{ | |
| exec, | ||
| printer::PrinterContext, | ||
| }; | ||
| use http::{StatusCode, header::CONTENT_TYPE}; | ||
| use http::{HeaderMap, StatusCode, header::CONTENT_TYPE}; | ||
| use serde::Serialize; | ||
| use std::collections::HashMap; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
|
|
@@ -227,6 +229,59 @@ pub enum PlanFormat { | |
| Metrics, | ||
| } | ||
|
|
||
| /// A handler for GET requests to the root (`/`). | ||
| /// It redirects to `https://nightlies.apache.org/datafusion/ballista/tui/<BALLISTA_VERSION>/` | ||
| /// forwarding any query parameters | ||
| pub async fn get_webtui< | ||
| T: AsLogicalPlan + Clone + Send + Sync + 'static, | ||
| U: AsExecutionPlan + Send + Sync + 'static, | ||
| >( | ||
| header_map: HeaderMap, | ||
| Query(mut params): Query<HashMap<String, String>>, | ||
| State(data_server): State<Arc<SchedulerServer<T, U>>>, | ||
| ) -> Result<Redirect, (StatusCode, String)> { | ||
| const NIGHTLIES_URL: &str = "https://nightlies.apache.org/datafusion/ballista/tui"; | ||
| let external_host = &data_server.state.config.external_host; | ||
| let bind_port = data_server.state.config.bind_port; | ||
|
|
||
| let ballista_scheduler_url = | ||
| params.remove("ballista_scheduler_url").unwrap_or_else(|| { | ||
| let default_scheduler_url = &format!("{external_host}:{bind_port}"); | ||
| let proto = header_map | ||
| .get("x-forwarded-proto") | ||
| .and_then(|v| v.to_str().ok()) | ||
| .unwrap_or("http"); | ||
| let host = header_map | ||
| .get("x-forwarded-host") | ||
| .and_then(|hv| hv.to_str().ok()) | ||
| .unwrap_or(external_host); | ||
| let port = header_map | ||
| .get("x-forwarded-port") | ||
| .and_then(|hv| hv.to_str().ok()) | ||
| .and_then(|v| v.parse::<u16>().ok()) | ||
| .unwrap_or(bind_port); | ||
| format!("{proto}://{host}:{port}") | ||
| }); | ||
|
|
||
| let mut query_string = String::new(); | ||
| query_string.push_str(&format!( | ||
| "ballista_scheduler_url={}", | ||
| url_escape::encode_query(&ballista_scheduler_url) | ||
| )); | ||
|
|
||
| for (k, v) in params.iter() { | ||
| query_string.push_str(&format!( | ||
| "&{}={}", | ||
| url_escape::encode_query(k), | ||
| url_escape::encode_query(v) | ||
| )); | ||
| } | ||
|
|
||
| let target = format!("{NIGHTLIES_URL}/{BALLISTA_VERSION}/?{query_string}"); | ||
|
Contributor
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. it would be great if we could make target configurable and forward to NIGHTLIES_URL only if there is no such configuration, this would allow users to have its own version of tui deployed somewhere else
Member
Author
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. If they have their own deployment then they do not need to use |
||
|
|
||
| Ok(Redirect::to(&target)) | ||
| } | ||
|
|
||
| pub async fn get_scheduler_state< | ||
| T: AsLogicalPlan + Clone + Send + Sync + 'static, | ||
| U: AsExecutionPlan + Send + Sync + 'static, | ||
|
|
@@ -546,7 +601,7 @@ pub async fn get_query_stages< | |
| let metrics = running_stage.stage_metrics.as_deref().unwrap_or(&[]); | ||
| summary.stage_plan = Some(match plan_format { | ||
| PlanFormat::Default => displayable(running_stage.plan.as_ref()).indent(false).to_string(), | ||
| PlanFormat::Tree => displayable(running_stage.plan.as_ref()).tree_render().to_string(), | ||
| PlanFormat::Tree => displayable(running_stage.plan.as_ref()).tree_render().to_string(), | ||
| PlanFormat::Metrics => format_stage_metrics(running_stage.plan.as_ref(), metrics), | ||
| }); | ||
| summary.input_rows = running_stage | ||
|
|
@@ -591,7 +646,7 @@ pub async fn get_query_stages< | |
| finish_time: info.finish_time as u64, | ||
| input_rows, | ||
| output_rows, | ||
| status: task_status | ||
| status: task_status, | ||
| } | ||
| }) | ||
| }) | ||
|
|
@@ -600,7 +655,7 @@ pub async fn get_query_stages< | |
| ExecutionStage::Successful(completed_stage) => { | ||
| summary.stage_plan = Some(match plan_format { | ||
| PlanFormat::Default => displayable(completed_stage.plan.as_ref()).indent(false).to_string(), | ||
| PlanFormat::Tree => displayable(completed_stage.plan.as_ref()).tree_render().to_string(), | ||
| PlanFormat::Tree => displayable(completed_stage.plan.as_ref()).tree_render().to_string(), | ||
| PlanFormat::Metrics => format_stage_metrics(completed_stage.plan.as_ref(), &completed_stage.stage_metrics), | ||
| }); | ||
| summary.input_rows = get_combined_count( | ||
|
|
@@ -638,7 +693,7 @@ pub async fn get_query_stages< | |
| finish_time: task_info.finish_time as u64, | ||
| input_rows, | ||
| output_rows, | ||
| status: task_status | ||
| status: task_status, | ||
| }) | ||
| }) | ||
| .collect(); | ||
|
|
@@ -908,7 +963,7 @@ pub async fn get_job_dot_graph< | |
| })? | ||
| { | ||
| ExecutionGraphDot::generate(graph.as_ref()) | ||
| .map_err(|e| { | ||
| .map_err(|e| { | ||
| tracing::error!("Error occurred while getting the dot graph for job '{job_id}' reason: {e:?}"); | ||
| SchedulerErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR) | ||
| }) | ||
|
|
@@ -953,10 +1008,10 @@ pub async fn get_job_svg_graph< | |
| &mut PrinterContext::default(), | ||
| vec![CommandArg::Format(Format::Svg)], | ||
| ) | ||
| .map_err(|e| { | ||
| tracing::error!("Error occurred while getting job svg graph for job '{job_id}' reason: {e:?}"); | ||
| SchedulerErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR) | ||
| })?; | ||
| .map_err(|e| { | ||
| tracing::error!("Error occurred while getting job svg graph for job '{job_id}' reason: {e:?}"); | ||
| SchedulerErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR) | ||
| })?; | ||
|
|
||
| let svg = String::from_utf8_lossy(&result).to_string(); | ||
| Ok(Response::builder() | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
should we also take into account
external_hostfrom scheduler configuration g?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.
Done with aed9569