File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
main/java/org/hypertrace/agent/otel/extensions
test/java/org/hypertrace/agent/otel/extensions Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ public String readContainerId() {
5151 try (BufferedReader br = new BufferedReader (new FileReader (cgroupsPath ))) {
5252 String line ;
5353 while ((line = br .readLine ()) != null ) {
54+ if (line .endsWith (".scope" )) {
55+ line = line .substring (0 , line .length () - ".scope" .length ());
56+ }
5457 if (line .length () > CONTAINER_ID_LENGTH ) {
5558 String id = line .substring (line .length () - CONTAINER_ID_LENGTH );
5659 if (!id .contains ("/" )) {
Original file line number Diff line number Diff line change @@ -42,4 +42,16 @@ void readContainerId(@TempDir File tempFolder) throws IOException {
4242 CgroupsReader cgroupsReader = new CgroupsReader (file .getPath ());
4343 Assertions .assertEquals (expected , cgroupsReader .readContainerId ());
4444 }
45+
46+ @ Test
47+ void readScopedContainerId (@ TempDir File tempFolder ) throws IOException {
48+ File file = new File (tempFolder , "cgroup" );
49+ String expected = "736665661f3cf3ec691b2feeb2a1ec78918c0ef65381160bbb04f4c298169679" ;
50+ String content =
51+ "1:name=systemd:/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-podab2df320_6a91_4bc7_bd18_0d4328f04a8f.slice/crio-736665661f3cf3ec691b2feeb2a1ec78918c0ef65381160bbb04f4c298169679.scope" ;
52+ Files .write (content .getBytes (Charsets .UTF_8 ), file );
53+
54+ CgroupsReader cgroupsReader = new CgroupsReader (file .getPath ());
55+ Assertions .assertEquals (expected , cgroupsReader .readContainerId ());
56+ }
4557}
You can’t perform that action at this time.
0 commit comments