@@ -76,6 +76,8 @@ public String getContainerID() throws IOException {
7676 * not running in a container or running is private cgroup namespace, we
7777 * fallback to the cgroup controller inode. The agent (7.51+) will use it to get
7878 * the container ID.
79+ * In Host cgroup namespace, the container ID should be found. If it is not
80+ * found, it means that the application is running on a host/vm.
7981 *
8082 */
8183 if ((containerID == null || containerID .equals ("" )) && !isHostCgroupNamespace (CGROUP_NS_PATH )) {
@@ -85,7 +87,7 @@ public String getContainerID() throws IOException {
8587 }
8688
8789 /**
88- * Parses `path` (=/proc/self/cgroup) and returns the container ID if available .
90+ * Returns the content of `path` (=/proc/self/cgroup).
8991 *
9092 * @throws IOException if /proc/self/cgroup is readable and still an I/O error
9193 * occurs reading from the stream.
@@ -100,7 +102,9 @@ private String read(Path path) throws IOException {
100102 }
101103
102104 /**
103- * Parses a Cgroup file content and returns the corresponding container ID.
105+ * Parses a Cgroup file (=/proc/self/cgroup) content and returns the
106+ * corresponding container ID. It can be found only if the container
107+ * is running in host cgroup namespace.
104108 *
105109 * @param cgroupsContent Cgroup file content
106110 */
@@ -165,6 +169,10 @@ public static String getCgroupInode(final Path cgroupMountPath, final String cgr
165169 }
166170 Path path = Paths .get (cgroupMountPath .toString (), controller , cgroupNodePath );
167171 long inode = inodeForPath (path );
172+ /*
173+ * Inode 0 is not a valid inode. Inode 1 is a bad block inode and inode 2 is the
174+ * root of a filesystem. We can safely ignore them.
175+ */
168176 if (inode > 2 ) {
169177 return "in-" + inode ;
170178 }
@@ -188,7 +196,7 @@ public static Map<String, String> parseCgroupNodePath(final String cgroupContent
188196 if (tokens .length != 3 ) {
189197 continue ;
190198 }
191- if (CGROUPV1_BASE_CONTROLLER .equals (tokens [1 ]) || tokens [1 ]. isEmpty ( )) {
199+ if (CGROUPV1_BASE_CONTROLLER .equals (tokens [1 ]) || CGROUPV2_BASE_CONTROLLER . equals ( tokens [1 ])) {
192200 res .put (tokens [1 ], tokens [2 ]);
193201 }
194202 }
0 commit comments