Skip to content

Commit

Permalink
FLEET-19 Fix /proc/filesystems query to be more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrainer committed Oct 16, 2024
1 parent c59b24c commit 7e971cf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions apollo-router/src/plugins/fleet_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ fn detect_cpu_count(system: &System) -> u64 {

let system_cpus = system.cpus().len() as u64;
// Grab the contents of /proc/filesystems
let filesystems_file = fs::read_to_string("/proc/filesystems").unwrap();
// Parse the list and only take the first column, filtering to elements that contain
// 'cgroups'
let fses: HashSet<&str> = filesystems_file
.split('\n')
.map(|x| x.split_whitespace().next().unwrap())
.filter(|x| x.contains("cgroup"))
.collect();
let fses: HashSet<&str> = match fs::read_to_string("/proc/filesystems") {
Ok(content) => content
.lines()
.map(|x| x.split_whitespace().next().unwrap_or(""))
.filter(|x| x.contains("cgroup"))
.collect(),
Err(_) => return system_cpus,
};

if fses.contains("cgroup2") {
// If we're looking at cgroup2 then we need to look in `cpu.max`
match fs::read_to_string("/sys/fs/cgroup/cpu.max") {
Ok(readings) => {
// The format of the file lists the quota first, followed by the period,
// but the quote could also be max which would mean there are no restrictions.
// but the quota could also be max which would mean there are no restrictions.
if readings.starts_with("max") {
system_cpus
} else {
Expand Down

0 comments on commit 7e971cf

Please sign in to comment.