Skip to content

[nexus] support bundle diag commands should be saved in json #7462

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

18 changes: 11 additions & 7 deletions nexus/src/app/background/tasks/support_bundle_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Background task for managing Support Bundles

use crate::app::background::BackgroundTask;
use anyhow::Context;
use camino::Utf8DirEntry;
use camino::Utf8Path;
use camino_tempfile::Utf8TempDir;
Expand Down Expand Up @@ -772,15 +773,15 @@ async fn sha2_hash(file: &mut tokio::fs::File) -> anyhow::Result<ArtifactHash> {
}

/// Run a `sled-dianostics` future and save its output to a corresponding file.
async fn save_diag_cmd_output_or_error<F, D: std::fmt::Debug>(
async fn save_diag_cmd_output_or_error<F, S: serde::Serialize>(
path: &Utf8Path,
command: &str,
future: F,
) -> anyhow::Result<()>
where
F: Future<
Output = Result<
sled_agent_client::ResponseValue<D>,
sled_agent_client::ResponseValue<S>,
sled_agent_client::Error<sled_agent_client::types::Error>,
>,
> + Send,
Expand All @@ -789,11 +790,14 @@ where
match result {
Ok(result) => {
let output = result.into_inner();
tokio::fs::write(
path.join(format!("{command}.txt")),
format!("{output:?}"),
)
.await?;
let json = serde_json::to_string(&output).with_context(|| {
format!("failed to serialize {command} output as json")
})?;
tokio::fs::write(path.join(format!("{command}.json")), json)
.await
.with_context(|| {
format!("failed to write output of {command} to file")
})?;
}
Err(err) => {
tokio::fs::write(
Expand Down
Loading