Skip to content
Open
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 @@ -252,14 +252,37 @@ public static ContainerInfo parse(final String cgroupsContent) throws ParseExcep
containerInfo.setPodId(cGroupInfo.getPodId());
}

if (cGroupInfo.getContainerId() != null) {
containerInfo.setContainerId(cGroupInfo.getContainerId());
}
replaceContainerIdIfBetter(containerInfo, cGroupInfo);
}

return containerInfo;
}

/**
* Keeps the best available container id candidate across cgroup lines.
*
* <p>Some environments expose both detailed cgroup-v1 controller paths and a cgroup-v2 membership
* path (0::...) where the tail can be task-level and less specific.
*/
private static void replaceContainerIdIfBetter(
ContainerInfo currentContainerInfo, CGroupInfo candidate) {
String candidateContainerId = candidate.getContainerId();
if (candidateContainerId == null) return;

String currentContainerId = currentContainerInfo.getContainerId();
if (currentContainerId != null
&& currentContainerId.matches(CONTAINER_REGEX)
&& candidateContainerId.matches(TASK_REGEX)
&& currentContainerInfo.getPodId() != null
&& candidate.getPodId() == null) {
// Do not replace a pod-scoped container id with a task-scoped id from a less specific path.
// This protects hybrid cgroup output where trailing 0:: lines contain only task ids.
return;
}

currentContainerInfo.setContainerId(candidateContainerId);
}

static CGroupInfo parseLine(final String line) throws ParseException {
final Matcher matcher = LINE_PATTERN.matcher(line);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ class ContainerInfoTest extends DDSpecification {
2:memory:/ecs/55091c13-b8cf-4801-b527-f4601742204d/432624d2150b349fe35ba397284dea788c2bf66b885d14dfc1569b01890ca7da
1:name=systemd:/ecs/34dc0b5e626f2c5c4c5170e34b10e765-1234567890"""

// EKS Fargate cgroup with trailing cgroup v2 membership entry (0::...)
"cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc" | "defa568d-ff14-43d9-9a63-9e39ee9b39b4" | 13 | """12:misc:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
11:cpuset:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
10:perf_event:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
9:blkio:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
8:net_cls,net_prio:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
7:memory:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
6:cpu,cpuacct:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
5:pids:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
4:devices:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
3:hugetlb:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
2:freezer:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
1:name=systemd:/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393/kubepods/burstable/poddefa568d-ff14-43d9-9a63-9e39ee9b39b4/cf1241bbf80ea91eebdd28bf719057380997ca4b0cea16869393b905fb6d52bc
0::/ecs/545b896a072744d186c7fb09a45ec172/545b896a072744d186c7fb09a45ec172-3057940393"""

// PCF file
"6f265890-5165-7fab-6b52-18d1" | null | 12 | """12:rdma:/
11:net_cls,net_prio:/garden/6f265890-5165-7fab-6b52-18d1
Expand Down
Loading