Skip to content

Commit 98fd85c

Browse files
committed
Clippy
1 parent aa2fbcf commit 98fd85c

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

lustrefs-exporter/src/routes.rs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -178,40 +178,39 @@ pub async fn scrape(Query(params): Query<Params>) -> Result<Response<Body>, Erro
178178
.or_insert(value);
179179
}
180180

181-
if targets.enabled(&Dimension::Jobstats) {
182-
if let Ok(mut child) = tokio::task::spawn_blocking(move || jobstats_metrics_cmd().spawn())
181+
if targets.enabled(&Dimension::Jobstats)
182+
&& let Ok(mut child) = tokio::task::spawn_blocking(move || jobstats_metrics_cmd().spawn())
183183
.await?
184184
.inspect_err(|e| tracing::debug!("Error while spawning lctl jobstats: {e}"))
185-
{
186-
let reader = BufReader::with_capacity(
187-
128 * 1_024,
188-
child.stdout.take().ok_or(io::Error::new(
189-
io::ErrorKind::NotFound,
190-
"stdout missing for lctl jobstats call.",
191-
))?,
192-
);
193-
194-
let reader_stderr = BufReader::new(child.stderr.take().ok_or(io::Error::new(
185+
{
186+
let reader = BufReader::with_capacity(
187+
128 * 1_024,
188+
child.stdout.take().ok_or(io::Error::new(
195189
io::ErrorKind::NotFound,
196-
"stderr missing for lctl jobstats call.",
197-
))?);
190+
"stdout missing for lctl jobstats call.",
191+
))?,
192+
);
198193

199-
tokio::task::spawn(async move {
200-
for line in reader_stderr.lines().map_while(Result::ok) {
201-
tracing::debug!("stderr: {line}");
202-
}
203-
});
194+
let reader_stderr = BufReader::new(child.stderr.take().ok_or(io::Error::new(
195+
io::ErrorKind::NotFound,
196+
"stderr missing for lctl jobstats call.",
197+
))?);
204198

205-
tokio::task::spawn_blocking(move || {
206-
if let Err(e) = child.wait() {
207-
tracing::debug!("Unexpected error when waiting for child: {e}");
208-
}
209-
});
199+
tokio::task::spawn(async move {
200+
for line in reader_stderr.lines().map_while(Result::ok) {
201+
tracing::debug!("stderr: {line}");
202+
}
203+
});
210204

211-
jobstats_stream(reader, JobstatMetrics::default())
212-
.await?
213-
.register_metric(&mut registry);
214-
}
205+
tokio::task::spawn_blocking(move || {
206+
if let Err(e) = child.wait() {
207+
tracing::debug!("Unexpected error when waiting for child: {e}");
208+
}
209+
});
210+
211+
jobstats_stream(reader, JobstatMetrics::default())
212+
.await?
213+
.register_metric(&mut registry);
215214
}
216215

217216
if targets.enabled(&Dimension::Lustre) {
@@ -316,10 +315,10 @@ mod tests {
316315
#[serial]
317316
async fn test_metrics_endpoint_is_idempotent() -> Result<(), Box<dyn std::error::Error>> {
318317
let (request, app) = get_app();
319-
let original = app.oneshot(request).await.unwrap().as_text().await;
318+
let original = app.oneshot(request).await.unwrap().try_into_string().await;
320319

321320
let (request, app) = get_app();
322-
let new = app.oneshot(request).await.unwrap().as_text().await;
321+
let new = app.oneshot(request).await.unwrap().try_into_string().await;
323322
assert_eq!(original, new);
324323

325324
insta::assert_snapshot!(original);
@@ -328,11 +327,11 @@ mod tests {
328327
}
329328

330329
trait AsText {
331-
fn as_text(self) -> impl Future<Output = String>;
330+
fn try_into_string(self) -> impl Future<Output = String>;
332331
}
333332

334333
impl AsText for Response<Body> {
335-
async fn as_text(self) -> String {
334+
async fn try_into_string(self) -> String {
336335
let mut body = self.into_body().into_data_stream();
337336
let mut out = vec![];
338337

@@ -355,7 +354,7 @@ mod tests {
355354
#[serial]
356355
async fn test_app_params(params: Option<&str>) {
357356
let request = Request::builder()
358-
.uri(&format!(
357+
.uri(format!(
359358
"/metrics{}",
360359
params.map(|p| format!("?{p}")).unwrap_or_default()
361360
))
@@ -366,7 +365,10 @@ mod tests {
366365
let response = crate::routes::app().oneshot(request).await.unwrap();
367366

368367
assert!(response.status().is_success());
369-
insta::assert_snapshot!(params.unwrap_or("default"), response.as_text().await);
368+
insta::assert_snapshot!(
369+
params.unwrap_or("default"),
370+
response.try_into_string().await
371+
);
370372
}
371373

372374
#[commandeer(Replay, "lctl", "lnetctl")]

lustrefs-exporter/src/snapshots/lustrefs_exporter__routes__tests__jobstats_with_stderr_output.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,15 @@ lustre_stats_time_total{component="mdt",operation="open",target="ai400x2-MDT0000
12251225
lustre_stats_time_total{component="mdt",operation="setattr",target="ai400x2-MDT0000"} 22544
12261226
lustre_stats_time_total{component="mdt",operation="statfs",target="ai400x2-MDT0000"} 1292933
12271227
lustre_stats_time_total{component="mdt",operation="sync",target="ai400x2-MDT0000"} 7767
1228+
# HELP lustre_send_bytes_total Total number of bytes that have been sent.
1229+
# TYPE lustre_send_bytes_total counter
1230+
lustre_send_bytes_total{} 261865376
1231+
# HELP lustre_receive_bytes_total Total number of bytes that have been received.
1232+
# TYPE lustre_receive_bytes_total counter
1233+
lustre_receive_bytes_total{} 254091008
1234+
# HELP lustre_drop_bytes_total Total number of bytes that have been dropped.
1235+
# TYPE lustre_drop_bytes_total counter
1236+
lustre_drop_bytes_total{} 4832
12281237
# HELP lustre_send_count_total Total number of messages that have been sent.
12291238
# TYPE lustre_send_count_total counter
12301239
lustre_send_count_total{nid="0@lo"} 180076
@@ -1240,13 +1249,4 @@ lustre_receive_count_total{nid="172.16.0.25@tcp"} 464877
12401249
lustre_drop_count_total{nid="0@lo"} 4
12411250
lustre_drop_count_total{nid="172.16.0.24@tcp"} 4
12421251
lustre_drop_count_total{nid="172.16.0.25@tcp"} 3
1243-
# HELP lustre_send_bytes_total Total number of bytes that have been sent.
1244-
# TYPE lustre_send_bytes_total counter
1245-
lustre_send_bytes_total{} 261865376
1246-
# HELP lustre_receive_bytes_total Total number of bytes that have been received.
1247-
# TYPE lustre_receive_bytes_total counter
1248-
lustre_receive_bytes_total{} 254091008
1249-
# HELP lustre_drop_bytes_total Total number of bytes that have been dropped.
1250-
# TYPE lustre_drop_bytes_total counter
1251-
lustre_drop_bytes_total{} 4832
12521252
# EOF

lustrefs-exporter/src/snapshots/lustrefs_exporter__routes__tests__metrics_endpoint_is_idempotent.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: lustrefs-exporter/src/routes.rs
3-
expression: original_body_str
3+
expression: original
44
---
55
# HELP lustre_job_read_samples_total Total number of reads that have been recorded.
66
# TYPE lustre_job_read_samples_total counter
@@ -1225,6 +1225,15 @@ lustre_stats_time_total{component="mdt",operation="open",target="ai400x2-MDT0000
12251225
lustre_stats_time_total{component="mdt",operation="setattr",target="ai400x2-MDT0000"} 22544
12261226
lustre_stats_time_total{component="mdt",operation="statfs",target="ai400x2-MDT0000"} 1292933
12271227
lustre_stats_time_total{component="mdt",operation="sync",target="ai400x2-MDT0000"} 7767
1228+
# HELP lustre_send_bytes_total Total number of bytes that have been sent.
1229+
# TYPE lustre_send_bytes_total counter
1230+
lustre_send_bytes_total{} 261865376
1231+
# HELP lustre_receive_bytes_total Total number of bytes that have been received.
1232+
# TYPE lustre_receive_bytes_total counter
1233+
lustre_receive_bytes_total{} 254091008
1234+
# HELP lustre_drop_bytes_total Total number of bytes that have been dropped.
1235+
# TYPE lustre_drop_bytes_total counter
1236+
lustre_drop_bytes_total{} 4832
12281237
# HELP lustre_send_count_total Total number of messages that have been sent.
12291238
# TYPE lustre_send_count_total counter
12301239
lustre_send_count_total{nid="0@lo"} 180076
@@ -1240,13 +1249,4 @@ lustre_receive_count_total{nid="172.16.0.25@tcp"} 464877
12401249
lustre_drop_count_total{nid="0@lo"} 4
12411250
lustre_drop_count_total{nid="172.16.0.24@tcp"} 4
12421251
lustre_drop_count_total{nid="172.16.0.25@tcp"} 3
1243-
# HELP lustre_send_bytes_total Total number of bytes that have been sent.
1244-
# TYPE lustre_send_bytes_total counter
1245-
lustre_send_bytes_total{} 261865376
1246-
# HELP lustre_receive_bytes_total Total number of bytes that have been received.
1247-
# TYPE lustre_receive_bytes_total counter
1248-
lustre_receive_bytes_total{} 254091008
1249-
# HELP lustre_drop_bytes_total Total number of bytes that have been dropped.
1250-
# TYPE lustre_drop_bytes_total counter
1251-
lustre_drop_bytes_total{} 4832
12521252
# EOF

0 commit comments

Comments
 (0)