open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.09k stars 2.38k forks source link

[processor/resourcedetection]: Add support for k8s.cluster.name for local clusters #35116

Open MichaelKatsoulis opened 2 months ago

MichaelKatsoulis commented 2 months ago

Component(s)

processor/k8sattributes

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

When running Otel collector and resourcedetection processor in a local Kubernetes cluster created by kind, minikube or kube-adm there is no way currently to get the Kubernetes cluster name. These clusters are used very often for development, testing but also in production.

Describe the solution you'd like

Clusters created by kind, minikube and kube-adm produce a configmap in kube-system namespace called kubeadm-config. This looks like this and contains the cluster name.

apiVersion: v1
data:
  ClusterConfiguration: |
    apiServer:
      certSANs:
      - localhost
      - 127.0.0.1
      extraArgs:
        authorization-mode: Node,RBAC
        runtime-config: ""
      timeoutForControlPlane: 4m0s
    apiVersion: kubeadm.k8s.io/v1beta3
    certificatesDir: /etc/kubernetes/pki
    clusterName: kind
    controlPlaneEndpoint: kind-control-plane:6443

Describe alternatives you've considered

No response

Additional context

No response

github-actions[bot] commented 2 months ago

Pinging code owners:

dashpole commented 2 months ago

This seems reasonable. I would consider this a new "kubeadm" resource detector. Are there any other resource attribute it could detect?

odubajDT commented 1 month ago

Hello, I would like to take this issue if possible

ChrsMark commented 1 month ago

Thank's @odubajDT, I have assigned this to you.

ChrsMark commented 1 month ago

This seems reasonable. I would consider this a new "kubeadm" resource detector. Are there any other resource attribute it could detect?

There is also the k8s.cluster.uid resource attribute which is defined in the current K8s semantic conventions: https://github.com/open-telemetry/semantic-conventions/blob/b780f480e73ffc2d1da117689475b7b9c8af610b/docs/attributes-registry/k8s.md?plain=1#L19

Maybe that would also make sense to be included in this detector?

dashpole commented 1 month ago

Maybe that would also make sense to be included in this detector?

I would omit that here, and recommend users use the k8sattributes processor, which detects that by default: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/k8sattributesprocessor/README.md#configuration