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

Fix empty host.id #4317

Merged
merged 6 commits into from
Jul 18, 2023
Merged

Fix empty host.id #4317

merged 6 commits into from
Jul 18, 2023

Conversation

mwear
Copy link
Member

@mwear mwear commented Jul 14, 2023

Fixes #4312.

When reading a non-existent file, readFile was returning "", nil instead of "", err resulting in an empty host id. The original intent was to return an error in this case, but this will make the example in #4312 (pasted below) panic:

package main

import (
	"context"
	"fmt"

	"go.opentelemetry.io/otel/sdk/resource"
)

func main() {
	res, err := resource.New(context.Background(),
		resource.WithHostID(),
	)

	if err != nil {
		panic(err)
	}

	fmt.Println(res)
}

In a containerized environment, it's very likely that HostID detection will fail. That calls into question how we should handle this case. Should the hostIDDetector ignore errors and return an empty resource, or should it propagate the error (as per the original intent)? There is a similar detector in JS, but they work a little differently than the ones in the Go SDK. The HostDetector detects all host.* attributes. It will omit host.id if it's not found, but return the other found attributes in a new resource. I think the Go SDK equivalent would be to make the hostIDDetector a best-effort detector, and return an empty resource if it fails. Do any other detectors do this? Does anyone have thoughts or opinions? (cc: @mx-psi)

@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Merging #4317 (a7369a3) into main (f6a658c) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4317   +/-   ##
=====================================
  Coverage   83.4%   83.5%           
=====================================
  Files        184     184           
  Lines      14350   14350           
=====================================
+ Hits       11975   11983    +8     
+ Misses      2149    2141    -8     
  Partials     226     226           
Impacted Files Coverage Δ
sdk/resource/host_id_readfile.go 100.0% <100.0%> (+100.0%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Should there be a test for this?

Copy link
Member

@mx-psi mx-psi 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 this is a net improvement, we can continue discussing what the behavior should actually be in a containerized setup separately.

To me silently failing sounds like "there is no valid host.id on this setup". This is not necessarily the case if we fail to read the files specified on the spec, since host.id could also be a cloud provider ID (e.g. AWS EC2 instance id). But I don't have context on what other detectors do to have a strong opinion here.

@pellared
Copy link
Member

I think this is a net improvement, we can continue discussing what the behavior should actually be in a containerized setup separately.

To me silently failing sounds like "there is no valid host.id on this setup". This is not necessarily the case if we fail to read the files specified on the spec, since host.id could also be a cloud provider ID (e.g. AWS EC2 instance id). But I don't have context on what other detectors do to have a strong opinion here.

This PR fixes the bug. There should be a new issue (enhancement) that should be about providing a host.id value for the mentioned use cases.

@mwear
Copy link
Member Author

mwear commented Jul 17, 2023

Should there be a test for this?

readFile ends up getting mocked in all of the higher level tests. I can specifically add tests for the readFile function. Let me know if you'd like me to go that route.

@mwear
Copy link
Member Author

mwear commented Jul 17, 2023

Since readFile does not get exercised in normal tests due to mocking, I went ahead and added a couple of tests for it.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

LGTM with the suggested CHANGELOG fix applied.

MrAlias and others added 2 commits July 18, 2023 07:43
@pellared pellared merged commit 9b0c4d2 into open-telemetry:main Jul 18, 2023
@MrAlias MrAlias added this to the v1.17.0 milestone Aug 3, 2023
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 is set to empty value in containerized setups
6 participants