A running job's step strip is laid out from its earlier runs' steps and typical times, so the boxes stay put and fill instead of the layout shifting each second
Browse files at this commit573667115b130939cbc3be19c04f4868b113a11cParent: 3e78c0bAll checks have passed
Show checks
ci/buildSucceededDetails
- fix
- a running job's step strip is laid out from its earlier runs' steps and typical times, so the boxes stay put and fill instead of the layout shifting each second
5 changed files +110 -11
- crates/forge-ci/src/steps.rs +4 -1
- crates/forge-core/src/ci.rs +1 -0
- crates/forge-core/src/store/ci.rs +2 -1
- crates/forge-web-pages/src/pages/ci_estimate.rs +53 -0
- crates/forge-web-pages/src/pages/ci_runs.rs +50 -9
crates/forge-ci/src/steps.rsmodified+4 -1
| @@ -48,7 +48,10 @@ pub fn scan(bytes: &[u8], base_offset: u64, depth: &mut u32) -> Scan { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub fn strip_ansi(line: &str) -> String { | 50 | pub fn strip_ansi(line: &str) -> String { |
| 51 | - let line = line.rsplit('\r').find(|part| !part.is_empty()).unwrap_or(""); | 51 | + let line = line |
| 52 | + .rsplit('\r') | ||
| 53 | + .find(|part| !part.is_empty()) | ||
| 54 | + .unwrap_or(""); | ||
| 52 | let mut out = String::with_capacity(line.len()); | 55 | let mut out = String::with_capacity(line.len()); |
| 53 | let mut chars = line.chars().peekable(); | 56 | let mut chars = line.chars().peekable(); |
| 54 | while let Some(c) = chars.next() { | 57 | while let Some(c) = chars.next() { |
crates/forge-core/src/ci.rsmodified+1 -0
| @@ -484,6 +484,7 @@ pub struct StepSample { | |||
| 484 | pub repo_rank: i64, | 484 | pub repo_rank: i64, |
| 485 | pub job: String, | 485 | pub job: String, |
| 486 | pub step: String, | 486 | pub step: String, |
| 487 | + pub seq: i64, | ||
| 487 | pub secs: i64, | 488 | pub secs: i64, |
| 488 | } | 489 | } |
| 489 | 490 | ||
crates/forge-core/src/store/ci.rsmodified+2 -1
| @@ -1757,7 +1757,7 @@ impl Store { | |||
| 1757 | let (params, scope) = recent_done_scope(repo_id, git_refs); | 1757 | let (params, scope) = recent_done_scope(repo_id, git_refs); |
| 1758 | let sql = format!( | 1758 | let sql = format!( |
| 1759 | "{DONE_RUNS} SELECT done.git_ref, done.branch_rank, done.repo_rank, j.name, s.name, \ | 1759 | "{DONE_RUNS} SELECT done.git_ref, done.branch_rank, done.repo_rank, j.name, s.name, \ |
| 1760 | - s.started_at, s.finished_at \ | 1760 | + s.started_at, s.finished_at, s.seq \ |
| 1761 | FROM done JOIN ci_jobs j ON j.run_id = done.id \ | 1761 | FROM done JOIN ci_jobs j ON j.run_id = done.id \ |
| 1762 | JOIN ci_job_steps s ON s.job_id = j.id \ | 1762 | JOIN ci_job_steps s ON s.job_id = j.id \ |
| 1763 | WHERE ({scope}) \ | 1763 | WHERE ({scope}) \ |
| @@ -1774,6 +1774,7 @@ impl Store { | |||
| 1774 | repo_rank: col_int(row, 2)?, | 1774 | repo_rank: col_int(row, 2)?, |
| 1775 | job: col_text(row, 3)?, | 1775 | job: col_text(row, 3)?, |
| 1776 | step: col_text(row, 4)?, | 1776 | step: col_text(row, 4)?, |
| 1777 | + seq: col_int(row, 7)?, | ||
| 1777 | secs: (end - start).max(0), | 1778 | secs: (end - start).max(0), |
| 1778 | }), | 1779 | }), |
| 1779 | _ => None, | 1780 | _ => None, |
crates/forge-web-pages/src/pages/ci_estimate.rsmodified+53 -0
| @@ -43,6 +43,29 @@ pub fn step_expected(samples: &[StepSample], git_ref: &str, job: &str, step: &st | |||
| 43 | expected_of(&rows, git_ref) | 43 | expected_of(&rows, git_ref) |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | +pub fn typical_step(samples: &[StepSample], git_ref: &str, job: &str, step: &str) -> Option<i64> { | ||
| 47 | + step_expected(samples, git_ref, job, step).or_else(|| { | ||
| 48 | + let secs: Vec<i64> = samples | ||
| 49 | + .iter() | ||
| 50 | + .filter(|s| s.job == job && s.step == step) | ||
| 51 | + .map(|s| s.secs) | ||
| 52 | + .collect(); | ||
| 53 | + (!secs.is_empty()).then(|| median(secs)) | ||
| 54 | + }) | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +pub fn planned_steps(samples: &[StepSample], job: &str) -> Vec<String> { | ||
| 58 | + let mut seen: Vec<(i64, &str)> = Vec::new(); | ||
| 59 | + for s in samples.iter().filter(|s| s.job == job) { | ||
| 60 | + match seen.iter_mut().find(|(_, name)| *name == s.step) { | ||
| 61 | + Some(entry) => entry.0 = entry.0.min(s.seq), | ||
| 62 | + None => seen.push((s.seq, &s.step)), | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + seen.sort(); | ||
| 66 | + seen.into_iter().map(|(_, name)| name.to_owned()).collect() | ||
| 67 | +} | ||
| 68 | + | ||
| 46 | struct Sample<'a> { | 69 | struct Sample<'a> { |
| 47 | git_ref: &'a str, | 70 | git_ref: &'a str, |
| 48 | branch_rank: i64, | 71 | branch_rank: i64, |
| @@ -177,6 +200,36 @@ fn left_text(lang: Lang, secs: i64) -> String { | |||
| 177 | mod tests { | 200 | mod tests { |
| 178 | use super::*; | 201 | use super::*; |
| 179 | 202 | ||
| 203 | + #[test] | ||
| 204 | + fn planned_steps_keep_the_run_order_and_typical_falls_back_to_one_run() { | ||
| 205 | + let step = |name: &str, seq: i64, secs: i64| StepSample { | ||
| 206 | + git_ref: "refs/heads/main".to_owned(), | ||
| 207 | + branch_rank: 1, | ||
| 208 | + repo_rank: 1, | ||
| 209 | + job: "build".to_owned(), | ||
| 210 | + step: name.to_owned(), | ||
| 211 | + seq, | ||
| 212 | + secs, | ||
| 213 | + }; | ||
| 214 | + let samples = [ | ||
| 215 | + step("Build", 2, 600), | ||
| 216 | + step("Packages", 0, 40), | ||
| 217 | + step("Toolchain", 1, 12), | ||
| 218 | + ]; | ||
| 219 | + assert_eq!( | ||
| 220 | + planned_steps(&samples, "build"), | ||
| 221 | + ["Packages", "Toolchain", "Build"] | ||
| 222 | + ); | ||
| 223 | + assert_eq!( | ||
| 224 | + typical_step(&samples, "refs/heads/main", "build", "Build"), | ||
| 225 | + Some(600) | ||
| 226 | + ); | ||
| 227 | + assert_eq!( | ||
| 228 | + typical_step(&samples, "refs/heads/main", "build", "Lint"), | ||
| 229 | + None | ||
| 230 | + ); | ||
| 231 | + } | ||
| 232 | + | ||
| 180 | fn sample(git_ref: &str, branch_rank: i64, repo_rank: i64, secs: i64) -> JobSample { | 233 | fn sample(git_ref: &str, branch_rank: i64, repo_rank: i64, secs: i64) -> JobSample { |
| 181 | JobSample { | 234 | JobSample { |
| 182 | git_ref: git_ref.to_owned(), | 235 | git_ref: git_ref.to_owned(), |
crates/forge-web-pages/src/pages/ci_runs.rsmodified+50 -9
| @@ -1134,17 +1134,39 @@ fn job_steps( | |||
| 1134 | }) | 1134 | }) |
| 1135 | }) | 1135 | }) |
| 1136 | .collect(); | 1136 | .collect(); |
| 1137 | - let total: u64 = elapsed_of | 1137 | + let live = job.finished.is_none(); |
| 1138 | + let typical = |name: &str| ci_estimate::typical_step(samples, &run.git_ref, &job.name, name); | ||
| 1139 | + let planned: Vec<String> = if live { | ||
| 1140 | + ci_estimate::planned_steps(samples, &job.name) | ||
| 1141 | + .into_iter() | ||
| 1142 | + .filter(|name| !steps.iter().any(|step| &step.name == name)) | ||
| 1143 | + .collect() | ||
| 1144 | + } else { | ||
| 1145 | + Vec::new() | ||
| 1146 | + }; | ||
| 1147 | + let weights: Vec<u64> = steps | ||
| 1138 | .iter() | 1148 | .iter() |
| 1139 | - .map(|secs| u64::try_from(*secs).unwrap_or(0)) | 1149 | + .zip(&elapsed_of) |
| 1140 | - .sum(); | 1150 | + .map(|(step, elapsed)| { |
| 1141 | - for (step, elapsed) in steps.iter().zip(elapsed_of) { | 1151 | + let planned = if live { |
| 1152 | + typical(&step.name).unwrap_or(0) | ||
| 1153 | + } else { | ||
| 1154 | + 0 | ||
| 1155 | + }; | ||
| 1156 | + u64::try_from(planned.max(*elapsed)).unwrap_or(0) | ||
| 1157 | + }) | ||
| 1158 | + .chain( | ||
| 1159 | + planned | ||
| 1160 | + .iter() | ||
| 1161 | + .map(|name| u64::try_from(typical(name).unwrap_or(0)).unwrap_or(0)), | ||
| 1162 | + ) | ||
| 1163 | + .collect(); | ||
| 1164 | + let total: u64 = weights.iter().sum(); | ||
| 1165 | + for ((step, elapsed), weight) in steps.iter().zip(elapsed_of).zip(&weights) { | ||
| 1142 | let state = step.state(job.state); | 1166 | let state = step.state(job.state); |
| 1143 | let running = state == StepState::Running; | 1167 | let running = state == StepState::Running; |
| 1144 | let started = unix_of(&step.started_at); | 1168 | let started = unix_of(&step.started_at); |
| 1145 | - let expected = running | 1169 | + let expected = running.then(|| typical(&step.name)).flatten(); |
| 1146 | - .then(|| ci_estimate::step_expected(samples, &run.git_ref, &job.name, &step.name)) | ||
| 1147 | - .flatten(); | ||
| 1148 | let href = (job.log_bytes != 0).then(|| format!("{pick}&step={}", step.seq)); | 1170 | let href = (job.log_bytes != 0).then(|| format!("{pick}&step={}", step.seq)); |
| 1149 | let pct = expected | 1171 | let pct = expected |
| 1150 | .filter(|secs| *secs > 0) | 1172 | .filter(|secs| *secs > 0) |
| @@ -1181,7 +1203,23 @@ fn job_steps( | |||
| 1181 | StepState::Failed => "bad", | 1203 | StepState::Failed => "bad", |
| 1182 | StepState::Cancelled => "skip", | 1204 | StepState::Cancelled => "skip", |
| 1183 | }, | 1205 | }, |
| 1184 | - fr: crate::views::parts::seg_fr(u64::try_from(elapsed).unwrap_or(0), total), | 1206 | + fr: crate::views::parts::seg_fr(*weight, total), |
| 1207 | + }); | ||
| 1208 | + } | ||
| 1209 | + for (name, weight) in planned.into_iter().zip(&weights[steps.len()..]) { | ||
| 1210 | + lines.push(StepLine { | ||
| 1211 | + name, | ||
| 1212 | + duration: String::new(), | ||
| 1213 | + since: None, | ||
| 1214 | + expected: None, | ||
| 1215 | + selected: false, | ||
| 1216 | + href: None, | ||
| 1217 | + value: None, | ||
| 1218 | + expected_secs: None, | ||
| 1219 | + pct: None, | ||
| 1220 | + state_class: "ci-sp-off", | ||
| 1221 | + seg: "wait", | ||
| 1222 | + fr: crate::views::parts::seg_fr(*weight, total), | ||
| 1185 | }); | 1223 | }); |
| 1186 | } | 1224 | } |
| 1187 | lines | 1225 | lines |
| @@ -3014,7 +3052,10 @@ mod tests { | |||
| 3014 | fn previews_skip_blank_lines_and_ansi_codes() { | 3052 | fn previews_skip_blank_lines_and_ansi_codes() { |
| 3015 | assert_eq!(strip_ansi("\u{1b}[31mred\u{1b}[0m ok"), "red ok"); | 3053 | assert_eq!(strip_ansi("\u{1b}[31mred\u{1b}[0m ok"), "red ok"); |
| 3016 | assert_eq!(strip_ansi("\u{1b}]0;title\u{7}x"), "x"); | 3054 | assert_eq!(strip_ansi("\u{1b}]0;title\u{7}x"), "x"); |
| 3017 | - assert_eq!(strip_ansi("Building 1/2\r Compiling a\r"), " Compiling a"); | 3055 | + assert_eq!( |
| 3056 | + strip_ansi("Building 1/2\r Compiling a\r"), | ||
| 3057 | + " Compiling a" | ||
| 3058 | + ); | ||
| 3018 | let tail = vec!["a".to_owned(), " b ".to_owned(), String::new()]; | 3059 | let tail = vec!["a".to_owned(), " b ".to_owned(), String::new()]; |
| 3019 | assert_eq!(last_line(&tail), Some("b")); | 3060 | assert_eq!(last_line(&tail), Some("b")); |
| 3020 | assert_eq!(last_line(&[]), None); | 3061 | assert_eq!(last_line(&[]), None); |