Repository navigation
Description
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
-
Update Backend (
pkg/common/structured):- Deprecate or replace the custom dot-separated parser (
parseFieldPath) inreader.go. - Implement RFC 6901 JSONPointer parsing in
getNode(or a dedicated method). - Update
reader_test.goto test JSONPointer syntax including proper unescaping for~0and~1, and edge cases like empty paths.
- Deprecate or replace the custom dot-separated parser (
-
Update Frontend (
web/):- Update
matchLogFieldandmatchTimelineRevisionBodyFieldinsrc/app/store/domain/filter/cel-functions.tsto parse JSONPointer instead of simply using.split('.').
- Update
-
Migrate existing usages:
- Migrate all existing dot-separated paths across the codebase to use JSONPointer.
- For example,
resource.labels.cluster_namebecomes/resource/labels/cluster_name. - Escaped paths like
labels.compute\.googleapis\.com/resource_namebecome/labels/compute.googleapis.com~1resource_name. - Primary affected areas:
pkg/task/inspection/*/contract/fieldset.go- Task implementations (
impl/*_task.go) that usestructured.NodeReader. - Test files (e.g.,
logfilter_task_test.go,loggroup_task_test.go).
Acceptance Criteria
-
pkg/common/structured/reader.gocorrectly 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-goand frontend tests pass successfully without any regression in log parsing.
Activity