Skip to content

Adopt RFC 6901 JSONPointer for structured data field path parsing #832

Open

Description

@kyasbal

Background

Currently, KHI uses a custom dot-separated string format for accessing fields in structured data (pkg/common/structured/reader.go), where dots . act as separators and are escaped with backslashes \..

Because Kubernetes labels and annotations frequently contain dots (e.g., compute.googleapis.com/resource_name), developers are forced to use escaping very often. Maintaining a custom path specification that lacks a formal standard increases the maintenance burden and cognitive load for new contributors.

Furthermore, frontend CEL filters currently traverse objects by simply splitting paths on ., which is both inconsistent and lacks escaping mechanisms entirely.

Proposal

We should migrate the structured data field parser in both backend and frontend to use the standard RFC 6901 JSONPointer.
JSONPointer uses / as the separator and standard escaping (~1 for / and ~0 for ~).

By adopting an IETF standard, we can:

  • Make the codebase more robust and standard.
  • Avoid maintaining custom string parsing/escaping logic.
  • Ensure consistency between backend parsing and frontend CEL filter evaluation.
  • Lower the learning curve for new developers.

Scope of Work

  1. Update Backend (pkg/common/structured):

    • Deprecate or replace the custom dot-separated parser (parseFieldPath) in reader.go.
    • Implement RFC 6901 JSONPointer parsing in getNode (or a dedicated method).
    • Update reader_test.go to test JSONPointer syntax including proper unescaping for ~0 and ~1, and edge cases like empty paths.
  2. Update Frontend (web/):

    • Update matchLogField and matchTimelineRevisionBodyField in src/app/store/domain/filter/cel-functions.ts to parse JSONPointer instead of simply using .split('.').
  3. Migrate existing usages:

    • Migrate all existing dot-separated paths across the codebase to use JSONPointer.
    • For example, resource.labels.cluster_name becomes /resource/labels/cluster_name.
    • Escaped paths like labels.compute\.googleapis\.com/resource_name become /labels/compute.googleapis.com~1resource_name.
    • Primary affected areas:
      • pkg/task/inspection/*/contract/fieldset.go
      • Task implementations (impl/*_task.go) that use structured.NodeReader.
      • Test files (e.g., logfilter_task_test.go, loggroup_task_test.go).

Acceptance Criteria

  • pkg/common/structured/reader.go correctly implements JSONPointer parsing.
  • Frontend CEL filtering correctly navigates object paths using JSONPointer.
  • All usages of ReadStringOrDefault, Has, GetReader, etc. across the codebase use the new JSONPointer syntax.
  • make test-go and frontend tests pass successfully without any regression in log parsing.

Activity

  1. added
    area:backend-core
    type:refactor
    on Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backend-coretype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions