Skip to content

feat(k8snode): bind container and pod sandbox IDs in all node component logs - #1028

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-qssmypznxquq
Sep 17, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-qssmypznxquq

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 17, 2026

Copy link
Copy Markdown
Member

What

Resolves container IDs and pod sandbox IDs in node logs emitted by components other than containerd and kubelet, such as gcfsd.

Why

KHI builds a mapping from container IDs and pod sandbox IDs to the pods and containers they belong to, and uses it to replace unreadable IDs in log summaries and to attach logs to pod and container timelines. Two gaps prevented this from working outside containerd and kubelet logs.

1. ID detection only started after " or =.

patternfinder.FindAllWithStarterRunes(raw, finder, false, '"', '=') attempts a match only when the preceding character is one of the listed delimiters. Other components punctuate IDs differently, so no match was ever found. For example, in a gcfsd log:

msg="Received TaskCreate event: {ContainerID:a1b2...6790 Bundle:/run/containerd/io.containerd.runtime.v2.task/k8s.io/a1b2...6790 ...}"

the ID is preceded by : and by /, so all three occurrences were missed.

2. The fallback mapper never looked at IDs.

Pod and container timeline association existed only in mapper_containerd.go and mapper_kubelet.go. mapper_fallback.go, which handles every other node component, only added an event to the component timeline.

How

  • Add patternfinder.FindAllHexTokens. Container IDs and pod sandbox IDs are lowercase hexadecimal strings, so a genuine occurrence is always delimited by non-hexadecimal bytes on both ends. Matching on that boundary finds IDs regardless of the surrounding punctuation, removes the need to enumerate delimiters, and keeps a registered ID from matching inside a longer digest that merely shares its prefix. FindAllWithStarterRunes stays for resource UID lookups, which are not plain hexadecimal.
  • Extract findPodAndContainerReferences in parser_utility.go, replacing the ID lookup that was duplicated across the log ingester and the containerd and kubelet mappers.
  • Make mapper_fallback.go attach logs of other node components to pod and container timelines.
  • Update the package dependency diagram in registration.go.

Out of scope

Resource UID (UUID) lookup is unchanged. UUIDs contain hyphens, so the hexadecimal token rule does not apply directly. A similar gap may exist there and is left for a separate change.

Testing

  • TestFindAllHexTokens covers :, /, ", and = delimiters, a match at the start of the text, rejection of a match embedded in a longer hexadecimal run on either side, repeated IDs, and unregistered IDs.
  • TestFindPodAndContainerReferences covers pod resolution, container resolution with the owning pod, omission of container IDs whose pod sandbox is unknown, and unregistered IDs.
  • New gcfsd cases verify summary replacement in common_test.go, and pod and container timeline association in mapper_fallback_test.go.
  • BenchmarkFindAllHexTokensWithContainerIDScenario mirrors the existing starter-rune benchmark.
  • make pre-commit, make lint-go, and make test-go all pass.
…nt logs

Node logs emitted by components other than containerd and kubelet, such as
gcfsd, reference container IDs and pod sandbox IDs, but KHI never resolved
them. Pattern matching only attempted a match after a '"' or '=', so IDs
written as 'ContainerID:<id>' or '/containers/<id>/' were missed, and the
fallback mapper did not associate those logs with pod or container timelines
at all.

- Add patternfinder.FindAllHexTokens, which matches a registered pattern only
  when it forms a whole lowercase hexadecimal token. This finds IDs regardless
  of the surrounding punctuation and keeps an ID from matching inside a longer
  digest that shares its prefix.
- Extract findPodAndContainerReferences, replacing the ID lookup duplicated
  across the log ingester and the containerd and kubelet mappers.
- Associate logs of other node components with pod and container timelines.
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API labels Sep 17, 2026
@kyasbal
kyasbal requested a review from RyuSA as a code owner September 17, 2026 13:54
@kyasbal kyasbal added the area:backend-parser Log parsers and log timeline mapper tasks label Sep 17, 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 introduces a new pattern-matching function FindAllHexTokens to identify lowercase hexadecimal tokens (such as container and pod sandbox IDs) within log messages, along with corresponding tests and benchmarks. It refactors several log mappers and ingesters to use a unified helper function findPodAndContainerReferences for resolving pod and container references. Feedback on the changes highlights a potential nil pointer dereference panic in findPodAndContainerReferences when pattern finders are nil (e.g., in dry-run mode), recommending explicit nil checks to ensure robustness.

@kyasbal
kyasbal added this pull request to the merge queue Sep 17, 2026
Merged via the queue into GoogleCloudPlatform:main with commit b14ad9b Sep 17, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-qssmypznxquq branch September 17, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks type:feature New feature or request

1 participant