Skip to content

Commit

Permalink
chore(k8sprocessor): Improve logging of missing data events
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Feb 16, 2024
1 parent e051b39 commit 6fc3669
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/1448.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chore(k8sprocessor): Improve logging of missing data events
7 changes: 7 additions & 0 deletions pkg/processor/k8sprocessor/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/client-go/tools/cache"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sprocessor/observability"
)

Expand Down Expand Up @@ -321,6 +322,9 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
}

if c.Rules.NodeName {
if len(pod.Spec.NodeName) == 0 {
c.logger.Warn("missing Node name for Pod, cache may be out of sync", zap.String("pod", pod.Name))
}
tags[c.Rules.Tags.NodeName] = pod.Spec.NodeName
}

Expand All @@ -340,6 +344,9 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
if len(pod.Status.ContainerStatuses) > 0 {
cs := pod.Status.ContainerStatuses[0]
if c.Rules.ContainerID {
if len(cs.ContainerID) == 0 {
c.logger.Warn("missing container ID for Pod, cache may be out of sync", zap.String("pod", pod.Name), zap.String("container_name", cs.Name))
}
tags[c.Rules.Tags.ContainerID] = cs.ContainerID
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/processor/k8sprocessor/kube/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,22 @@ func (op *OwnerCache) GetOwners(pod *Pod) []*ObjectOwner {
visited[ownerUID] = true
}
}
} else {
// try to find the owner
var ownerReference meta_v1.OwnerReference
for _, or := range *pod.OwnerReferences {
if or.UID == uid {
ownerReference = or
}
}
// ownerReference may be empty
op.logger.Warn(
"missing owner data for Pod, cache may be out of sync",
zap.String("pod", pod.Name),
zap.String("owner_id", string(uid)),
zap.String("owner_kind", ownerReference.Kind),
zap.String("owner_name", ownerReference.Name),
)
}
op.ownersMutex.RUnlock()
}
Expand Down

0 comments on commit 6fc3669

Please sign in to comment.