diff --git a/apollo-router/src/plugins/fleet_detector.rs b/apollo-router/src/plugins/fleet_detector.rs index bf36dabcf1..4f25931868 100644 --- a/apollo-router/src/plugins/fleet_detector.rs +++ b/apollo-router/src/plugins/fleet_detector.rs @@ -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::().unwrap() / b.parse::().unwrap() + match readings.split_once(' ') { + None => system_cpus, + Some((quota, period)) => { + calculate_cpu_count_with_default(system_cpus, quota, period) + } + } } } Err(_) => system_cpus, @@ -224,7 +228,7 @@ fn detect_cpu_count(system: &System) -> u64 { if quota == "-1" { system_cpus } else { - quota.parse::().unwrap() / period.parse::().unwrap() + calculate_cpu_count_with_default(system_cpus, "a, &period) } } _ => system_cpus, @@ -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::(), period.parse::()) { + q / p + } else { + default + } +} + fn get_otel_arch() -> &'static str { match ARCH { "x86_64" => "amd64",