Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[resourcedetectionprocessor] Add docker detector #2775

Merged
merged 8 commits into from
May 13, 2021

Conversation

mx-psi
Copy link
Member

@mx-psi mx-psi commented Mar 19, 2021

Description:

  • Add Docker detector

Link to tracking Issue: Fixes #2773

Testing: Amended unit tests. Tested on Ubuntu 18.04 (you need to add -v /var/run/docker.sock:/var/run/docker.sock).

Documentation: Documented on README

@codecov
Copy link

codecov bot commented Mar 19, 2021

Codecov Report

Merging #2775 (ebc2ed6) into main (80eb4fc) will decrease coverage by 0.04%.
The diff coverage is 60.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2775      +/-   ##
==========================================
- Coverage   91.61%   91.56%   -0.05%     
==========================================
  Files         486      488       +2     
  Lines       23540    23568      +28     
==========================================
+ Hits        21565    21581      +16     
- Misses       1465     1473       +8     
- Partials      510      514       +4     
Flag Coverage Δ
integration 63.09% <ø> (-0.27%) ⬇️
unit 90.57% <60.60%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...urcedetectionprocessor/internal/system/metadata.go 0.00% <0.00%> (-57.15%) ⬇️
...sourcedetectionprocessor/internal/docker/docker.go 46.66% <46.66%> (ø)
...urcedetectionprocessor/internal/docker/metadata.go 69.23% <69.23%> (ø)
...cedetectionprocessor/internal/resourcedetection.go 97.22% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80eb4fc...ebc2ed6. Read the comment docs.

@mx-psi mx-psi marked this pull request as ready for review March 19, 2021 17:12
@mx-psi mx-psi requested review from anuraaga and jrcamp as code owners March 19, 2021 17:12
@mx-psi mx-psi requested a review from a team March 19, 2021 17:12
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Mar 27, 2021
@mx-psi
Copy link
Member Author

mx-psi commented Mar 29, 2021

@kbrockhoff can you take a look? Happy to try to improve test coverage after I have a review on the overall idea

@github-actions github-actions bot removed the Stale label Mar 30, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2021

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@mx-psi
Copy link
Member Author

mx-psi commented Apr 16, 2021

@kbrockhoff Friendly ping!

Also @anuraaga @jrcamp I would be happy if you took a look :)

@bogdandrutu
Copy link
Member

@jrcamp please review :)

@jrcamp jrcamp assigned jrcamp and unassigned kbrockhoff Apr 19, 2021
@@ -17,6 +17,8 @@ details of which are currently pending confirmation in the OpenTelemetry specifi
* host.name
* os.type

If running the Collector Docker image, mount `/var/run/docker.sock` and set the `use_docker_sock` flag to `true` to retrieve the attributes from the host machine. Docker detection does not work on macOS.
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda feel like it should be its own detector (you called it out as a possibility in the original issue). Was there any reason you decided not to go that route?

Copy link
Member Author

Choose a reason for hiding this comment

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

Was there any reason you decided not to go that route?

The main reasons were that

  1. it felt like the Docker/bare system detectors should evolve together and provide the same attributes when technically feasible: we get the same attributes today and if e.g. someone wants to add the host.arch attribute when running the Collector binary it makes sense that they would also want it when running on Docker.
  2. the system detector should work regardless of how the Collector is ran: from a user's POV it should make no difference if they are running the Collector from a bare binary or a containerized version.

But as I wrote, I can definitely see it being its own detector, specially if we think they might end up diverging in some way (e.g. we want to add a docker.version attribute or some other attribute that only makes sense on Docker). We have to have a use_docker_sock flag anyway so it's not going to make the user experience much worse and it is more flexible

Copy link
Member Author

Choose a reason for hiding this comment

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

@jrcamp I thought about this a bit more, and while I think the arguments above make sense, I think it's likely that these detector end up diverging so I separated it, PTAL

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 27, 2021
@mx-psi mx-psi changed the title Detect host.name and os.type on system detector when running on Docker [resourcedetectionprocessor] Add docker detector Apr 27, 2021
@mx-psi mx-psi requested a review from jrcamp April 27, 2021 11:07
@tigrannajaryan
Copy link
Member

