Skip to content

Commit

Permalink
[processor/k8sattributes] add StatefulSet attributes (open-telemetry#…
Browse files Browse the repository at this point in the history
…13125)

Add support for discovering K8S StatefulSet attributes
  • Loading branch information
povilasv authored Aug 9, 2022
1 parent f46d7ad commit 6a9cce7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion processor/k8sattributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ type ExtractConfig struct {
// k8s.node.name, k8s.namespace.name, k8s.pod.start_time,
// k8s.replicaset.name, k8s.replicaset.uid,
// k8s.daemonset.name, k8s.daemonset.uid,
// k8s.job.name, and k8s.job.uid
// k8s.job.name, k8s.job.uid,
// k8s.statefulset.name, and k8s.statefulset.uid
//
// Specifying anything other than these values will result in an error.
// By default all of the fields are extracted and added to spans and metrics.
Expand Down
10 changes: 9 additions & 1 deletion processor/k8sattributesprocessor/internal/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {

if c.Rules.ReplicaSetID || c.Rules.ReplicaSetName ||
c.Rules.DaemonSetUID || c.Rules.DaemonSetName ||
c.Rules.JobUID || c.Rules.JobName {
c.Rules.JobUID || c.Rules.JobName ||
c.Rules.StatefulSetUID || c.Rules.StatefulSetName {
for _, ref := range pod.OwnerReferences {
switch ref.Kind {
case "ReplicaSet":
Expand All @@ -319,6 +320,13 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
if c.Rules.DaemonSetName {
tags[conventions.AttributeK8SDaemonSetName] = ref.Name
}
case "StatefulSet":
if c.Rules.StatefulSetUID {
tags[conventions.AttributeK8SStatefulSetUID] = string(ref.UID)
}
if c.Rules.StatefulSetName {
tags[conventions.AttributeK8SStatefulSetName] = ref.Name
}
case "Job":
if c.Rules.JobUID {
tags[conventions.AttributeK8SJobUID] = string(ref.UID)
Expand Down
22 changes: 22 additions & 0 deletions processor/k8sattributesprocessor/internal/kube/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ func TestExtractionRules(t *testing.T) {
Name: "pi",
UID: "59f27ac1-5c71-42e5-abe9-2c499d603706",
},
{
APIVersion: "apps/v1",
Kind: "StatefulSet",
Name: "pi-statefulset",
UID: "03755eb1-6175-47d5-afd5-05cfc30244d7",
},
},
},
Spec: api_v1.PodSpec{
Expand Down Expand Up @@ -541,6 +547,22 @@ func TestExtractionRules(t *testing.T) {
attributes: map[string]string{
"k8s.job.name": "pi",
},
}, {
name: "statefulsetUID",
rules: ExtractionRules{
StatefulSetUID: true,
},
attributes: map[string]string{
"k8s.statefulset.uid": "03755eb1-6175-47d5-afd5-05cfc30244d7",
},
}, {
name: "jobName",
rules: ExtractionRules{
StatefulSetName: true,
},
attributes: map[string]string{
"k8s.statefulset.name": "pi-statefulset",
},
}, {
name: "metadata",
rules: ExtractionRules{
Expand Down
2 changes: 2 additions & 0 deletions processor/k8sattributesprocessor/internal/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ type ExtractionRules struct {
PodUID bool
ReplicaSetID bool
ReplicaSetName bool
StatefulSetUID bool
StatefulSetName bool
Node bool
StartTime bool
ContainerID bool
Expand Down
4 changes: 4 additions & 0 deletions processor/k8sattributesprocessor/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func withExtractMetadata(fields ...string) option {
p.rules.DaemonSetName = true
case conventions.AttributeK8SDaemonSetUID:
p.rules.DaemonSetUID = true
case conventions.AttributeK8SStatefulSetName:
p.rules.StatefulSetName = true
case conventions.AttributeK8SStatefulSetUID:
p.rules.StatefulSetUID = true
case conventions.AttributeK8SJobName:
p.rules.JobName = true
case conventions.AttributeK8SJobUID:
Expand Down
16 changes: 16 additions & 0 deletions unreleased/k8sattributes-sts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: k8sattributesprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for discovering Kubernetes StatefulSet name and StatefulSet UID"

# One or more tracking issues related to the change
issues: [141]

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

0 comments on commit 6a9cce7

Please sign in to comment.