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

add host.id to resource auto-detection #3812

Merged
merged 12 commits into from
Mar 21, 2023

Conversation

mwear
Copy link
Member

@mwear mwear commented Feb 27, 2023

This PR adds host id detection support for non-containerized hosts. The implementation is based on this spec pr: open-telemetry/opentelemetry-specification#3173.

Fixes #3811

Summary

  • This PR introduces a hostIDReader interface with platform specific implementations for Darwin, Linux, BSD, Windows and a fallback for unsupported platfoms.
  • The platform specific implementations use unprivileged means to lookup the host.id, aka machine id for non-containerized environments. Depending on platform this involves reading files in well known locations, excuting shell commands, or a combination of the two.
  • I followed the code organization used for the OS Description Detector, which also has platform specific implementations, however, there is one notable difference. Currently the Go SDK divides platform specific code into darwin, unix, and windows and the associated build tags for those platforms. Host id detection is more granular and requires dividing unix into linux and BSD.

See also

I realize we will want to see the spec PR merge before getting too serious about this work, but I wanted to get some eyes on the approach and encourage anyone with opinions to provide feedback here and on the spec PR.

CHANGELOG.md Outdated Show resolved Hide resolved
sdk/resource/config.go Outdated Show resolved Hide resolved
sdk/resource/host_id_linux.go Outdated Show resolved Hide resolved
sdk/resource/host_id_unsupported.go Outdated Show resolved Hide resolved
sdk/resource/host_id_unsupported.go Show resolved Hide resolved
sdk/resource/resource_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 1, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@1eab60f). Click here to learn what that means.
The diff coverage is 74.0%.

❗ Current head 6df6880 differs from pull request most recent head 3230472. Consider uploading reports for the commit 3230472 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             main   #3812   +/-   ##
======================================
  Coverage        ?   81.5%           
======================================
  Files           ?     170           
  Lines           ?   12765           
  Branches        ?       0           
======================================
  Hits            ?   10415           
  Misses          ?    2131           
  Partials        ?     219           
Impacted Files Coverage Δ
sdk/resource/host_id.go 73.0% <73.0%> (ø)
sdk/resource/config.go 100.0% <100.0%> (ø)

sdk/resource/export_test.go Outdated Show resolved Hide resolved
sdk/resource/host_id.go Outdated Show resolved Hide resolved
sdk/resource/host_id_bsd.go Outdated Show resolved Hide resolved
sdk/resource/host_id_bsd_test.go Outdated Show resolved Hide resolved
@mwear mwear force-pushed the detect_host_id branch 3 times, most recently from 4eb70b5 to a154c62 Compare March 7, 2023 23:28
sdk/resource/resource_test.go Show resolved Hide resolved
@@ -71,6 +71,11 @@ func WithHost() Option {
return WithDetectors(host{})
}

// WithHostID adds host ID information to the configured resource.
func WithHostID() Option {
return WithDetectors(hostIDDetector{})
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we add hostIDDetector to WithHost()? We might consider adding WithHostName to offer a resource detector that only sets host.name resource attribute.

Copy link
Member Author

@mwear mwear Mar 8, 2023

Choose a reason for hiding this comment

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

Because the rules for detecting HostID are different for containerized vs non-containerized hosts I didn't want to couple the hostIDDetector to WithHost, although I had considered it. My thoughts were that someone who wanted to use WithHost on a cloud provider wouldn't have to worry about detector order when detecting HostID. However, I could see having WithHost that detects HostID and HostName, and separate options WithHostID and WithHostName to collect the attributes individually. Let me know what your preference is.

Copy link
Member

@pellared pellared Mar 9, 2023

Choose a reason for hiding this comment

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

EDIT: After second thought, I have no strong preference. Maybe we should improve the docs and list all the attributes that given detector (option) should set? This could be addressed in a separate issue as I feel this is a problem not only for this detector/option.

@mwear
Copy link
Member Author

mwear commented Mar 20, 2023

I wanted to check in to see if there is anything that anyone would like to see addressed in this PR?

@MadVikingGod MadVikingGod merged commit 282a47e into open-telemetry:main Mar 21, 2023
@XSAM XSAM added this to the Old Untracked PRs milestone Nov 7, 2024
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.

host.id resource auto-detection
5 participants