@anuraaga @jrcamp please review.


* Docker metadata: Queries the Docker daemon to retrieve the following resource attributes from the host machine:

* host.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you describe the difference between retrieving these with normal means? I'm surprised we need to use the docker API to get simple looking attributes.

Maybe it's to retrieve the information about the host, not the docker container. If so, this seems wrong, I believe our semantic conventions intend these to be filled for the current process, which would be using the values from within the docker container, not the host machine. I'd expect us to define new conventions in the spec, something like containerhost.host.name, containerhost.os.type for things outside the process.

Sorry if I'm missing something

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I was expecting this PR to implement container attributes

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/container.md#container

Surprised to see host.name and os.type in the docker detector :)

Copy link
Member Author

@mx-psi mx-psi May 6, 2021

Choose a reason for hiding this comment

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

Can you describe the difference between retrieving these with normal means? I'm surprised we need to use the docker API to get simple looking attributes.

Here is the output of the hostname command and the Name field from the Docker API info endpoint from an Ubuntu Docker image running on an Ubuntu VM:

❯ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -it ubuntu bash
root@3d639eae3af3:/# apt-get update && apt-get install -y curl jq
# ...
root@3d639eae3af3:/# hostname
3d639eae3af3
root@3d639eae3af3:/# curl --silent --unix-socket /var/run/docker.sock http://localhost/info | jq .Name
"ubuntu-vm"

hostname gives you the os.Hostname (which is a random string on Docker). The Docker API gives you the name of the host machine (on Linux and Windows).

Similarly, the os.type will give you the host OS type (so, e.g., windows even if your container is Linux-based).

I'd expect us to define new conventions in the spec, something like containerhost.host.name, containerhost.os.type for things outside the process.

I can definitely do that, but I fail to see why someone would care about the Docker hostname: the whole point (at least to me) of running the Collector as a Docker image is to not have other stuff running in the same Docker image so the useful info is the one about the host where the Docker image is running.

Also I was expecting this PR to implement container attributes

👍 will do

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks for the explanation, that's the opposite behavior of what I was expecting for os.type, surprised native calls within the container don't return information about the container :O And populating something other than the random string seems good.

Just curious, do you know how common it is to have the docker API exposed? For example, will kubernetes users generally be able to use the detector?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just curious, do you know how common it is to have the docker API exposed? For example, will kubernetes users generally be able to use the detector?

I don't know about Kubernetes specifically, I would expect that people have to mount the Unix socket manually. We use this on our Datadog Agent for users running Docker by itself, but we have a different solution for Kubernetes.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

I think we can add further container attributes in a future PR now I understand that this is important for correctly populating those existing ones


* Docker metadata: Queries the Docker daemon to retrieve the following resource attributes from the host machine:

* host.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks for the explanation, that's the opposite behavior of what I was expecting for os.type, surprised native calls within the container don't return information about the container :O And populating something other than the random string seems good.

Just curious, do you know how common it is to have the docker API exposed? For example, will kubernetes users generally be able to use the detector?

@bogdandrutu
Copy link
Member

Please rebase, codecov should not run :)

@bogdandrutu
Copy link
Member

@jrcamp if you have any other comment please open an issue.

@bogdandrutu bogdandrutu merged commit a7a9ead into open-telemetry:main May 13, 2021
@mx-psi mx-psi deleted the mx-psi/system-docker branch May 14, 2021 07:33
@mx-psi
Copy link
Member Author

mx-psi commented May 14, 2021

Sorry, I was out yesterday and didn't see this, happy to see there was no problem with the merge

alexperez52 referenced this pull request in open-o11y/opentelemetry-collector-contrib Aug 18, 2021
* Add a host wrapper  to improve ReportFatalError msg

* Adding host wrapper when starting pipeline

* Do not allocate in the loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System resource detection on containerized Collector
6 participants