Skip to content

Commit

Permalink
Fix Datadog-Entity-ID detection paths joining (#6864)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygree committed Apr 2, 2024
1 parent a18c05c commit ab1bf09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static boolean isHostCgroupNamespace() {
for (String controller : Arrays.asList(CGROUPV1_BASE_CONTROLLER, CGROUPV2_BASE_CONTROLLER)) {
for (CGroupInfo cgroup : cgroups) {
if (cgroup.getControllers().contains(controller)) {
Path path = cgroupMountPath.resolve(controller).resolve(cgroup.getPath());
Path path = Paths.get(cgroupMountPath.toString(), controller, cgroup.getPath());
long inode = readInode(path);
// ignore invalid and root inode
if (inode > 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,24 @@ class ContainerInfoTest extends DDSpecification {
Arrays.asList("memory") | true
Arrays.asList("") | false
}

def "readEntityID return id-<ino> for a parent when path is /"() {
setup:
File mountPath = File.createTempDir("container-info-test-", "-sys-fs-cgroup")
mountPath.deleteOnExit()
File memoryController = Files.createDirectory(mountPath.toPath().resolve("memory")).toFile()
memoryController.deleteOnExit()
Long ino = readInode(memoryController.toPath())

when:
ContainerInfo containerInfo = new ContainerInfo()
ContainerInfo.CGroupInfo cGroupInfo = new ContainerInfo.CGroupInfo()
cGroupInfo.setControllers(Arrays.asList("memory"))
cGroupInfo.setPath("/")
List<ContainerInfo.CGroupInfo> cGroups = Arrays.asList(cGroupInfo)
containerInfo.setcGroups(cGroups)

then:
containerInfo.readEntityID(containerInfo, false, mountPath.toPath()) == "in-" + ino
}
}

0 comments on commit ab1bf09

Please sign in to comment.