Skip to content

Commit

Permalink
add k8s.container.status.state metric
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Jan 22, 2025
1 parent 2eb5802 commit 726203e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .chloggen/container-status.yaml
Original file line number Diff line number Diff line change
@@ -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: new_component

# 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: "Add k8s.container.status.state"

# 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: [1672]

# (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:
29 changes: 29 additions & 0 deletions docs/attributes-registry/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Kubernetes resource attributes.
| <a id="k8s-cluster-name" href="#k8s-cluster-name">`k8s.cluster.name`</a> | string | The name of the cluster. | `opentelemetry-cluster` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-cluster-uid" href="#k8s-cluster-uid">`k8s.cluster.uid`</a> | string | A pseudo-ID for the cluster, set to the UID of the `kube-system` namespace. [1] | `218fc5a9-a5f1-4b54-aa05-46717d0ab26d` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-container-name" href="#k8s-container-name">`k8s.container.name`</a> | string | The name of the Container from Pod specification, must be unique within a Pod. Container runtime usually uses different globally unique name (`container.name`). | `redis` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-container-reason" href="#k8s-container-reason">`k8s.container.reason`</a> | string | The reason for the container state. | `ContainerCreating`; `CrashLoopBackOff`; `CreateContainerConfigError`; `ErrImagePull`; `ImagePullBackOff`; `OOMKilled`; `Completed`; `Error`; `ContainerCannotRun` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-container-restart-count" href="#k8s-container-restart-count">`k8s.container.restart_count`</a> | int | Number of times the container was restarted. This attribute can be used to identify a particular container (running or stopped) within a container spec. | | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-container-state" href="#k8s-container-state">`k8s.container.state`</a> | string | The state of the container. | `terminated`; `running`; `waiting` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-container-status-last-terminated-reason" href="#k8s-container-status-last-terminated-reason">`k8s.container.status.last_terminated_reason`</a> | string | Last terminated reason of the Container. | `Evicted`; `Error` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-cronjob-name" href="#k8s-cronjob-name">`k8s.cronjob.name`</a> | string | The name of the CronJob. | `opentelemetry` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| <a id="k8s-cronjob-uid" href="#k8s-cronjob-uid">`k8s.cronjob.uid`</a> | string | The UID of the CronJob. | `275ecb36-5aa8-4c2a-9c47-d8bb681b9aff` | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
Expand Down Expand Up @@ -71,6 +73,33 @@ conflict.

---

`k8s.container.reason` has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

| Value | Description | Stability |
|---|---|---|
| `` | Reason unknown. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `Completed` | The container has completed execution. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `ContainerCannotRun` | The container cannot run. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `ContainerCreating` | The container is being created. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `CrashLoopBackOff` | The container is in a crash loop back off state. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `CreateContainerConfigError` | There was an error creating the container configuration. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `ErrImagePull` | There was an error pulling the container image. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `Error` | There was an error with the container. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `ImagePullBackOff` | The container image pull is in back off state. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `OOMKilled` | The container was killed due to out of memory. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |

---

`k8s.container.state` has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

| Value | Description | Stability |
|---|---|---|
| `running` | The container is running. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `terminated` | The container has terminated. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |
| `waiting` | The container is waiting. | ![Experimental](https://img.shields.io/badge/-experimental-blue) |

---

`k8s.namespace.phase` has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

| Value | Description | Stability |
Expand Down
15 changes: 15 additions & 0 deletions model/k8s/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ groups:
- ref: network.interface.name
- ref: network.io.direction

# k8s.container.* metrics
- id: metric.k8s.container.status.state
type: metric
metric_name: k8s.container.status.state
stability: experimental
brief: ""
instrument: updowncounter
unit: ""
attributes:
- ref: k8s.container.state
requirement_level: required
- ref: k8s.container.reason
requirement_level: required


# k8s.node.* metrics
- id: metric.k8s.node.uptime
type: metric
Expand Down
66 changes: 66 additions & 0 deletions model/k8s/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,69 @@ groups:
value: 'terminating'
brief: "Terminating namespace phase as described by [K8s API](https://pkg.go.dev/k8s.io/[email protected]/core/v1#NamespacePhase)"
stability: experimental
- id: k8s.container.state
stability: experimental
brief: >
The state of the container.
type:
members:
- id: terminated
value: 'terminated'
brief: 'The container has terminated.'
stability: experimental
- id: running
value: 'running'
brief: 'The container is running.'
stability: experimental
- id: waiting
value: 'waiting'
brief: 'The container is waiting.'
stability: experimental
examples: ['terminated', 'running', 'waiting']
- id: k8s.container.reason
type:
members:
- id: container_creating
value: 'ContainerCreating'
brief: 'The container is being created.'
stability: experimental
- id: crash_loop_back_off
value: 'CrashLoopBackOff'
brief: 'The container is in a crash loop back off state.'
stability: experimental
- id: create_container_config_error
value: 'CreateContainerConfigError'
brief: 'There was an error creating the container configuration.'
stability: experimental
- id: err_image_pull
value: 'ErrImagePull'
brief: 'There was an error pulling the container image.'
stability: experimental
- id: image_pull_back_off
value: 'ImagePullBackOff'
brief: 'The container image pull is in back off state.'
stability: experimental
- id: oom_killed
value: 'OOMKilled'
brief: 'The container was killed due to out of memory.'
stability: experimental
- id: completed
value: 'Completed'
brief: 'The container has completed execution.'
stability: experimental
- id: error
value: 'Error'
brief: 'There was an error with the container.'
stability: experimental
- id: container_cannot_run
value: 'ContainerCannotRun'
brief: 'The container cannot run.'
stability: experimental
- id: empty
value: ''
brief: 'Reason unknown.'
stability: experimental
stability: experimental
brief: >
The reason for the container state.
examples: ['ContainerCreating', 'CrashLoopBackOff', 'CreateContainerConfigError', 'ErrImagePull', 'ImagePullBackOff', 'OOMKilled', 'Completed', 'Error', 'ContainerCannotRun']

0 comments on commit 726203e

Please sign in to comment.