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

[exporter/datadog] Kubernetes node name resolution via the downward API #11033

Open
mx-psi opened this issue Jun 14, 2022 · 3 comments
Open

[exporter/datadog] Kubernetes node name resolution via the downward API #11033

mx-psi opened this issue Jun 14, 2022 · 3 comments
Labels
enhancement New feature or request exporter/datadog Datadog components never stale Issues marked with this label will be never staled and automatically removed priority:p3 Lowest

Comments

@mx-psi
Copy link
Member

mx-psi commented Jun 14, 2022

Is your feature request related to a problem? Please describe.

The Datadog exporter needs to query the Kubernetes node name for resolving the hostname (see #10911). The exporter currently relies on the assumption that the pod name can be retrieved by calling os.Hostname, which is not necessarily true if, e.g., the hostname has been modified via fields like setHostnameAsFQDN. In these cases, the Kubernetes source provider will fail.

Describe the solution you'd like

The Datadog exporter Kubernetes source provider supports getting the node name via the downward API or directly from the known environment variables documented in open-telemetry/oteps#195.

Describe alternatives you've considered

There are no alternatives to support these setups, really.

Additional context

Originally mentioned in #10911 (comment)

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Nov 9, 2022
@mx-psi mx-psi removed the Stale label Nov 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Jan 9, 2023
@mx-psi mx-psi added never stale Issues marked with this label will be never staled and automatically removed and removed Stale labels Jan 10, 2023
@ringerc
Copy link

ringerc commented Jan 28, 2024

This should use the downward API to inject both the k8s pod name and the node name into the Pod at DaemonSet level

spec:
  template:
    spec:
      containers:
        - name: opentelemetry-collector
          env:
          - name: K8S_POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: K8S_NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: K8S_NAMESPACE_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          ...

... but preferably adjusted to follow OpenTelemetry semantic conventions for resource environment variables.

The current code at

func (p *nodeNameProviderImpl) NodeName(ctx context.Context) (string, error) {
namespace := p.namespace()
// NOTE: The pod name may not match the OS hostname, e.g. if it has been modified
// via the 'setHostnameAsFQDN' and 'hostname' fields in the pod spec.
// The query below will error out in that case. See:
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/11033
podName, err := os.Hostname()
if err != nil {
return "", fmt.Errorf("could not fetch pod hostname: %w", err)
}
// NOTE: If changing this, check if the RBAC rules on the docs or examples need updates.
pod, err := p.client.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return "", err
}
return pod.Spec.NodeName, nil
}
relies on the assumption that hostname within a pod returns the pod name, which as the comments say isn't always guaranteed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request exporter/datadog Datadog components never stale Issues marked with this label will be never staled and automatically removed priority:p3 Lowest
Projects
None yet
Development

No branches or pull requests

3 participants