Skip to content

fix(csm): return structured.Node from TrackAndGetManifest to fix ResourceBody intern error - #943

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-znlkruyurmpm
Sep 2, 2026
Merged

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

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 2, 2026

Copy link
Copy Markdown
Member

Description

When parsing CSM (Cloud Service Mesh) Traffic Director audit logs into timelines, an inspection failure occurred with the following error:

error: failed to intern resource body for revision: expected map node, got 1

Root Cause

  1. In KHI v6, StagingRevision.ResourceBody stores resource tree structures as interned dictionary-compressed protobuf structures (InternedStruct) via khifilev6.ToInternedStruct(node, pool). ToInternedStruct strictly requires node.Type() == structured.MapNodeType (value 3).
  2. GCPOperationTracker.TrackAndGetManifest returned the resource manifest as a YAML string (string).
  3. In CSMTrafficDirectorLogToTimelineMapper.ProcessLogByGroup, this YAML string was wrapped into structured.NewStandardScalarNode(manifest) (ScalarNodeType = 1) before being assigned to StagingRevision.ResourceBody. When TimelineChangeSet.Flush() called ToInternedStruct, it threw a validation error expecting a MapNode instead of a ScalarNode.
  4. Existing unit tests asserted against structured.NewStandardScalarNode(...) without calling Flush() or ToInternedStruct(), which allowed this discrepancy to slip through.

Changes

  1. pkg/task/inspection/googlecloudcommon/contract/operation_tracker.go:
    • Updated TrackAndGetManifest(audit *GCPAuditLogFieldSet) signature to return (structured.Node, bool).
    • Extracted structured.Node from audit.Response.Node or audit.Request.Node, while preserving deduplication comparison using YAML string representations.
  2. pkg/task/inspection/googlecloudlogcsm/impl/traffic_director_parser_task.go:
    • Assigned the returned manifestNode directly to StagingRevision.ResourceBody without wrapping it in a scalar node.
    • Removed unused structured package import.
  3. Unit Tests:
    • Added TestGCPOperationTracker_TrackAndGetManifest in operation_tracker_test.go covering node extraction and deduplication.
    • Updated traffic_director_parser_task_test.go to expect the map node reqNode in wantMeshPath and added cs.Flush(builder.TimelineAccumulator) verification to ensure serialization into InternedStruct succeeds without errors.

Test Plan

  • Ran make build-go
  • Ran make test-go
  • Ran make lint-go
  • Ran make format-go
  • Ran make pre-commit
…urceBody intern error

In the CSM Traffic Director parser, ResourceBody was wrapped in
structured.NewStandardScalarNode(manifest) using a YAML string returned by
TrackAndGetManifest. When TimelineChangeSet.Flush was executed, ToInternedStruct
failed with "expected map node, got 1" because it expects MapNodeType.

This change modifies GCPOperationTracker.TrackAndGetManifest to return
(structured.Node, bool) directly from audit.Response or audit.Request,
assigns manifestNode directly to StagingRevision.ResourceBody, and updates
unit tests to verify that ResourceBody can be interned without error.
@kyasbal kyasbal added the type:bug Something isn't working as expected label Sep 2, 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 refactors TrackAndGetManifest in GCPOperationTracker to return a structured.Node instead of a string, updating its usage and corresponding tests across the codebase. Feedback suggests adding a defensive nil check for the audit parameter in TrackAndGetManifest to prevent potential nil pointer dereferences.

@kyasbal
kyasbal merged commit 42e1058 into GoogleCloudPlatform:main Sep 2, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-znlkruyurmpm branch September 2, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

1 participant