Skip to content

Commit 09d44a4

Browse files
committed
Print metrics postprocessing to stdout
This allows the code to be simplified a little bit.
1 parent 301c384 commit 09d44a4

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ jobs:
253253
fi
254254
255255
./build/citool/debug/citool postprocess-metrics \
256-
${METRICS} ${GITHUB_STEP_SUMMARY}
256+
${METRICS} >> ${GITHUB_STEP_SUMMARY}
257257
258258
- name: upload job metrics to DataDog
259259
# This step is not critical, and if some I/O problem happens, we don't want

src/ci/citool/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ enum Args {
158158
PostprocessMetrics {
159159
/// Path to the metrics.json file
160160
metrics_path: PathBuf,
161-
/// Path to a file where the postprocessed metrics summary will be stored.
162-
/// Usually, this will be GITHUB_STEP_SUMMARY on CI.
163-
summary_path: PathBuf,
164161
},
165162
/// Upload CI metrics to Datadog.
166163
UploadBuildMetrics {
@@ -211,8 +208,8 @@ fn main() -> anyhow::Result<()> {
211208
Args::UploadBuildMetrics { cpu_usage_csv } => {
212209
upload_ci_metrics(&cpu_usage_csv)?;
213210
}
214-
Args::PostprocessMetrics { metrics_path, summary_path } => {
215-
postprocess_metrics(&metrics_path, &summary_path)?;
211+
Args::PostprocessMetrics { metrics_path } => {
212+
postprocess_metrics(&metrics_path)?;
216213
}
217214
Args::PostMergeReport { current: commit, parent } => {
218215
post_merge_report(load_db(default_jobs_file)?, parent, commit)?;

src/ci/citool/src/metrics.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,51 @@
11
use std::collections::BTreeMap;
2-
use std::fs::File;
3-
use std::io::Write;
42
use std::path::Path;
53

64
use anyhow::Context;
75
use build_helper::metrics::{
86
BuildStep, JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, format_build_steps,
97
};
108

11-
pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow::Result<()> {
9+
pub fn postprocess_metrics(metrics_path: &Path) -> anyhow::Result<()> {
1210
let metrics = load_metrics(metrics_path)?;
1311

14-
let mut file = File::options()
15-
.append(true)
16-
.create(true)
17-
.open(summary_path)
18-
.with_context(|| format!("Cannot open summary file at {summary_path:?}"))?;
19-
2012
if !metrics.invocations.is_empty() {
21-
writeln!(file, "# Bootstrap steps")?;
22-
record_bootstrap_step_durations(&metrics, &mut file)?;
23-
record_test_suites(&metrics, &mut file)?;
13+
println!("# Bootstrap steps");
14+
record_bootstrap_step_durations(&metrics);
15+
record_test_suites(&metrics);
2416
}
2517

2618
Ok(())
2719
}
2820

29-
fn record_bootstrap_step_durations(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> {
21+
fn record_bootstrap_step_durations(metrics: &JsonRoot) {
3022
for invocation in &metrics.invocations {
3123
let step = BuildStep::from_invocation(invocation);
3224
let table = format_build_steps(&step);
3325
eprintln!("Step `{}`\n{table}\n", invocation.cmdline);
34-
writeln!(
35-
file,
26+
println!(
3627
r"<details>
3728
<summary>{}</summary>
3829
<pre><code>{table}</code></pre>
3930
</details>
4031
",
4132
invocation.cmdline
42-
)?;
33+
);
4334
}
4435
eprintln!("Recorded {} bootstrap invocation(s)", metrics.invocations.len());
45-
46-
Ok(())
4736
}
4837

49-
fn record_test_suites(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> {
38+
fn record_test_suites(metrics: &JsonRoot) {
5039
let suites = get_test_suites(&metrics);
5140

5241
if !suites.is_empty() {
5342
let aggregated = aggregate_test_suites(&suites);
5443
let table = render_table(aggregated);
55-
writeln!(file, "\n# Test results\n")?;
56-
writeln!(file, "{table}")?;
44+
println!("\n# Test results\n");
45+
println!("{table}");
5746
} else {
5847
eprintln!("No test suites found in metrics");
5948
}
60-
61-
Ok(())
6249
}
6350

6451
fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {

0 commit comments

Comments
 (0)