Skip to content

Commit b9f8ae7

Browse files
authored
[nexus] support bundle diag commands should be saved in json (#7462)
Diagnostic commands now output the json serialized value rather than the debug output for the inner type. This is on top of: - #7461
1 parent 3374aa6 commit b9f8ae7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

nexus/src/app/background/tasks/support_bundle_collector.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! Background task for managing Support Bundles
66
77
use crate::app::background::BackgroundTask;
8+
use anyhow::Context;
89
use camino::Utf8DirEntry;
910
use camino::Utf8Path;
1011
use camino_tempfile::Utf8TempDir;
@@ -772,15 +773,15 @@ async fn sha2_hash(file: &mut tokio::fs::File) -> anyhow::Result<ArtifactHash> {
772773
}
773774

774775
/// Run a `sled-dianostics` future and save its output to a corresponding file.
775-
async fn save_diag_cmd_output_or_error<F, D: std::fmt::Debug>(
776+
async fn save_diag_cmd_output_or_error<F, S: serde::Serialize>(
776777
path: &Utf8Path,
777778
command: &str,
778779
future: F,
779780
) -> anyhow::Result<()>
780781
where
781782
F: Future<
782783
Output = Result<
783-
sled_agent_client::ResponseValue<D>,
784+
sled_agent_client::ResponseValue<S>,
784785
sled_agent_client::Error<sled_agent_client::types::Error>,
785786
>,
786787
> + Send,
@@ -789,11 +790,14 @@ where
789790
match result {
790791
Ok(result) => {
791792
let output = result.into_inner();
792-
tokio::fs::write(
793-
path.join(format!("{command}.txt")),
794-
format!("{output:?}"),
795-
)
796-
.await?;
793+
let json = serde_json::to_string(&output).with_context(|| {
794+
format!("failed to serialize {command} output as json")
795+
})?;
796+
tokio::fs::write(path.join(format!("{command}.json")), json)
797+
.await
798+
.with_context(|| {
799+
format!("failed to write output of {command} to file")
800+
})?;
797801
}
798802
Err(err) => {
799803
tokio::fs::write(

0 commit comments

Comments
 (0)