From 717b6b4e2c6520667e6ce99f0fae7d25f764e49c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 14 Oct 2024 07:33:27 -0700 Subject: [PATCH] integration-tests: show logs in sorted order We were collecting the logs, printing them as we found them, and then returning the sorted result. That made it awkward for a human to review, so what we do now is defer printing the logged records until after we have sorted them. For records with the same timestamp, we sort based on the message id and the record type so that there is some additional consistency and to make it easier to reason about. --- crates/integration-tests/src/kumod.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/integration-tests/src/kumod.rs b/crates/integration-tests/src/kumod.rs index 3bde6943..bc308c7a 100644 --- a/crates/integration-tests/src/kumod.rs +++ b/crates/integration-tests/src/kumod.rs @@ -484,8 +484,6 @@ impl KumoDaemon { let entry = entry?; if entry.file_type()?.is_file() { let text = read_zstd_file_with_retry(&entry.path())?; - eprintln!("{text}"); - for line in text.lines() { let record: JsonLogRecord = serde_json::from_str(&line)?; records.push(record); @@ -493,7 +491,22 @@ impl KumoDaemon { } } - records.sort_by(|a, b| a.timestamp.cmp(&b.timestamp)); + records.sort_by(|a, b| { + use std::cmp::Ordering; + match a.timestamp.cmp(&b.timestamp) { + Ordering::Equal => match a.id.cmp(&b.id) { + Ordering::Equal => a.kind.cmp(&b.kind), + r => r, + }, + r => r, + } + }); + + // and print it in the sorted order for easier understanding + for r in &records { + eprintln!("{}", serde_json::to_string(r).unwrap()); + } + Ok(records) }