Module: Dash0::OpenTelemetry::Resource::KubernetesPod
- Extended by:
- KubernetesPod
- Included in:
- KubernetesPod
- Defined in:
- lib/dash0/opentelemetry/resource/kubernetes_pod.rb
Overview
Resource detector that derives k8s.pod.uid by parsing cgroup files,
gated on an /etc/hosts marker that indicates a Kubernetes-managed
environment. Ported from the Node.js distribution's
opentelemetry-resource-detector-kubernetes-pod.
OpenTelemetry::SDK must be loaded before detect is called.
Constant Summary collapse
- ETC_HOSTS_FILE =
'/etc/hosts'- EXPECTED_FIRST_LINE_IN_ETC_HOSTS =
'# Kubernetes-managed hosts file'- POD_UID_CHARS =
36- POD_LABEL =
'pod'- POD_LABEL_MOUNT_PART =
'/pods/'- POD_UID_PART_CHARS =
"pod" + 36-char uid
POD_UID_CHARS + POD_LABEL.length
- CONTAINER_ID_CHARS =
64- PROC_SELF_MOUNTINFO_FILE =
cgroup v1
'/proc/self/mountinfo'- PROC_SELF_CGROUP_FILE =
cgroup v2
'/proc/self/cgroup'- POD_UID_IN_CGROUP_LINE_REGEX =
Matches slice names like "kubepods-pode462ffed_94ce_4806_a52e_d2726f448f15.slice".
/\A[a-z_-]*pod(?<uid>[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12})\.slice\z/
Instance Method Summary collapse
-
#detect ⇒ Object
The detector interface: the only public method.
Instance Method Details
#detect ⇒ Object
The detector interface: the only public method.
37 38 39 40 41 42 |
# File 'lib/dash0/opentelemetry/resource/kubernetes_pod.rb', line 37 def detect attributes = {} uid = pod_uid attributes['k8s.pod.uid'] = uid if uid ::OpenTelemetry::SDK::Resources::Resource.create(attributes) end |