Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add container id support to Resource #2418

Merged
merged 16 commits into from
Mar 3, 2022

Conversation

XSAM
Copy link
Member

@XSAM XSAM commented Nov 26, 2021

@codecov
Copy link

codecov bot commented Nov 26, 2021

Codecov Report

Merging #2418 (15b4fc7) into main (0d0a732) will increase coverage by 0.0%.
The diff coverage is 93.3%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2418   +/-   ##
=====================================
  Coverage   75.7%   75.8%           
=====================================
  Files        172     173    +1     
  Lines      11619   11664   +45     
=====================================
+ Hits        8800    8842   +42     
- Misses      2609    2612    +3     
  Partials     210     210           
Impacted Files Coverage Δ
sdk/resource/container.go 92.3% <92.3%> (ø)
sdk/resource/config.go 100.0% <100.0%> (ø)

@jcchavezs
Copy link
Contributor

I was checking this PR, I was wondering if the approach I took in https://github.com/hypertrace/goagent/blob/main/sdk/internal/container/container.go was simpler or am I missing something. I also wonder, do we want an integration test like https://github.com/hypertrace/goagent/tree/main/tests/docker. I could port it here @XSAM

@XSAM
Copy link
Member Author

XSAM commented Dec 3, 2021

I was wondering if the approach I took in https://github.com/hypertrace/goagent/blob/main/sdk/internal/container/container.go was simpler or am I missing something.

This test case shows a cgroup line may contain the prefix and the suffix.

name: "with prefix and suffix",
line: "13:name=systemd:/podruntime/docker/kubepods/crio-dc679f8a8319c8cf7d38e1adf263bc08d23.stuff",
expectedContainerID: "dc679f8a8319c8cf7d38e1adf263bc08d23",

Also, here is an example of the cgroup string that is fetched from my Kubernetes cluster. You can see the cgroup string becomes complicated.

2:cpuset:/kubepods/besteffort/podbd31ef54-609d-44dd-85f8-12014a486358/a4a47304716dc887fc6c8e389bfd32c0f98f3571d41d220e43dbc6d0eec67182

I also wonder, do we want an integration test like https://github.com/hypertrace/goagent/tree/main/tests/docker.

Good point. I also wonder about this. To achieve this integration test, we need container runtime. It means to run the tests, it requires all contributors to install a container runtime. It also increases the dependence on this project. Not sure it is worth doing that. Any thoughts? @open-telemetry/go-approvers

@XSAM
Copy link
Member Author

XSAM commented Dec 3, 2021

BTW, I found the approach of this PR is not working for cgroup v2. In cgroup v2, we only get little info from the cgroup file.

For instance,

0::/

sdk/resource/container.go Outdated Show resolved Hide resolved
@jcchavezs
Copy link
Contributor

jcchavezs commented Dec 9, 2021 via email

@seh
Copy link
Contributor

seh commented Dec 9, 2021

Are you targeting a concrete case?

Are you asking me? If so, I'm telegraphing the conversation from today's Go SIG meeting—a conversation that I started. There will be other interpretation of what "a container's ID" is or what it means. I don't know what they are. I know enough to doubt the universality of this particular choice.

@MadVikingGod MadVikingGod self-requested a review December 13, 2021 16:37
@MadVikingGod
Copy link
Contributor

So I approved this with my understanding at the time that both cgroups were made in a response to containers, and that the current Linux runtimes, that I know of, all use cgroups under the hood to manage containers.

While both the OCI, and the CRI require a container ID, neither specifies that you must use cgroups to do so. I don't know if there is an implementation counter to this, but I will admit I haven't checked all of them.

With that in mind, these would be my recommendations:

  • Remove defaultContainerIDProvider. You can still have this setup if needed for testing, but it shouldn't be default, instead, there should be the option for many different detectors.
  • containerIDDetector should have cgroup in the name. It uses cgroups to find the containerID

@XSAM
Copy link
Member Author

XSAM commented Jan 5, 2022

FYI, I created a comment on OCI spec looking for an official/stable way to fetch container id within the container.

@XSAM
Copy link
Member Author

XSAM commented Feb 7, 2022

looking for an official/stable way to fetch container id within the container.

This should be a long-term direction and not block this PR.

@XSAM
Copy link
Member Author

XSAM commented Feb 23, 2022

I believe this PR is ready for review.

@XSAM XSAM requested a review from hanyuancheung as a code owner February 28, 2022 04:12
sdk/resource/container.go Outdated Show resolved Hide resolved
sdk/resource/process_test.go Show resolved Hide resolved
Copy link
Member

@hanyuancheung hanyuancheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

sdk/resource/container.go Outdated Show resolved Hide resolved
sdk/resource/container.go Outdated Show resolved Hide resolved
sdk/resource/resource_test.go Outdated Show resolved Hide resolved
XSAM and others added 2 commits March 3, 2022 18:37
Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
@Aneurysm9 Aneurysm9 merged commit f4ec95d into open-telemetry:main Mar 3, 2022
@XSAM XSAM deleted the container-id-resource branch March 4, 2022 01:15
hanyuancheung added a commit to hanyuancheung/opentelemetry-go that referenced this pull request Mar 5, 2022
* Add container id support to Resource

* Fix wrong test case name

* Add WithContainer option

* Update CHANGELOG

* Fix comments

* Update CHANGELOG

* Use regex to find container id

* Add tests for reading cgroup file

* Update sdk/resource/container.go

Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>

* Update format

Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
@MrAlias MrAlias added this to the Release v1.5.0 milestone Mar 15, 2022
@MrAlias MrAlias mentioned this pull request Mar 15, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container Resource MetaData auto detection in Resource SDK
8 participants