Skip to content

[processor/resourcedetection] k8snode detector queries K8s API for k8s.node.uid when the resource label is disabled #31941

@avanish-vaghela

Description

@avanish-vaghela

Component(s)

processor/resourcedetection

What happened?

Description

When you configure the K8snode detector to

  • get the node name from an existing variable such as MY_NODE_NAME and
  • disable the k8s.node.uid resource label and
  • disable the k8snode auth by setting auth_type to none
    the k8snode still calls the K8s API to get the K8s node UID, resulting in a resource detection error

This is a bug in the K8s node detector where even if you disable the K8s node uid label it will still query the k8s API.

Steps to Reproduce

Expected Result

k8snode detector should be able to set the k8s.node.name value from a given environment variable without having to call the K8s API and it should not call the K8s APIs to get the k8s.node.uid when it has been explicitly disabled.

Actual Result

2024-03-25T18:42:26.207519786Z 2024-03-25T18:42:26.207Z	warn	internal/resourcedetection.go:130	failed to detect resource	{"kind": "processor", "name": "resourcedetection", "pipeline": "metrics/splunk", "error": "failed getting k8s node UID: failed to fetch node with name sv2-rkeworkervm3-1a-lab from K8s API: Unauthorized"}

Adding a conditional logic around this line should address the issue.

Collector version

0.96.0

Environment information

Environment

OS: Linux
Env: K8s

OpenTelemetry Collector configuration

resourcedetection:
      detectors: [env, k8snode]
      timeout: 2s
      override: false
      k8snode:
        node_from_env_var: MY_NODE_NAME
        auth_type: none
        resource_attributes:
          k8s.node.uid:
            enabled: false

Log output

2024-03-25T18:42:26.207519786Z 2024-03-25T18:42:26.207Z	warn	internal/resourcedetection.go:130	failed to detect resource	{"kind": "processor", "name": "resourcedetection", "pipeline": "metrics/splunk", "error": "failed getting k8s node UID: failed to fetch node with name kv2-workervm3-1a-lab from K8s API: Unauthorized"}

Additional context

Code where detection happens without attributes enablement check. https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourcedetectionprocessor/internal/k8snode/k8snode.go#L51

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions