Skip to content
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

Provide more accurate information as to why each task is in a specific state #11

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rollout-dashboard/frontend/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ nav {
}

.tooltip .tooltiptext {
display: none;
visibility: hidden;
min-width: 120px;
min-width: 250px;
background-color: black;
color: #fff;
text-align: center;
Expand All @@ -55,6 +56,7 @@ nav {
}

.tooltip:hover .tooltiptext {
display: inline-block;
visibility: visible;
}

Expand Down
7 changes: 5 additions & 2 deletions rollout-dashboard/frontend/src/lib/Batch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
complete: { icon: "✅", name: "Complete" },
skipped: { icon: "⏩", name: "Skipped" },
error: { icon: "❌", name: "Error" },
unknown: { icon: "❓", name: "Unknown (check backend logs)" },
predecessor_failed: { icon: "❌", name: "Predecessor failed" },
unknown: { icon: "❓", name: "Does not appear in Airflow" },
};
</script>

Expand All @@ -32,7 +33,9 @@
<div class="subnet_state_icon tooltip">
{subnet_rollout_states[subnet.state].icon}<span
class="subnet_state tooltiptext"
>{subnet_rollout_states[subnet.state].name}</span
>{subnet_rollout_states[subnet.state]
.name}{#if subnet.comment}<br
/>{subnet.comment}{/if}</span
>
</div>
<span class="subnet_id">{subnet.subnet_id.substring(0, 5)}</span
Expand Down
31 changes: 30 additions & 1 deletion rollout-dashboard/server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rollout-dashboard/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ regex = "1.10.5"
reqwest = { version = "0.12.5", features = ["json", "cookies"] }
serde = { version = "1.0.203", features = ["derive", "std"] }
serde_json = "1.0.120"
strum = { version = "0.26.3", features = ["derive"] }
tokio = { version = "1.38.0", features = ["full"] }
topological-sort = "0.2.2"
tower-http = { version = "0.5.2", features = ["fs"] }
Expand Down
3 changes: 2 additions & 1 deletion rollout-dashboard/server/src/airflow_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;
use std::time::Duration;
use std::{f64, fmt};
use std::{vec, vec::Vec};
use strum::Display;
use urlencoding::decode;

/// Default maximum batch size for paged requests in Airflow.
Expand Down Expand Up @@ -151,7 +152,7 @@ pub struct XComEntryResponse {
pub value: String,
}

#[derive(Debug, Deserialize, Clone, PartialEq)]
#[derive(Debug, Deserialize, Clone, PartialEq, Display)]
#[serde(rename_all = "snake_case")]
pub enum TaskInstanceState {
Success,
Expand Down
140 changes: 103 additions & 37 deletions rollout-dashboard/server/src/frontend_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::python;
use chrono::{DateTime, Utc};
use lazy_static::lazy_static;
use log::{debug, error};
use log::{debug, error, trace};
use regex::Regex;
use serde::Serialize;
use std::cmp::min;
Expand All @@ -12,6 +12,7 @@ use std::rc::Rc;
use std::str::FromStr;
use std::sync::Arc;
use std::{vec, vec::Vec};
use strum::Display;
use tokio::sync::Mutex;
use topological_sort::TopologicalSort;

Expand All @@ -26,7 +27,7 @@ lazy_static! {
static ref BatchIdentificationRe: Regex = Regex::new("batch_([0-9]+)[.](.+)").unwrap();
}

#[derive(Serialize, Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
#[derive(Serialize, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Display)]
#[serde(rename_all = "snake_case")]
pub enum SubnetRolloutState {
Pending,
Expand All @@ -36,8 +37,9 @@ pub enum SubnetRolloutState {
WaitingForAdoption,
WaitingForAlertsGone,
Complete,
Skipped,
Error,
PredecessorFailed,
Skipped,
Unknown,
}

Expand All @@ -46,6 +48,7 @@ pub struct Subnet {
pub subnet_id: String,
pub git_revision: String,
pub state: SubnetRolloutState,
pub comment: String,
}

#[derive(Serialize, Debug, Clone)]
Expand All @@ -56,28 +59,81 @@ pub struct Batch {
pub subnets: Vec<Subnet>,
}

fn format_some<N>(opt: Option<N>, prefix: &str, fallback: &str) -> String
where
N: Display,
{
match opt {
None => fallback.to_string(),
Some(v) => format!("{}{}", prefix, v),
}
}

fn make_state_comment(task_instance: &TaskInstancesResponseItem) -> String {
format!(
"Task {}{} {}",
task_instance.task_id,
format_some(task_instance.map_index, ".", ""),
format_some(
task_instance.state.clone(),
" in state ",
" has no known state"
),
)
}

impl Batch {
fn set_min_subnet_state(&mut self, state: SubnetRolloutState, index: Option<usize>) {
match index {
fn set_min_subnet_state(
&mut self,
state: SubnetRolloutState,
task_instance: &TaskInstancesResponseItem,
) -> SubnetRolloutState {
match task_instance.map_index {
None => {
for subnet in self.subnets.iter_mut() {
subnet.state = min(subnet.state.clone(), state.clone())
let new_state = state.clone();
if new_state < subnet.state {
subnet.comment = make_state_comment(task_instance);
trace!(target: "subnet_state", "{} {} {:?} transition {} => {} note: {}", task_instance.dag_run_id, task_instance.task_id, task_instance.map_index, subnet.state, new_state, subnet.comment);
subnet.state = new_state;
}
}
}
Some(index) => {
self.subnets[index].state = min(self.subnets[index].state.clone(), state)
let new_state = state.clone();
if new_state < self.subnets[index].state {
self.subnets[index].comment = make_state_comment(task_instance);
trace!(target: "subnet_state", "{} {} {:?} transition {} => {} note: {}", task_instance.dag_run_id, task_instance.task_id, task_instance.map_index, self.subnets[index].state, new_state, self.subnets[index].comment);
self.subnets[index].state = new_state;
}
}
}
state
}
fn set_specific_subnet_state(&mut self, state: SubnetRolloutState, index: Option<usize>) {
match index {
fn set_specific_subnet_state(
&mut self,
state: SubnetRolloutState,
task_instance: &TaskInstancesResponseItem,
) -> SubnetRolloutState {
match task_instance.map_index {
None => {
for subnet in self.subnets.iter_mut() {
subnet.state = state.clone()
if state != subnet.state {
subnet.comment = make_state_comment(task_instance);
trace!(target: "subnet_state", "{} {} {:?} transition {} => {} note: {}", task_instance.dag_run_id, task_instance.task_id, task_instance.map_index, subnet.state, state, subnet.comment);
subnet.state = state.clone();
}
}
}
Some(index) => {
if state != self.subnets[index].state {
self.subnets[index].comment = make_state_comment(task_instance);
trace!(target: "subnet_state", "{} {} {:?} transition {} => {} note: {}", task_instance.dag_run_id, task_instance.task_id, task_instance.map_index, self.subnets[index].state, state, self.subnets[index].comment);
self.subnets[index].state = state.clone();
}
}
Some(index) => self.subnets[index].state = state,
}
state
}
}

Expand Down Expand Up @@ -300,6 +356,7 @@ impl RolloutPlan {
subnet_id: capped[1].to_string(),
git_revision: capped[2].to_string(),
state: SubnetRolloutState::Unknown,
comment: "".to_string(),
},
None => return Err(RolloutPlanParseError::InvalidSubnet(subnet.clone())),
});
Expand Down Expand Up @@ -595,37 +652,48 @@ impl RolloutApi {
);

match task_instance.state {
Some(TaskInstanceState::Skipped) | Some(TaskInstanceState::Removed) => {
Some(TaskInstanceState::Skipped) => {
batch.set_specific_subnet_state(
SubnetRolloutState::Skipped,
task_instance.map_index,
&task_instance,
);
}
Some(TaskInstanceState::UpForRetry)
| Some(TaskInstanceState::Restarting) => {
batch.set_specific_subnet_state(
SubnetRolloutState::Error,
task_instance.map_index,
&task_instance,
);
rollout.state = RolloutState::Problem
}
Some(TaskInstanceState::Failed)
| Some(TaskInstanceState::UpstreamFailed) => {
Some(TaskInstanceState::Failed) => {
batch.set_specific_subnet_state(
SubnetRolloutState::Error,
task_instance.map_index,
&task_instance,
);
rollout.state = RolloutState::Failed
}
Some(TaskInstanceState::Success) => {
Some(TaskInstanceState::UpstreamFailed) => {
batch.set_min_subnet_state(
match task_name {
"wait_until_no_alerts" => SubnetRolloutState::Complete,
"join" => SubnetRolloutState::Complete,
&_ => SubnetRolloutState::Unknown,
},
task_instance.map_index,
SubnetRolloutState::PredecessorFailed,
&task_instance,
);
rollout.state = RolloutState::Failed
}
Some(TaskInstanceState::Removed) => {
batch.set_specific_subnet_state(
SubnetRolloutState::Unknown,
&task_instance,
);
rollout.state = RolloutState::Failed
}
Some(TaskInstanceState::Success) => {
if task_name == "wait_until_no_alerts" || task_name == "join" {
batch.set_min_subnet_state(
SubnetRolloutState::Complete,
&task_instance,
);
}
if task_name == "wait_until_start_time" {
match batch.actual_start_time {
None => batch.actual_start_time = task_instance.end_date,
Expand All @@ -643,13 +711,19 @@ impl RolloutApi {
batch.end_time = task_instance.end_date;
};
}

None => {
if task_name == "collect_batch_subnets" {
batch.set_min_subnet_state(
SubnetRolloutState::Pending,
&task_instance,
);
}
}
Some(TaskInstanceState::UpForReschedule)
| Some(TaskInstanceState::Running)
| Some(TaskInstanceState::Deferred)
| Some(TaskInstanceState::Queued)
| Some(TaskInstanceState::Scheduled)
| None => {
| Some(TaskInstanceState::Scheduled) => {
batch.set_min_subnet_state(
match task_name {
"collect_batch_subnets" => SubnetRolloutState::Pending,
Expand All @@ -666,9 +740,10 @@ impl RolloutApi {
"wait_until_no_alerts" => {
SubnetRolloutState::WaitingForAlertsGone
}
"join" => SubnetRolloutState::Complete,
_ => SubnetRolloutState::Unknown,
},
task_instance.map_index,
&task_instance,
);
rollout.state = min(rollout.state, RolloutState::UpgradingSubnets)
}
Expand Down Expand Up @@ -700,15 +775,6 @@ impl RolloutApi {
}
}

for (num, batch) in rollout.batches.iter() {
// This indicates a task pertaining to a batch was never processed.
for subnet in batch.subnets.iter() {
if subnet.state == SubnetRolloutState::Unknown {
error!(target:"frontend_api", "Subnet {} of batch {} was never processed by any task", subnet.subnet_id, num);
}
}
}

if let Some(state) = Some(&dag_run.state) {
match state {
DagRunState::Success => rollout.state = RolloutState::Complete,
Expand Down