Skip to content

Commit

Permalink
FLEET-19 Get rid of unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrainer committed Nov 12, 2024
1 parent 245aad6 commit c1ec7c7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions apollo-router/src/plugins/fleet_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ fn detect_cpu_count(system: &System) -> u64 {
system_cpus
} else {
// If it's not max then divide the two to get an integer answer
let (a, b) = readings.split_once(' ').unwrap();
a.parse::<u64>().unwrap() / b.parse::<u64>().unwrap()
match readings.split_once(' ') {
None => system_cpus,
Some((quota, period)) => {
calculate_cpu_count_with_default(system_cpus, quota, period)
}
}
}
}
Err(_) => system_cpus,
Expand All @@ -224,7 +228,7 @@ fn detect_cpu_count(system: &System) -> u64 {
if quota == "-1" {
system_cpus
} else {
quota.parse::<u64>().unwrap() / period.parse::<u64>().unwrap()
calculate_cpu_count_with_default(system_cpus, &quota, &period)
}
}
_ => system_cpus,
Expand All @@ -234,6 +238,15 @@ fn detect_cpu_count(system: &System) -> u64 {
}
}

#[cfg(target_os = "linux")]
fn calculate_cpu_count_with_default(default: u64, quota: &str, period: &str) -> u64 {
if let (Ok(q), Ok(p)) = (quota.parse::<u64>(), period.parse::<u64>()) {
q / p
} else {
default
}
}

fn get_otel_arch() -> &'static str {
match ARCH {
"x86_64" => "amd64",
Expand Down

0 comments on commit c1ec7c7

Please sign in to comment.