@@ -35,7 +35,7 @@ describe('docker', () => {
35
35
`1:name=systemd:/docker/${ id } `
36
36
] . join ( '\n' )
37
37
38
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
38
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
39
39
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
40
40
docker . inject ( carrier )
41
41
@@ -49,7 +49,7 @@ describe('docker', () => {
49
49
`1:name=systemd:/uuid/${ id } `
50
50
] . join ( '\n' )
51
51
52
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
52
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
53
53
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
54
54
docker . inject ( carrier )
55
55
@@ -63,7 +63,7 @@ describe('docker', () => {
63
63
`1:name=systemd:/ecs/${ id } `
64
64
] . join ( '\n' )
65
65
66
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
66
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
67
67
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
68
68
docker . inject ( carrier )
69
69
@@ -77,7 +77,7 @@ describe('docker', () => {
77
77
`1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod2d3da189_6407_48e3_9ab6_78188d75e609.slice/docker-${ id } .scope` // eslint-disable-line @stylistic/js/max-len
78
78
] . join ( '\n' )
79
79
80
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
80
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
81
81
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
82
82
docker . inject ( carrier )
83
83
@@ -93,7 +93,7 @@ describe('docker', () => {
93
93
'3:cpu:/invalid'
94
94
] . join ( '\n' )
95
95
96
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
96
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
97
97
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
98
98
docker . inject ( carrier )
99
99
@@ -107,7 +107,7 @@ describe('docker', () => {
107
107
`0::/docker/${ id } `
108
108
] . join ( '\n' )
109
109
110
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
110
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
111
111
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
112
112
docker . inject ( carrier )
113
113
@@ -121,7 +121,7 @@ describe('docker', () => {
121
121
`1:name=systemd:/system.slice/garden.service/garden/${ id } `
122
122
] . join ( '\n' )
123
123
124
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
124
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
125
125
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
126
126
docker . inject ( carrier )
127
127
@@ -135,7 +135,7 @@ describe('docker', () => {
135
135
'1:name=systemd:/system.slice/garden.service/garden/'
136
136
] . join ( '\n' )
137
137
138
- fs . readFileSync . withArgs ( '/proc/self/cgroup' ) . returns ( Buffer . from ( cgroup ) )
138
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
139
139
fs . statSync . withArgs ( '/sys/fs/cgroup/system.slice/garden.service/garden' ) . returns ( { ino } )
140
140
docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
141
141
docker . inject ( carrier )
@@ -144,6 +144,22 @@ describe('docker', () => {
144
144
expect ( carrier [ 'Datadog-Entity-ID' ] ) . to . equal ( `in-${ ino } ` )
145
145
} )
146
146
147
+ it ( 'should support inode when the ID is not available (any line)' , ( ) => {
148
+ const ino = 1234
149
+ const cgroup = [
150
+ '1:name=systemd:/' ,
151
+ '0::/'
152
+ ] . join ( '\n' )
153
+
154
+ fs . readFileSync . withArgs ( '/proc/self/cgroup' , 'utf8' ) . returns ( cgroup )
155
+ fs . statSync . withArgs ( '/sys/fs/cgroup/' ) . returns ( { ino } )
156
+ docker = proxyquire ( '../src/exporters/common/docker' , { fs } )
157
+ docker . inject ( carrier )
158
+
159
+ expect ( carrier [ 'Datadog-Container-Id' ] ) . to . be . undefined
160
+ expect ( carrier [ 'Datadog-Entity-ID' ] ) . to . equal ( `in-${ ino } ` )
161
+ } )
162
+
147
163
it ( 'should support external env' , ( ) => {
148
164
process . env . DD_EXTERNAL_ENV = 'test'
149
165
0 commit comments