Skip to content

Commit cd0b2b0

Browse files
authored
Fix support bundle logs style nit (#8454)
This fixes a missed style nit from #8438
1 parent cc1e747 commit cd0b2b0

File tree

1 file changed

+50
-42
lines changed
  • sled-agent/src/support_bundle

1 file changed

+50
-42
lines changed

sled-agent/src/support_bundle/logs.rs

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,52 @@ impl<'a> SupportBundleLogs<'a> {
8080
where
8181
Z: Into<String>,
8282
{
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.
83+
let dataset_path = self.dataset_for_temporary_storage().await?;
84+
let mut tempfile = tempfile_in(dataset_path)?;
85+
86+
let log = self.log.clone();
87+
let zone = zone.into();
88+
89+
let zip_file = {
90+
let handle = sled_diagnostics::LogsHandle::new(log);
91+
match handle.get_zone_logs(&zone, max_rotated, &mut tempfile).await
92+
{
93+
Ok(_) => Ok(tempfile),
94+
Err(e) => Err(e),
95+
}
96+
}
97+
.map_err(Error::Logs)?;
98+
99+
// Since we are using a tempfile and the file path has already been
100+
// unlinked we need to convert our existing handle.
101+
let mut zip_file_async = tokio::fs::File::from_std(zip_file);
102+
// While we are at the end of a file seek by 0 to get its final length.
103+
let len = zip_file_async.seek(std::io::SeekFrom::Current(0)).await?;
104+
// After we have written to the zip file we need to seek back to the
105+
// start before streaming it out.
106+
zip_file_async.seek(std::io::SeekFrom::Start(0)).await?;
107+
108+
const CONTENT_TYPE: http::HeaderValue =
109+
http::HeaderValue::from_static("application/zip");
110+
let content_type = Some(CONTENT_TYPE);
111+
112+
// We don't actually support range requests directly because the zip
113+
// file is created on demand but the range-requests crate provides us
114+
// with a nice wrapper for streaming out the entire zip file.
115+
Ok(make_get_response(
116+
None,
117+
len,
118+
content_type,
119+
ReaderStream::new(zip_file_async),
120+
)?)
121+
}
122+
123+
/// Attempt to find a U.2 device with the most available free space
124+
/// for temporary storage to assemble a zip file made up of all of the
125+
/// discovered zone's logs.
126+
async fn dataset_for_temporary_storage(
127+
&self,
128+
) -> Result<camino::Utf8PathBuf, Error> {
86129
let mounted_debug_datasets =
87130
self.available_datasets_rx.all_mounted_debug_datasets();
88131
let storage_paths_to_size: Vec<_> = mounted_debug_datasets
@@ -121,47 +164,12 @@ impl<'a> SupportBundleLogs<'a> {
121164
.collect::<FuturesUnordered<_>>()
122165
.collect()
123166
.await;
124-
let (largest_avail_space, _) = storage_paths_to_size
167+
168+
storage_paths_to_size
125169
.into_iter()
126170
.flatten()
127171
.max_by_key(|(_, size)| *size)
128-
.ok_or(Error::MissingStorage)?;
129-
let mut tempfile = tempfile_in(largest_avail_space)?;
130-
131-
let log = self.log.clone();
132-
let zone = zone.into();
133-
134-
let zip_file = {
135-
let handle = sled_diagnostics::LogsHandle::new(log);
136-
match handle.get_zone_logs(&zone, max_rotated, &mut tempfile).await
137-
{
138-
Ok(_) => Ok(tempfile),
139-
Err(e) => Err(e),
140-
}
141-
}
142-
.map_err(Error::Logs)?;
143-
144-
// Since we are using a tempfile and the file path has already been
145-
// unlinked we need to convert our existing handle.
146-
let mut zip_file_async = tokio::fs::File::from_std(zip_file);
147-
// While we are at the end of a file seek by 0 to get its final length.
148-
let len = zip_file_async.seek(std::io::SeekFrom::Current(0)).await?;
149-
// After we have written to the zip file we need to seek back to the
150-
// start before streaming it out.
151-
zip_file_async.seek(std::io::SeekFrom::Start(0)).await?;
152-
153-
const CONTENT_TYPE: http::HeaderValue =
154-
http::HeaderValue::from_static("application/zip");
155-
let content_type = Some(CONTENT_TYPE);
156-
157-
// We don't actually support range requests directly because the zip
158-
// file is created on demand but the range-requests crate provides us
159-
// with a nice wrapper for streaming out the entire zip file.
160-
Ok(make_get_response(
161-
None,
162-
len,
163-
content_type,
164-
ReaderStream::new(zip_file_async),
165-
)?)
172+
.map(|(dataset_path, _)| dataset_path)
173+
.ok_or(Error::MissingStorage)
166174
}
167175
}

0 commit comments

Comments
 (0)