Skip to content

Commit

Permalink
[processor/k8sattributes] Add support for DaemonSet attributes (open-…
Browse files Browse the repository at this point in the history
…telemetry#12994)

Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
povilasv and dmitryax committed Aug 8, 2022
1 parent 9eb2952 commit baf4a8c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
3 changes: 2 additions & 1 deletion processor/k8sattributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ type ExtractConfig struct {
// Metadata fields supported right now are,
// k8s.pod.name, k8s.pod.uid, k8s.deployment.name,
// k8s.node.name, k8s.namespace.name, k8s.pod.start_time,
// k8s.replicaset.name, and k8s.replicaset.uid
// k8s.replicaset.name, k8s.replicaset.uid,
// k8s.daemonset.name, and k8s.daemonset.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
13 changes: 11 additions & 2 deletions processor/k8sattributesprocessor/internal/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,24 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
}
}

if c.Rules.ReplicaSetID || c.Rules.ReplicaSetName {
if c.Rules.ReplicaSetID || c.Rules.ReplicaSetName ||
c.Rules.DaemonSetUID || c.Rules.DaemonSetName {
for _, ref := range pod.OwnerReferences {
if ref.Kind == "ReplicaSet" {
switch ref.Kind {
case "ReplicaSet":
if c.Rules.ReplicaSetID {
tags[conventions.AttributeK8SReplicaSetUID] = string(ref.UID)
}
if c.Rules.ReplicaSetName {
tags[conventions.AttributeK8SReplicaSetName] = ref.Name
}
case "DaemonSet":
if c.Rules.DaemonSetUID {
tags[conventions.AttributeK8SDaemonSetUID] = string(ref.UID)
}
if c.Rules.DaemonSetName {
tags[conventions.AttributeK8SDaemonSetName] = ref.Name
}
}
}
}
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 @@ -455,6 +455,12 @@ func TestExtractionRules(t *testing.T) {
Name: "auth-service-66f5996c7c",
UID: "207ea729-c779-401d-8347-008ecbc137e3",
},
{
APIVersion: "apps/v1",
Kind: "DaemonSet",
Name: "auth-daemonset",
UID: "c94d3814-2253-427a-ab13-2cf609e4dafa",
},
},
},
Spec: api_v1.PodSpec{
Expand Down Expand Up @@ -497,6 +503,22 @@ func TestExtractionRules(t *testing.T) {
attributes: map[string]string{
"k8s.replicaset.name": "auth-service-66f5996c7c",
},
}, {
name: "daemonsetUID",
rules: ExtractionRules{
DaemonSetUID: true,
},
attributes: map[string]string{
"k8s.daemonset.uid": "c94d3814-2253-427a-ab13-2cf609e4dafa",
},
}, {
name: "daemonsetName",
rules: ExtractionRules{
DaemonSetName: true,
},
attributes: map[string]string{
"k8s.daemonset.name": "auth-daemonset",
},
}, {
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 @@ -183,6 +183,8 @@ type FieldFilter struct {
// from pods and added to the spans as tags.
type ExtractionRules struct {
Deployment bool
DaemonSetUID bool
DaemonSetName bool
Namespace bool
PodName bool
PodUID 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 @@ -102,6 +102,10 @@ func withExtractMetadata(fields ...string) option {
p.rules.ReplicaSetName = true
case conventions.AttributeK8SReplicaSetUID:
p.rules.ReplicaSetID = true
case conventions.AttributeK8SDaemonSetName:
p.rules.DaemonSetName = true
case conventions.AttributeK8SDaemonSetUID:
p.rules.DaemonSetUID = true
case metadataNode, conventions.AttributeK8SNodeName:
p.rules.Node = true
case conventions.AttributeContainerID:
Expand Down
16 changes: 16 additions & 0 deletions unreleased/k8sattributes-daemonset.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 DaemonSet name and DaemonSet 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 baf4a8c

Please sign in to comment.