@@ -119,20 +119,17 @@ func (c *cache) getContainerIDFromCache(pid uint64) (string, bool) {
119
119
}
120
120
121
121
func (c * cache ) getGetContainerIDFromPID (pid uint64 ) (string , error ) {
122
- p , ok := instance .containerIDCache . Load (pid )
122
+ containerID , ok := instance .getContainerIDFromCache (pid )
123
123
if ok {
124
- containerID , ok := p .(string )
125
- if ok {
126
- return containerID , nil
127
- }
124
+ return containerID , nil
128
125
}
129
126
130
127
path , err := getPathFromPID (procPath , pid )
131
128
if err != nil {
132
129
return utils .SystemProcessName , err
133
130
}
134
131
135
- containerID , err := extractPodContainerIDfromPath (path )
132
+ containerID , err = extractPodContainerIDfromPathWithCgroup (path )
136
133
if err != nil {
137
134
return utils .SystemProcessName , err
138
135
}
@@ -152,7 +149,7 @@ func (c *cache) getContainerIDFromcGroupID(cGroupID uint64) (string, error) {
152
149
return utils .SystemProcessName , err
153
150
}
154
151
155
- containerID , err := extractPodContainerIDfromPath (path )
152
+ containerID , err := extractPodContainerIDfromPathWithCgroup (path )
156
153
if err != nil {
157
154
return utils .SystemProcessName , err
158
155
}
@@ -180,20 +177,24 @@ func (c *cache) getPathFromcGroupID(cgroupID uint64) (string, error) {
180
177
if err != nil {
181
178
return fmt .Errorf ("error resolving handle: %w" , err )
182
179
}
180
+ // found a path and load into cache.
183
181
instance .cGroupIDToPath .Store (getCgroupID , path )
184
182
return nil
185
183
})
186
184
185
+ // if error is not nil
187
186
if err != nil {
188
187
return unknownPath , fmt .Errorf ("failed to find cgroup id: %v" , err )
189
188
}
190
-
189
+ // if path found and load from cache.
191
190
p , ok = instance .cGroupIDToPath .Load (cgroupID )
192
191
if ok {
193
192
return p .(string ), nil
194
193
}
195
-
194
+ // if error is nil, but path not found
195
+ // add mapping in cache
196
196
instance .cGroupIDToPath .Store (cgroupID , unknownPath )
197
+ // return
197
198
return unknownPath , nil
198
199
}
199
200
@@ -291,11 +292,6 @@ func getContainerIDFromPath(cGroupID, pid uint64, withCGroupID bool) (string, er
291
292
return instance .getGetContainerIDFromPID (pid )
292
293
}
293
294
294
- // extractPodContainerIDfromPath extracts the container ID from the provided cgroup path
295
- func extractPodContainerIDfromPath (path string ) (string , error ) {
296
- return extractPodContainerIDfromPathWithCgroup (path )
297
- }
298
-
299
295
// extractPodContainerIDfromPathWithCgroup extracts the container ID from a cgroup path
300
296
func extractPodContainerIDfromPathWithCgroup (path string ) (string , error ) {
301
297
if path == unknownPath {
0 commit comments