diff --git a/containermetadata/containermetadata.go b/containermetadata/containermetadata.go index 486955c..6d66c73 100644 --- a/containermetadata/containermetadata.go +++ b/containermetadata/containermetadata.go @@ -88,7 +88,9 @@ var ( dockerBuildkitPattern = regexp.MustCompile(`\d+:.*:/.*/*docker/buildkit/([0-9a-z]+)`) lxcPattern = regexp.MustCompile(`\d+::/lxc\.(monitor|payload)\.([a-zA-Z]+)/`) containerdPattern = regexp.MustCompile(`\d+:.+:/([a-zA-Z0-9_-]+)/+([a-zA-Z0-9_-]+)`) - defaultPattern = regexp.MustCompile(`^.*/(?:.*[-:])?([0-9a-f]+)(?:\.|\s*$)`) + // The inner container ID pattern is extracted from: + // https://github.com/DataDog/datadog-agent/blob/6e43db2/pkg/util/cgroups/reader.go#L24C24-L24C90 + defaultPattern = regexp.MustCompile(`^.*/(?:.*[-:])?([0-9a-f]{64})|([0-9a-f]{32}-\\d+)|([0-9a-f]{8}(-[0-9a-f]{4}){4}$)(?:\.|\s*$)`) containerIDPattern = regexp.MustCompile(`.+://([0-9a-f]{64})`) diff --git a/containermetadata/containermetadata_test.go b/containermetadata/containermetadata_test.go index 7568677..2948a2a 100644 --- a/containermetadata/containermetadata_test.go +++ b/containermetadata/containermetadata_test.go @@ -151,6 +151,12 @@ func TestExtractContainerIDFromFile(t *testing.T) { containerdClient: &containerd.Client{}, }, }, + { + name: "systemd", + cgroupname: "testdata/cgroupv1systemd", + expContainerID: "", + expEnv: envUndefined, + }, } defaultHandler := &containerMetadataProvider{ diff --git a/containermetadata/testdata/cgroupv1systemd b/containermetadata/testdata/cgroupv1systemd new file mode 100644 index 0000000..9bb9f2a --- /dev/null +++ b/containermetadata/testdata/cgroupv1systemd @@ -0,0 +1,14 @@ +13:devices:/system.slice/dd.taskapi.service +12:pids:/system.slice/dd.taskapi.service +11:cpu,cpuacct:/system.slice/dd.taskapi.service +10:cpuset:/ +9:memory:/system.slice/dd.taskapi.service +8:rdma:/ +7:freezer:/ +6:misc:/ +5:hugetlb:/ +4:blkio:/system.slice/dd.taskapi.service +3:perf_event:/ +2:net_cls,net_prio:/ +1:name=systemd:/system.slice/dd.taskapi.service +0::/system.slice/dd.taskapi.service