Skip to content

fix(k8snode): link modern containerd logs, audit container IDs, and resource UIDs to Pod and Container timelines - #1192

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-lrmmpzynqykm
Oct 29, 2026
Merged

kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-lrmmpzynqykm

Conversation

@kyasbal

@kyasbal kyasbal commented Oct 29, 2026

Copy link
Copy Markdown
Member

Fixes #1191

Background

On modern GKE clusters running containerd 1.7+ / 2.0, a large portion of containerd and node logs fail to associate with their target Pod and Container timelines due to three gaps in the node log parsing pipeline:

  1. Protobuf stringification format change in containerd: Modern containerd migrated its CRI protobuf types from gogo/protobuf (&PodSandboxMetadata{Name:...,Namespace:...} and &ContainerMetadata{Name:...}) to google.golang.org/protobuf (prototext key-value output such as name:"..." uid:"..." namespace:"..."). Because containerd sandbox and container discovery only parsed the legacy Go struct syntax, RunPodSandbox and CreateContainer events on modern clusters were not indexed in the PodSandboxID and ContainerID pattern finders.
  2. Audit-discovered Container IDs lacked Pod identity: When a Pod started before the log collection window, no RunPodSandbox log exists in containerd logs to populate the PodSandboxID map. Even when ContainerID was discovered from k8s_audit status.containerStatuses, ContainerIdentity only recorded ContainerName without the parent Pod's namespace and name, preventing node logs referencing that ContainerID from linking to the Pod and Container timelines unless a RunPodSandbox log was also captured.
  3. Colon-delimited systemd cgroup slice UIDs and missing mapper dependencies: Systemd cgroup slice paths in 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, and containerd / fallback node log mappers did not wire ResourceUIDPatternFinderTaskID, logs referencing Pods solely via cgroup slice UIDs were only attached to the node timeline.

Approach

  • Extend containerd metadata extraction in findPodSandboxIDInfo and findContainerIDInfo to fall back to prototext quoted fields (name:"...", namespace:"...") when the legacy &PodSandboxMetadata{...} or &ContainerMetadata{...} struct format is not present.
  • Record PodNamespace and PodName on k8saudit.ContainerIdentity during audit log ContainerID inventory discovery (and strip both containerd:// and docker:// runtime prefixes), allowing findPodAndContainerReferences to resolve Pod and Container timelines directly from audit-discovered container identities even when PodSandboxID is absent.
  • Add : to the node log UID starter runes (nodeLogUIDStarterRunes) and unify Pod, Container, and Resource UID timeline event registration across kubelet, containerd, and fallback node log mappers via addPodContainerAndResourceEvents.

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
Loading
@kyasbal kyasbal added type:bug Something isn't working as expected area:backend-parser Log parsers and log timeline mapper tasks labels Oct 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kyasbal
kyasbal added this pull request to the merge queue Oct 29, 2026
Merged via the queue into GoogleCloudPlatform:main with commit f389d2c Oct 29, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-lrmmpzynqykm branch October 29, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-parser Log parsers and log timeline mapper tasks type:bug Something isn't working as expected

1 participant