Repository navigation
fix(k8snode): link modern containerd logs, audit container IDs, and resource UIDs to Pod and Container timelines - #1192
Conversation
…esource UIDs to Pod and Container timelines
There was a problem hiding this comment.
Code Review
This pull request enhances container and pod identity discovery from Kubernetes audit and node logs. It updates ContainerIdentity to include pod namespace and name, adds support for parsing modern prototext log formats in containerd mappers, and unifies the mapping of pods, containers, and resource events across different node log mappers (containerd, kubelet, and fallback mappers) using a shared helper. Comprehensive unit tests have been added to verify these changes. The review feedback focuses on performance optimizations in string parsing, specifically recommending the use of strings.Index instead of a character-by-character loop in readQuotedFieldFromString, and utilizing strings.Cut instead of strings.Split to avoid unnecessary allocations.
f389d2c
Fixes #1191
Background
On modern GKE clusters running
containerd1.7+ / 2.0, a large portion ofcontainerdand node logs fail to associate with their target Pod and Container timelines due to three gaps in the node log parsing pipeline:containerd: Moderncontainerdmigrated its CRI protobuf types fromgogo/protobuf(&PodSandboxMetadata{Name:...,Namespace:...}and&ContainerMetadata{Name:...}) togoogle.golang.org/protobuf(prototextkey-value output such asname:"..." uid:"..." namespace:"..."). Becausecontainerdsandbox and container discovery only parsed the legacy Go struct syntax,RunPodSandboxandCreateContainerevents on modern clusters were not indexed in thePodSandboxIDandContainerIDpattern finders.RunPodSandboxlog exists incontainerdlogs to populate thePodSandboxIDmap. Even whenContainerIDwas discovered fromk8s_auditstatus.containerStatuses,ContainerIdentityonly recordedContainerNamewithout the parent Pod's namespace and name, preventing node logs referencing thatContainerIDfrom linking to the Pod and Container timelines unless aRunPodSandboxlog was also captured.containerd,kubelet, and node component logs embed Pod UIDs immediately after a colon (cri-containerd:<pod-uid>.scope). Because:was not included in the UID starter runes for node logs, andcontainerd/ fallback node log mappers did not wireResourceUIDPatternFinderTaskID, logs referencing Pods solely via cgroup slice UIDs were only attached to the node timeline.Approach
containerdmetadata extraction infindPodSandboxIDInfoandfindContainerIDInfoto fall back toprototextquoted fields (name:"...",namespace:"...") when the legacy&PodSandboxMetadata{...}or&ContainerMetadata{...}struct format is not present.PodNamespaceandPodNameonk8saudit.ContainerIdentityduring audit logContainerIDinventory discovery (and strip bothcontainerd://anddocker://runtime prefixes), allowingfindPodAndContainerReferencesto resolve Pod and Container timelines directly from audit-discovered container identities even whenPodSandboxIDis absent.:to the node log UID starter runes (nodeLogUIDStarterRunes) and unify Pod, Container, and Resource UID timeline event registration acrosskubelet,containerd, and fallback node log mappers viaaddPodContainerAndResourceEvents.Task Graph Changes
flowchart LR subgraph sub_k8saudit ["k8saudit Inventory"] task_uid_finder["ResourceUIDPatternFinderTask"] task_cid_finder["ContainerIDPatternFinderTask"] end subgraph sub_k8snode ["k8snode Timeline Mappers"] task_sandbox_finder["ContainerdPodSandboxIDDiscoveryTask"] task_kubelet_mapper["KubeletLogToTimelineMapperTask"] task_containerd_mapper["ContainerdLogToTimelineMapperTask"] task_other_mapper["OtherNodeLogToTimelineMapperTask"] end task_uid_finder -->|"existing"| task_kubelet_mapper task_uid_finder -->|"added"| task_containerd_mapper task_uid_finder -->|"added"| task_other_mapper task_cid_finder -->|"existing"| task_kubelet_mapper task_cid_finder -->|"existing"| task_containerd_mapper task_cid_finder -->|"existing"| task_other_mapper task_sandbox_finder -->|"existing"| task_kubelet_mapper task_sandbox_finder -->|"existing"| task_containerd_mapper task_sandbox_finder -->|"existing"| task_other_mapper