Skip to content

Commit 3d4776c

Browse files
authored
aj/fix fd max metric (#535)
* feat: v69-next * fix: prevent early return from skipping fd check * fix: format * fix: remove result, always a float * fix: remove unwraps * fix: remove version bump * fix: must use
1 parent e5c5a45 commit 3d4776c

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

bottlecap/src/metrics/enhanced/lambda.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ impl Lambda {
566566

567567
// Set fd_max and initial value for fd_use
568568
let fd_max = proc::get_fd_max_data(&pids);
569-
let mut fd_use = proc::get_fd_use_data(&pids).unwrap_or_else(|_| -1_f64);
569+
let mut fd_use = proc::get_fd_use_data(&pids);
570570

571571
// Set threads_max and initial value for threads_use
572572
let threads_max = proc::get_threads_max_data(&pids);
@@ -586,9 +586,8 @@ impl Lambda {
586586
// Otherwise keep monitoring file descriptor and thread usage periodically
587587
_ = interval.tick() => {
588588
pids = proc::get_pid_list();
589-
if let Ok(fd_use_curr) = proc::get_fd_use_data(&pids) {
590-
fd_use = fd_use.max(fd_use_curr);
591-
}
589+
let fd_use_curr = proc::get_fd_use_data(&pids);
590+
fd_use = fd_use.max(fd_use_curr);
592591
if let Ok(threads_use_curr) = proc::get_threads_use_data(&pids) {
593592
threads_use = threads_use.max(threads_use_curr);
594593
}

bottlecap/src/proc/mod.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use constants::{
1111
LAMDBA_NETWORK_INTERFACE, PROC_NET_DEV_PATH, PROC_PATH, PROC_STAT_PATH, PROC_UPTIME_PATH,
1212
};
1313
use regex::Regex;
14-
use tracing::debug;
14+
use tracing::{debug, trace};
1515

1616
#[must_use]
1717
pub fn get_pid_list() -> Vec<i64> {
@@ -244,26 +244,29 @@ fn get_fd_max_data_from_path(path: &str, pids: &[i64]) -> f64 {
244244
fd_max
245245
}
246246

247-
pub fn get_fd_use_data(pids: &[i64]) -> Result<f64, io::Error> {
247+
#[must_use]
248+
pub fn get_fd_use_data(pids: &[i64]) -> f64 {
248249
get_fd_use_data_from_path(PROC_PATH, pids)
249250
}
250251

251-
fn get_fd_use_data_from_path(path: &str, pids: &[i64]) -> Result<f64, io::Error> {
252+
fn get_fd_use_data_from_path(path: &str, pids: &[i64]) -> f64 {
252253
let mut fd_use = 0;
253254

254255
for &pid in pids {
255256
let fd_path = format!("{path}/{pid}/fd");
256-
let Ok(files) = fs::read_dir(fd_path) else {
257-
return Err(io::Error::new(
258-
io::ErrorKind::InvalidData,
259-
"File descriptor use data not found",
260-
));
257+
let Ok(files) = fs::read_dir(&fd_path) else {
258+
trace!(
259+
"File descriptor use data not found in path {} with pid {}",
260+
fd_path,
261+
pid
262+
);
263+
continue;
261264
};
262265
let count = files.count();
263266
fd_use += count;
264267
}
265268

266-
Ok(fd_use as f64)
269+
fd_use as f64
267270
}
268271

269272
#[must_use]
@@ -473,14 +476,8 @@ mod tests {
473476
fn test_get_fd_use_data() {
474477
let path = "./tests/proc/process/valid";
475478
let pids = get_pid_list_from_path(path_from_root(path).as_str());
476-
let fd_use_result = get_fd_use_data_from_path(path, &pids);
477-
assert!(fd_use_result.is_ok());
478-
let fd_use = fd_use_result.unwrap();
479+
let fd_use = get_fd_use_data_from_path(path, &pids);
479480
assert!((fd_use - 5.0).abs() < f64::EPSILON);
480-
481-
let path = "./tests/proc/process/invalid_missing";
482-
let fd_use_result = get_fd_use_data_from_path(path, &pids);
483-
assert!(fd_use_result.is_err());
484481
}
485482

486483
#[test]

0 commit comments

Comments
 (0)