[CONTINT-1132] Send in-<inode> using the cgroup controller when container-id cannot be retrieved#232
Merged
Merged
Conversation
AliDatadog
force-pushed
the
ali/inode-cid-resolver
branch
4 times, most recently
from
January 12, 2024 10:30
5950a63 to
a773124
Compare
AliDatadog
force-pushed
the
ali/inode-cid-resolver
branch
from
January 12, 2024 11:21
a773124 to
73bf9fb
Compare
vickenty
reviewed
Jan 12, 2024
| } | ||
|
|
||
| /** | ||
| * Parses `path` (=/proc/self/cgroup) and returns the container ID if available. |
Contributor
There was a problem hiding this comment.
This comment doesn't seem to match what the method is doing.
| * the container ID. | ||
| * | ||
| */ | ||
| if ((containerID == null || containerID.equals("")) && !isHostCgroupNamespace(CGROUP_NS_PATH)) { |
Contributor
There was a problem hiding this comment.
Can you please add a comment explaining why we exclude isHostCgroupNamespace(CGROUP_NS_PATH) case?
| if (tokens.length != 3) { | ||
| continue; | ||
| } | ||
| if (CGROUPV1_BASE_CONTROLLER.equals(tokens[1]) || tokens[1].isEmpty()) { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (CGROUPV1_BASE_CONTROLLER.equals(tokens[1]) || tokens[1].isEmpty()) { | |
| if (CGROUPV1_BASE_CONTROLLER.equals(tokens[1]) || | |
| CGROUPV2_BASE_CONTROLLER.equals(tokens[1])) { |
| // Docker | ||
| String docker = new StringBuilder() | ||
| .append("13:name=systemd:/docker/3726184226f5d3147c25fdeab5b60097e378e8a720503a5e19ecfdf29f869860\n") | ||
| .append("12:pids:/docker/3726184226f5d3147c25fdeab5b60097e378e8a720503a5e19ecfdf29f869860\n") |
Contributor
There was a problem hiding this comment.
Please don't reformat the code that you didn't modify.
…UPV2_BASE_CONTROLLER
AliDatadog
force-pushed
the
ali/inode-cid-resolver
branch
from
January 16, 2024 14:05
f5229f5 to
c15f5f4
Compare
vickenty
approved these changes
Jan 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation of DataDog/datadog-go#291 but in Java
This Pull Request implements the support of Origin Detection when the container-id is unavailable from inside the application container only with cgroupv2.
It first retrieves the cgroup node path by parsing proc/self/cgroup which is formatted differently depending on the cgroup version. See https://man7.org/linux/man-pages/man7/cgroups.7.html.
The format is a list of hierarchy-ID:controller-list:cgroup-path similar to:
0::
1:name=systemd:... // only in cgroupv1
Once the path is retrieved, we retrieve the inode of /sys/fs/cgroup + + where is the path retrieved previously.
I am not sure how to create a dummy app that uses this library.
Test
dummy.metricis correctly tagged with container-id when it wasn't before.If you are curious about the dummy app, I pushed it here https://github.com/AliDatadog/dummy-dsd-java-app.