-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
k8sprocessor: add container.name field #1167
Changes from 1 commit
9fc15db
2ea31b3
5a054f5
1f7b843
86dc2cb
7c5748f
dc18129
9502d95
0848767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package kube | |
import ( | ||
"fmt" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
@@ -235,6 +236,30 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string { | |
tags[r.Name] = c.extractField(v, r) | ||
} | ||
} | ||
|
||
if c.Rules.HostName { | ||
// Basing on v1.17 Kubernetes docs, when a hostname is specified, it takes precedence over | ||
// the associated metadata name, see: | ||
// https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields | ||
if pod.Spec.Hostname == "" { | ||
tags[conventions.AttributeHostName] = pod.Name | ||
} else { | ||
tags[conventions.AttributeHostName] = pod.Spec.Hostname | ||
} | ||
} | ||
|
||
if len(pod.Spec.Containers) > 0 { | ||
if c.Rules.ContainerName { | ||
pmalek-sumo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var names []string | ||
for _, container := range pod.Spec.Containers { | ||
names = append(names, container.Name) | ||
} | ||
|
||
sort.Strings(names) | ||
tags[conventions.AttributeContainerName] = strings.Join(names, ",") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to semantic conventions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done but please comment whether it makes sense to have configuration option in plural and the tag in singular. |
||
} | ||
} | ||
|
||
return tags | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,13 +102,15 @@ type FieldFilter struct { | |
// ExtractionRules is used to specify the information that needs to be extracted | ||
// from pods and added to the spans as tags. | ||
type ExtractionRules struct { | ||
Deployment bool | ||
Namespace bool | ||
PodName bool | ||
PodUID bool | ||
Node bool | ||
Cluster bool | ||
StartTime bool | ||
Deployment bool | ||
Namespace bool | ||
PodName bool | ||
PodUID bool | ||
Node bool | ||
Cluster bool | ||
StartTime bool | ||
HostName bool | ||
ContainerName bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed this but taking into account @dmitryax's comment I'm not sure it will fit since the tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can keep it singular here for consistency, even if it may have multiple values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 done. Singular it is. |
||
|
||
Annotations []FieldExtractionRule | ||
Labels []FieldExtractionRule | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reasons for this? (other than maybe accessing
pod.Spec.Hostname
just once)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmalek-sumo, I think such approach makes the intention more clear. Currently, you check
pod.Spec.Hostname
and assignpod.Name
which is not obvious why, unless the line below is being readOf course, that might be a small thing, but one where clarity could be improved easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 done