ProcessManager: Extract containerID with the rest of process metadata#577
ProcessManager: Extract containerID with the rest of process metadata#577christos68k merged 9 commits intomainfrom
Conversation
This is a follow up to #535. While the tracer part of the project reports the cgroup v2 path for each sample, the reporter is expected to report the container ID. The container ID then can be used to associate the sample to more detailed resource information. In the context of OTel collector, the container ID then can be used like this: ``` k8sattributes: auth_type: "serviceAccount" passthrough: false filter: node_from_env_var: KUBERNETES_NODE_NAME extract: metadata: - k8s.pod.name - k8s.pod.uid - k8s.deployment.name - k8s.namespace.name - k8s.node.name - k8s.pod.start_time - service.namespace - service.name - service.version - service.instance.id labels: - tag_name: app.label.component key: app.kubernetes.io/component from: pod otel_annotations: true pod_association: - sources: - from: resource_attribute name: container.id ``` As the cgroupv2 path contains further information, that could be beneficial for other reporters, the extraction of the container ID happens in the reporter. Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
|
Repeating my #548 (comment) here as well: While it seems tempting to move process data extraction to processmanager, it is not the purpose of processmanager in the first place. Therefore, I suggest:
|
florianl
left a comment
There was a problem hiding this comment.
I think, @fabled summarized the situation well in #548 (comment) and so I think, this option is a good interim solution until there is a plugin mechanism to extract such information by configuration.
OK let's close #548, review #577 (I still need to do another pass and test some more) and I'll merge after (I'll also add you as a co-author to the squashed commit). |
|
Closing in favor of #577 |
sry 🙏 |
|
@Anthony-Tafoya can you provide the full cgroupv2 path of one of your containers? You can fetch it from |
|
After taking a further look, this works fine. I was testing on a docker compose setup (so I would not have to deploy every small yaml change). Before I was seeing the login session’s cgroup like /user.slice/user‑1000.slice/session‑1.scope and /../... On my kubernetes cluster this works as expected (grabs the containerID). Apologies for the confusion |
| } | ||
|
|
||
| for _, tc := range tests { | ||
| tc := tc |
There was a problem hiding this comment.
| tc := tc |
| for _, tc := range tests { | ||
| tc := tc | ||
| t.Run(tc.expectedContainerID, func(t *testing.T) { | ||
| reader := bytes.NewReader([]byte(tc.line)) |
There was a problem hiding this comment.
| reader := bytes.NewReader([]byte(tc.line)) | |
| reader := strings.NewReader(tc.line) |
| Set(pre host.FileID, post libpf.FileID) | ||
| } | ||
|
|
||
| func parseContainerID(cgroupFile io.Reader) string { |
There was a problem hiding this comment.
Since the tests only contain cgroupV2 strings, should we document this function to support cgroupV2 only? Otherwise, we should add cgroupV1 test cases.
IMO, we don't need to support for v1.
| scanner.Buffer(buf, 8192) | ||
| var pathParts []string | ||
| for scanner.Scan() { | ||
| line := scanner.Text() |
There was a problem hiding this comment.
Skip regex processing and heap allocations for the very common case of "0::/".
| line := scanner.Text() | |
| b := scanner.Bytes() | |
| if bytes.Equal(b, []byte("0::/")) { | |
| continue // Skip a common case | |
| } | |
| line := string(b) |
rockdaboot
left a comment
There was a problem hiding this comment.
LGTM, just some minor comments

Summary
This is an alternate solution to #548, see here and here for more context.
It includes all the commits that @florianl did in #548 (which is now closed), we can review and merge #577 standalone.