Skip to content

Commit 2627bf8

Browse files
authored
[sled-diagnostics] log collection should happen on u.2s (#8438)
1 parent 2f8d2cd commit 2627bf8

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

illumos-utils/src/zfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl Zfs {
13081308
.collect::<Result<Vec<&str>, GetValueError>>()?
13091309
.join(",");
13101310

1311-
cmd.args(&[ZFS, "get", "-Ho", "value"]);
1311+
cmd.args(&[ZFS, "get", "-Hpo", "value"]);
13121312
if let Some(source) = source {
13131313
cmd.args(&["-s", &source.to_string()]);
13141314
}

sled-agent/src/sled_agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl SledAgent {
703703
pub(crate) fn as_support_bundle_logs(&self) -> SupportBundleLogs<'_> {
704704
SupportBundleLogs::new(
705705
&self.log,
706-
self.inner.config_reconciler.internal_disks_rx(),
706+
self.inner.config_reconciler.available_datasets_rx(),
707707
)
708708
}
709709

sled-agent/src/support_bundle/logs.rs

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
77
use camino_tempfile::tempfile_in;
88
use dropshot::HttpError;
9+
use futures::StreamExt;
10+
use futures::stream::FuturesUnordered;
911
use range_requests::make_get_response;
10-
use sled_agent_config_reconciler::InternalDisksReceiver;
12+
use sled_agent_config_reconciler::AvailableDatasetsReceiver;
1113
use slog::Logger;
1214
use slog_error_chain::InlineErrorChain;
1315
use tokio::io::AsyncSeekExt;
@@ -43,15 +45,15 @@ impl From<Error> for HttpError {
4345

4446
pub struct SupportBundleLogs<'a> {
4547
log: &'a Logger,
46-
internal_disks_rx: &'a InternalDisksReceiver,
48+
available_datasets_rx: AvailableDatasetsReceiver,
4749
}
4850

4951
impl<'a> SupportBundleLogs<'a> {
5052
pub fn new(
5153
log: &'a Logger,
52-
internal_disks_rx: &'a InternalDisksReceiver,
54+
available_datasets_rx: AvailableDatasetsReceiver,
5355
) -> Self {
54-
Self { log, internal_disks_rx }
56+
Self { log, available_datasets_rx }
5557
}
5658

5759
/// Get a list of zones on a sled containing logs that we want to include in
@@ -78,12 +80,53 @@ impl<'a> SupportBundleLogs<'a> {
7880
where
7981
Z: Into<String>,
8082
{
81-
// We are using an M.2 device for temporary storage to assemble a zip
82-
// file made up of all of the discovered zone's logs.
83-
let current_internal_disks = self.internal_disks_rx.current();
84-
let mut m2_debug_datasets = current_internal_disks.all_debug_datasets();
85-
let tempdir = m2_debug_datasets.next().ok_or(Error::MissingStorage)?;
86-
let mut tempfile = tempfile_in(tempdir)?;
83+
// Attempt to find a U.2 device with the most available free space
84+
// for temporary storage to assemble a zip file made up of all of the
85+
// discovered zone's logs.
86+
let mounted_debug_datasets =
87+
self.available_datasets_rx.all_mounted_debug_datasets();
88+
let storage_paths_to_size: Vec<_> = mounted_debug_datasets
89+
.into_iter()
90+
.map(|dataset_path| {
91+
let path = dataset_path.path;
92+
async move {
93+
match illumos_utils::zfs::Zfs::get_value(
94+
path.as_str(),
95+
"available",
96+
)
97+
.await
98+
{
99+
Ok(size_str) => match size_str.parse::<usize>() {
100+
Ok(size) => Some((path, size)),
101+
Err(e) => {
102+
warn!(
103+
&self.log,
104+
"failed to parse available size for the \
105+
dataset at path {path}: {e}"
106+
);
107+
None
108+
}
109+
},
110+
Err(e) => {
111+
warn!(
112+
&self.log,
113+
"failed to get available size for the dataset \
114+
at path {path}: {e}"
115+
);
116+
None
117+
}
118+
}
119+
}
120+
})
121+
.collect::<FuturesUnordered<_>>()
122+
.collect()
123+
.await;
124+
let (largest_avail_space, _) = storage_paths_to_size
125+
.into_iter()
126+
.flatten()
127+
.max_by_key(|(_, size)| *size)
128+
.ok_or(Error::MissingStorage)?;
129+
let mut tempfile = tempfile_in(largest_avail_space)?;
87130

88131
let log = self.log.clone();
89132
let zone = zone.into();

sled-storage/src/resources.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,6 @@ impl AllDisks {
209209
.collect()
210210
}
211211

212-
/// Return the directories that can be used for temporary sled-diagnostics
213-
/// file storage.
214-
pub fn all_sled_diagnostics_directories(&self) -> Vec<Utf8PathBuf> {
215-
// These directories are currently used for tempfile storage when
216-
// zipping up zone logs before shuffling them off to a nexus collecting
217-
// a support bundle.
218-
self.all_m2_mountpoints(M2_DEBUG_DATASET).into_iter().collect()
219-
}
220-
221212
/// Returns an iterator over all managed disks.
222213
pub fn iter_managed(&self) -> impl Iterator<Item = (&DiskIdentity, &Disk)> {
223214
self.inner.values.iter().filter_map(|(identity, disk)| match disk {

0 commit comments

Comments
 (0)