Skip to content

Commit

Permalink
[k8sclusterreceiver] add k8s.pod.qos_class optional resource attribute (
Browse files Browse the repository at this point in the history
open-telemetry#27485)

**Description:** <Describe what has changed.>

add k8s.pod.qos_class optional resource attriute

**Link to tracking Issue:** <Issue number if applicable>

open-telemetry#27483

**Testing:** <Describe what testing was performed and which tests were
added.>
- updated unit tests

**Documentation:** <Describe the documentation added.>

- generated
  • Loading branch information
povilasv authored and JaredTan95 committed Oct 18, 2023
1 parent 99f3758 commit c2a5972
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/k8sclusterreceiver-qos-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: k8sclusterreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "add optional k8s.pod.qos_class resource attribute"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27483]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 1 addition & 0 deletions receiver/k8sclusterreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ Current status reason of the pod (1 - Evicted, 2 - NodeAffinity, 3 - NodeLost, 4
| k8s.node.name | The k8s node name. | Any Str | true |
| k8s.node.uid | The k8s node uid. | Any Str | true |
| k8s.pod.name | The k8s pod name. | Any Str | true |
| k8s.pod.qos_class | The k8s pod qos class name. One of Guaranteed, Burstable, BestEffort. | Any Str | false |
| k8s.pod.uid | The k8s pod uid. | Any Str | true |
| k8s.replicaset.name | The k8s replicaset name | Any Str | true |
| k8s.replicaset.uid | The k8s replicaset uid | Any Str | true |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ all_set:
enabled: true
k8s.pod.name:
enabled: true
k8s.pod.qos_class:
enabled: true
k8s.pod.uid:
enabled: true
k8s.replicaset.name:
Expand Down Expand Up @@ -283,6 +285,8 @@ none_set:
enabled: false
k8s.pod.name:
enabled: false
k8s.pod.qos_class:
enabled: false
k8s.pod.uid:
enabled: false
k8s.replicaset.name:
Expand Down
4 changes: 3 additions & 1 deletion receiver/k8sclusterreceiver/internal/pod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func Transform(pod *corev1.Pod) *corev1.Pod {
NodeName: pod.Spec.NodeName,
},
Status: corev1.PodStatus{
Phase: pod.Status.Phase,
Phase: pod.Status.Phase,
QOSClass: pod.Status.QOSClass,
},
}
for _, cs := range pod.Status.ContainerStatuses {
Expand Down Expand Up @@ -76,6 +77,7 @@ func RecordMetrics(logger *zap.Logger, mb *metadata.MetricsBuilder, pod *corev1.
rb.SetK8sNodeName(pod.Spec.NodeName)
rb.SetK8sPodName(pod.Name)
rb.SetK8sPodUID(string(pod.UID))
rb.SetK8sPodQosClass(string(pod.Status.QOSClass))
mb.EmitForResource(metadata.WithResource(rb.Emit()))

for _, c := range pod.Spec.Containers {
Expand Down
1 change: 1 addition & 0 deletions receiver/k8sclusterreceiver/internal/pod/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestPodStatusReasonAndContainerMetricsReportCPUMetrics(t *testing.T) {

mbc := metadata.DefaultMetricsBuilderConfig()
mbc.Metrics.K8sPodStatusReason.Enabled = true
mbc.ResourceAttributes.K8sPodQosClass.Enabled = true
ts := pcommon.Timestamp(time.Now().UnixNano())
mb := metadata.NewMetricsBuilder(mbc, receivertest.NewNopCreateSettings())
RecordMetrics(zap.NewNop(), mb, pod, ts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ resourceMetrics:
- key: k8s.pod.name
value:
stringValue: test-pod-1
- key: k8s.pod.qos_class
value:
stringValue: BestEffort
- key: k8s.pod.uid
value:
stringValue: test-pod-1-uid
Expand Down
5 changes: 3 additions & 2 deletions receiver/k8sclusterreceiver/internal/testutils/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ func NewPodStatusWithContainer(containerName, containerID string) *corev1.PodSta

func NewEvictedTerminatedPodStatusWithContainer(containerName, containerID string) *corev1.PodStatus {
return &corev1.PodStatus{
Phase: corev1.PodFailed,
Reason: "Evicted",
Phase: corev1.PodFailed,
QOSClass: corev1.PodQOSBestEffort,
Reason: "Evicted",
ContainerStatuses: []corev1.ContainerStatus{
{
Name: containerName,
Expand Down
5 changes: 5 additions & 0 deletions receiver/k8sclusterreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ resource_attributes:
type: string
enabled: true

k8s.pod.qos_class:
description: "The k8s pod qos class name. One of Guaranteed, Burstable, BestEffort."
type: string
enabled: false

k8s.replicaset.name:
description: The k8s replicaset name
type: string
Expand Down

0 comments on commit c2a5972

Please sign in to comment.