Skip to content

handle .scope postfix when parsing cgroup #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public String readContainerId() {
try (BufferedReader br = new BufferedReader(new FileReader(cgroupsPath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.endsWith(".scope")) {
line = line.substring(0, line.length() - ".scope".length());
}
if (line.length() > CONTAINER_ID_LENGTH) {
String id = line.substring(line.length() - CONTAINER_ID_LENGTH);
if (!id.contains("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ void readContainerId(@TempDir File tempFolder) throws IOException {
CgroupsReader cgroupsReader = new CgroupsReader(file.getPath());
Assertions.assertEquals(expected, cgroupsReader.readContainerId());
}

@Test
void readScopedContainerId(@TempDir File tempFolder) throws IOException {
File file = new File(tempFolder, "cgroup");
String expected = "736665661f3cf3ec691b2feeb2a1ec78918c0ef65381160bbb04f4c298169679";
String content =
"1:name=systemd:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podab2df320_6a91_4bc7_bd18_0d4328f04a8f.slice/crio-736665661f3cf3ec691b2feeb2a1ec78918c0ef65381160bbb04f4c298169679.scope";
Files.write(content.getBytes(Charsets.UTF_8), file);

CgroupsReader cgroupsReader = new CgroupsReader(file.getPath());
Assertions.assertEquals(expected, cgroupsReader.readContainerId());
}
}