Skip to content

Commit

Permalink
Fixing a bug around identify cgroup v1 correctly (#504)
Browse files Browse the repository at this point in the history
Co-authored-by: Sundaram Ananthanarayanan <[email protected]>
  • Loading branch information
sundargates and sundargates authored Aug 1, 2023
1 parent 8cdf526 commit 24bb3de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -120,12 +122,16 @@ private static long convertStringToLong(String strval) {
}
}

private static final Set<String> knownSubsystems =
new HashSet<>(Arrays.asList("cpu", "cpuacct", "cpuset", "memory"));

private List<String> getSubsystems() {
return
Arrays.asList(Objects.requireNonNull(Paths.get(path).toFile().listFiles()))
.stream()
.filter(s -> s.isDirectory())
.map(s -> s.getName())
.filter(s -> knownSubsystems.contains(s))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.mantisrx.server.agent.metrics.cgroups;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import io.mantisrx.shaded.com.google.common.collect.ImmutableMap;
import io.mantisrx.shaded.com.google.common.io.Resources;
Expand All @@ -33,6 +34,7 @@ public void testReadingStatFiles() throws IOException {
assertEquals(
ImmutableMap.of("user", 49692738L, "system", 4700825L),
cgroup.getStats("cpuacct", "cpuacct.stat"));
assertTrue(cgroup.isV1());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.mantisrx.server.agent.metrics.cgroups;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -55,6 +56,7 @@ public void testWhenCgroupsReturnsCorrectData() throws Exception {
public void testCgroupsV2() throws IOException {
final Cgroup cgroupv2 =
new CgroupImpl(Resources.getResource("example2").getPath());
assertFalse(cgroupv2.isV1());

final CpuAcctsSubsystemProcess process = new CpuAcctsSubsystemProcess(cgroupv2);
final Usage.UsageBuilder usageBuilder = Usage.builder();
Expand Down

0 comments on commit 24bb3de

Please sign in to comment.