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

GCE to also get hostname #511

Closed
nhamlh opened this issue Oct 12, 2022 · 14 comments · Fixed by #669
Closed

GCE to also get hostname #511

nhamlh opened this issue Oct 12, 2022 · 14 comments · Fixed by #669
Assignees
Labels
enhancement accepted An actionable enhancement for which PRs will be accepted enhancement New feature or request priority: p2

Comments

@nhamlh
Copy link

nhamlh commented Oct 12, 2022

For our usecase, we're running on GKE and would love to also have hostname of GCE requested and populated to otel-collector. Currently, the HostName returns InstanceName instead of hostname:

// GCEHostName returns the instance name of the instance on which this program is running
func (d *Detector) GCEHostName() (string, error) {
return d.metadata.InstanceName()
}

I just wonder if there's any reason blocking adding it? If not, I can open a PR for this.

@dashpole
Copy link
Contributor

That seems reasonable to me. Feel free to add it as GCEHostHostname or GCEHostname. As a note, GCE attributes are not accessible on GKE if you are using workload identity (or autopilot, which uses workload identity).

@dashpole dashpole added the enhancement New feature or request label Oct 12, 2022
@dashpole
Copy link
Contributor

In the collector, we need to make sure failure to obtain this information does not cause resource detection to fail entirely.

@nhamlh
Copy link
Author

nhamlh commented Oct 13, 2022

@dashpole as a side note, should we deprecate GCEHostName and change the name to GCEInstanceName? IMO, it'll avoid ambiguous; however this change will break downsteam project.

@dashpole
Copy link
Contributor

dashpole commented Oct 13, 2022

I just realized they changed the host name attributes recently: open-telemetry/opentelemetry-specification#838. It appears we can only have either the name of the host, or the hostname of the instance as a semantic convention.

I assume hostname and instance name are generally significantly different?

@nhamlh
Copy link
Author

nhamlh commented Oct 14, 2022

In this case I think they are not that much of the difference. Actually, exposing GCE hostname would leave users with a more flexible of choices: while GCE on GKE expose hostname instead of instance name, users can use gcp detector to get the hostname, or system detector to get instance name.

In resourcedetection processor we can add a fallback from instance name to hostname, wdyt?

@dashpole
Copy link
Contributor

WDYM about the system detector getting the instance name? I wouldn't expect the system detector to use the GCE metadata server.

The instance name is critical when running on GCE, though... I think we need to find another place to put it before replacing it with hostname.

@nhamlh
Copy link
Author

nhamlh commented Oct 17, 2022

The system detector doesn't use GCE metadata server, it picks the hostname locally if used with hostname_sources: ["os"] which is actually the instance.name metadata. So users can choose to use system detector or gcp detector's fqdn hostname for host.name, that's the flexible I mentioned before.

@mx-psi
Copy link

mx-psi commented Oct 19, 2022

As a note, GCE attributes are not accessible on GKE if you are using workload identity (or autopilot, which uses workload identity).

In this case, wouldn't we be able to get the cluster node name through the API server? AFAIK, instance/name returns the Kubernetes node name on GKE (when not using workload identity).

So users can choose to use system detector or gcp detector's fqdn hostname for host.name, that's the flexible I mentioned before.

Changing the host.name value would break some of our (Datadog) supported setups. I would suggest having GCP-specific attributes such as gcp.instance.name or gcp.instance.hostname to avoid breakage. I think this could be even eventually added at the OpenTelemetry specification.

@aabmass
Copy link
Contributor

aabmass commented Feb 13, 2023

Thanks for the PR @nhamlh. We'll try to get this reviewed and merged soon

@aabmass aabmass added the enhancement accepted An actionable enhancement for which PRs will be accepted label Feb 13, 2023
@dashpole
Copy link
Contributor

I agree with mx-psi above. I would prefer to see this added to the specification before adding it to the resource detector.

@damemi damemi self-assigned this Apr 11, 2023
@damemi
Copy link
Contributor

damemi commented Apr 12, 2023

To summarize, we can't change the value of host.name in the collector because that would be breaking. But, we can add 2 new gcp specific labels gcp.instance.name and gcp.instance.hostname in the resource detection processor.

The change in #515 alone won't break anything, because that's just adding the new method to the detector. For that reason, I think we could go ahead and merge #515 without any spec changes, but adding the new labels by default in the collector processor should have the spec change first. Does that sound right to everyone?

@damemi
Copy link
Contributor

damemi commented Apr 12, 2023

Opened open-telemetry/opentelemetry-specification#3384 upstream to add gcp.gce.instance.name and gcp.gce.instance.hostname

@damemi
Copy link
Contributor

damemi commented Jun 1, 2023

With open-telemetry/semantic-conventions#15 merged, we will be using the 2 new attributes mentioned above (once a new semconv release is published)

@nhamlh, are you still interested in working on #515 ?

@damemi
Copy link
Contributor

damemi commented Jul 10, 2023

Opened #669

TylerHelmuth pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this issue Aug 4, 2023
… instance name/hostname (#24598)

**Description:** 
This uses new detector functions from
GoogleCloudPlatform/opentelemetry-operations-go#669
to update the GCP resource detector to add new GCE-specific attributes
for hostname and instance name. These attributes are meant to more
clearly express their intent in specific context to GCE. See
https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/cloud-provider/gcp/gce.md

**Link to tracking Issue:**
GoogleCloudPlatform/opentelemetry-operations-go#511

**Testing:** unit tests updated, plus downstream unit and integration
tests

**Documentation:** matches semantic conventions

---------

Co-authored-by: David Ashpole <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement accepted An actionable enhancement for which PRs will be accepted enhancement New feature or request priority: p2
Projects
None yet
5 participants