From 5abb2e3c0ed334ebc4ea245e74fea616f26c9b73 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Wed, 30 Apr 2025 16:51:30 +0200 Subject: [PATCH] [k8s] Introduce semantic conventions for k8s Deployment labels and annotations (#2168) Signed-off-by: odubajDT --- .chloggen/deployments-labels-annotations.yaml | 22 +++++++ docs/attributes-registry/k8s.md | 58 ++++++++++--------- docs/resource/k8s.md | 6 ++ model/k8s/registry.yaml | 16 +++++ model/k8s/resources.yaml | 4 ++ 5 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 .chloggen/deployments-labels-annotations.yaml diff --git a/.chloggen/deployments-labels-annotations.yaml b/.chloggen/deployments-labels-annotations.yaml new file mode 100644 index 000000000..154a9ad75 --- /dev/null +++ b/.chloggen/deployments-labels-annotations.yaml @@ -0,0 +1,22 @@ +# Use this changelog template to create an entry for release notes. +# +# If your change doesn't affect end users you should instead start +# your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db) +component: k8s + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Introduce semantic conventions for k8s Deployment labels and annotations" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +# The values here must be integers. +issues: [2134] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/docs/attributes-registry/k8s.md b/docs/attributes-registry/k8s.md index 60ad07406..362a83eb4 100644 --- a/docs/attributes-registry/k8s.md +++ b/docs/attributes-registry/k8s.md @@ -23,36 +23,38 @@ Kubernetes resource attributes. | `k8s.cronjob.uid` | string | The UID of the CronJob. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.daemonset.name` | string | The name of the DaemonSet. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.daemonset.uid` | string | The UID of the DaemonSet. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.deployment.annotation.` | string | The annotation key-value pairs placed on the Deployment. [4] | `k8s.deployment.annotation.replicas=1`; `k8s.deployment.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.deployment.label.` | string | The label key-value pairs placed on the Deployment. [5] | `k8s.deployment.label.app=guestbook`; `k8s.deployment.label.injected=` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.deployment.name` | string | The name of the Deployment. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.deployment.uid` | string | The UID of the Deployment. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.hpa.name` | string | The name of the horizontal pod autoscaler. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.hpa.uid` | string | The UID of the horizontal pod autoscaler. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.job.annotation.` | string | The annotation key-value pairs placed on the Job. [4] | `k8s.job.annotation.number=1`; `k8s.job.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.job.label.` | string | The label key-value pairs placed on the Job. [5] | `k8s.job.label.jobtype=ci`; `k8s.job.label.automated=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.job.annotation.` | string | The annotation key-value pairs placed on the Job. [6] | `k8s.job.annotation.number=1`; `k8s.job.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.job.label.` | string | The label key-value pairs placed on the Job. [7] | `k8s.job.label.jobtype=ci`; `k8s.job.label.automated=` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.job.name` | string | The name of the Job. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.job.uid` | string | The UID of the Job. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.namespace.annotation.` | string | The annotation key-value pairs placed on the Namespace. [6] | `k8s.namespace.annotation.ttl=0`; `k8s.namespace.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.namespace.label.` | string | The label key-value pairs placed on the Namespace. [7] | `k8s.namespace.label.kubernetes.io/metadata.name=default`; `k8s.namespace.label.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.namespace.annotation.` | string | The annotation key-value pairs placed on the Namespace. [8] | `k8s.namespace.annotation.ttl=0`; `k8s.namespace.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.namespace.label.` | string | The label key-value pairs placed on the Namespace. [9] | `k8s.namespace.label.kubernetes.io/metadata.name=default`; `k8s.namespace.label.data=` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.namespace.name` | string | The name of the namespace that the pod is running in. | `default` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.namespace.phase` | string | The phase of the K8s namespace. [8] | `active`; `terminating` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.node.annotation.` | string | The annotation placed on the Node, the `` being the annotation name, the value being the annotation value, even if the value is empty. [9] | `0`; `` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.node.label.` | string | The label placed on the Node, the `` being the label name, the value being the label value, even if the value is empty. [10] | `arm64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.namespace.phase` | string | The phase of the K8s namespace. [10] | `active`; `terminating` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.node.annotation.` | string | The annotation placed on the Node, the `` being the annotation name, the value being the annotation value, even if the value is empty. [11] | `0`; `` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.node.label.` | string | The label placed on the Node, the `` being the label name, the value being the label value, even if the value is empty. [12] | `arm64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.node.name` | string | The name of the Node. | `node-1` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.node.uid` | string | The UID of the Node. | `1eb3a0c6-0477-4080-a9cb-0cb7db65c6a2` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.pod.annotation.` | string | The annotation placed on the Pod, the `` being the annotation name, the value being the annotation value. [11] | `true`; `x64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.pod.label.` | string | The label placed on the Pod, the `` being the label name, the value being the label value. [12] | `my-app`; `x64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.pod.annotation.` | string | The annotation placed on the Pod, the `` being the annotation name, the value being the annotation value. [13] | `true`; `x64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.pod.label.` | string | The label placed on the Pod, the `` being the label name, the value being the label value. [14] | `my-app`; `x64`; `` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.pod.name` | string | The name of the Pod. | `opentelemetry-pod-autoconf` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.pod.uid` | string | The UID of the Pod. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.replicaset.annotation.` | string | The annotation key-value pairs placed on the ReplicaSet. [13] | `k8s.replicaset.annotation.replicas=0`; `k8s.replicaset.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.replicaset.label.` | string | The label key-value pairs placed on the ReplicaSet. [14] | `k8s.replicaset.label.app=guestbook`; `k8s.replicaset.label.injected=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.replicaset.annotation.` | string | The annotation key-value pairs placed on the ReplicaSet. [15] | `k8s.replicaset.annotation.replicas=0`; `k8s.replicaset.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.replicaset.label.` | string | The label key-value pairs placed on the ReplicaSet. [16] | `k8s.replicaset.label.app=guestbook`; `k8s.replicaset.label.injected=` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.replicaset.name` | string | The name of the ReplicaSet. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.replicaset.uid` | string | The UID of the ReplicaSet. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.replicationcontroller.name` | string | The name of the replication controller. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.replicationcontroller.uid` | string | The UID of the replication controller. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.resourcequota.name` | string | The name of the resource quota. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.resourcequota.uid` | string | The UID of the resource quota. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.statefulset.annotation.` | string | The annotation key-value pairs placed on the StatefulSet. [15] | `k8s.statefulset.annotation.replicas=1`; `k8s.statefulset.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | -| `k8s.statefulset.label.` | string | The label key-value pairs placed on the StatefulSet. [16] | `k8s.statefulset.label.app=guestbook`; `k8s.statefulset.label.injected=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.statefulset.annotation.` | string | The annotation key-value pairs placed on the StatefulSet. [17] | `k8s.statefulset.annotation.replicas=1`; `k8s.statefulset.annotation.data=` | ![Development](https://img.shields.io/badge/-development-blue) | +| `k8s.statefulset.label.` | string | The label key-value pairs placed on the StatefulSet. [18] | `k8s.statefulset.label.app=guestbook`; `k8s.statefulset.label.injected=` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.statefulset.name` | string | The name of the StatefulSet. | `opentelemetry` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.statefulset.uid` | string | The UID of the StatefulSet. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Development](https://img.shields.io/badge/-development-blue) | | `k8s.volume.name` | string | The name of the K8s volume. | `volume0` | ![Development](https://img.shields.io/badge/-development-blue) | @@ -95,32 +97,36 @@ conflict. - A label `automated` with empty string value SHOULD be recorded as the `k8s.cronjob.label.automated` attribute with value `""`. -**[4] `k8s.job.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. +**[4] `k8s.deployment.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. -**[5] `k8s.job.label`:** The `` being the label name, the value being the label value, even if the value is empty. +**[5] `k8s.deployment.label`:** The `` being the label name, the value being the label value, even if the value is empty. -**[6] `k8s.namespace.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. +**[6] `k8s.job.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. -**[7] `k8s.namespace.label`:** The `` being the label name, the value being the label value, even if the value is empty. +**[7] `k8s.job.label`:** The `` being the label name, the value being the label value, even if the value is empty. -**[8] `k8s.namespace.phase`:** This attribute aligns with the `phase` field of the +**[8] `k8s.namespace.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. + +**[9] `k8s.namespace.label`:** The `` being the label name, the value being the label value, even if the value is empty. + +**[10] `k8s.namespace.phase`:** This attribute aligns with the `phase` field of the [K8s NamespaceStatus](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#namespacestatus-v1-core) -**[9] `k8s.node.annotation`:** Examples: +**[11] `k8s.node.annotation`:** Examples: - An annotation `node.alpha.kubernetes.io/ttl` with value `0` SHOULD be recorded as the `k8s.node.annotation.node.alpha.kubernetes.io/ttl` attribute with value `"0"`. - An annotation `data` with empty string value SHOULD be recorded as the `k8s.node.annotation.data` attribute with value `""`. -**[10] `k8s.node.label`:** Examples: +**[12] `k8s.node.label`:** Examples: - A label `kubernetes.io/arch` with value `arm64` SHOULD be recorded as the `k8s.node.label.kubernetes.io/arch` attribute with value `"arm64"`. - A label `data` with empty string value SHOULD be recorded as the `k8s.node.label.data` attribute with value `""`. -**[11] `k8s.pod.annotation`:** Examples: +**[13] `k8s.pod.annotation`:** Examples: - An annotation `kubernetes.io/enforce-mountable-secrets` with value `true` SHOULD be recorded as the `k8s.pod.annotation.kubernetes.io/enforce-mountable-secrets` attribute with value `"true"`. @@ -129,7 +135,7 @@ conflict. - An annotation `data` with empty string value SHOULD be recorded as the `k8s.pod.annotation.data` attribute with value `""`. -**[12] `k8s.pod.label`:** Examples: +**[14] `k8s.pod.label`:** Examples: - A label `app` with value `my-app` SHOULD be recorded as the `k8s.pod.label.app` attribute with value `"my-app"`. @@ -138,13 +144,13 @@ conflict. - A label `data` with empty string value SHOULD be recorded as the `k8s.pod.label.data` attribute with value `""`. -**[13] `k8s.replicaset.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. +**[15] `k8s.replicaset.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. -**[14] `k8s.replicaset.label`:** The `` being the label name, the value being the label value, even if the value is empty. +**[16] `k8s.replicaset.label`:** The `` being the label name, the value being the label value, even if the value is empty. -**[15] `k8s.statefulset.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. +**[17] `k8s.statefulset.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. -**[16] `k8s.statefulset.label`:** The `` being the label name, the value being the label value, even if the value is empty. +**[18] `k8s.statefulset.label`:** The `` being the label name, the value being the label value, even if the value is empty. --- diff --git a/docs/resource/k8s.md b/docs/resource/k8s.md index 3900410e6..bd3783804 100644 --- a/docs/resource/k8s.md +++ b/docs/resource/k8s.md @@ -279,6 +279,12 @@ distributed among the nodes of a cluster. |---|---|---|---|---|---| | [`k8s.deployment.name`](/docs/attributes-registry/k8s.md) | string | The name of the Deployment. | `opentelemetry` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) | | [`k8s.deployment.uid`](/docs/attributes-registry/k8s.md) | string | The UID of the Deployment. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) | +| [`k8s.deployment.annotation.`](/docs/attributes-registry/k8s.md) | string | The annotation key-value pairs placed on the Deployment. [1] | `k8s.deployment.annotation.replicas=1`; `k8s.deployment.annotation.data=` | `Opt-In` | ![Development](https://img.shields.io/badge/-development-blue) | +| [`k8s.deployment.label.`](/docs/attributes-registry/k8s.md) | string | The label key-value pairs placed on the Deployment. [2] | `k8s.deployment.label.app=guestbook`; `k8s.deployment.label.injected=` | `Opt-In` | ![Development](https://img.shields.io/badge/-development-blue) | + +**[1] `k8s.deployment.annotation`:** The `` being the annotation name, the value being the annotation value, even if the value is empty. + +**[2] `k8s.deployment.label`:** The `` being the label name, the value being the label value, even if the value is empty. diff --git a/model/k8s/registry.yaml b/model/k8s/registry.yaml index 2938c0f8e..9759b8b7a 100644 --- a/model/k8s/registry.yaml +++ b/model/k8s/registry.yaml @@ -229,6 +229,22 @@ groups: brief: > The name of the Deployment. examples: ['opentelemetry'] + - id: k8s.deployment.label + type: template[string] + stability: development + brief: > + The label key-value pairs placed on the Deployment. + note: | + The `` being the label name, the value being the label value, even if the value is empty. + examples: ['k8s.deployment.label.app=guestbook', 'k8s.deployment.label.injected='] + - id: k8s.deployment.annotation + type: template[string] + stability: development + brief: > + The annotation key-value pairs placed on the Deployment. + note: | + The `` being the annotation name, the value being the annotation value, even if the value is empty. + examples: [ 'k8s.deployment.annotation.replicas=1', 'k8s.deployment.annotation.data=' ] - id: k8s.statefulset.uid type: string stability: development diff --git a/model/k8s/resources.yaml b/model/k8s/resources.yaml index 63dad0bed..65e2b7412 100644 --- a/model/k8s/resources.yaml +++ b/model/k8s/resources.yaml @@ -84,6 +84,10 @@ groups: attributes: - ref: k8s.deployment.uid - ref: k8s.deployment.name + - ref: k8s.deployment.label + requirement_level: opt_in + - ref: k8s.deployment.annotation + requirement_level: opt_in - id: resource.k8s.statefulset type: resource