Repository navigation
feat(workbench): persistent background Trigram indexing and search optimization - #905
Merged
Merged
Conversation
… Trigram indexing
…ompletion, import, and delete
…nd TrigramIndex synchronization
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
August 26, 2026 02:07
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a persistent disk and memory caching mechanism for search indexes (TrigramIndex) via a new InspectionIndexManager, integrating it across the server, import, and workbench services to support asynchronous indexing. The code review highlights several critical issues, including a potential runtime panic in broadcast due to concurrent channel closure, stale cache issues when re-importing or re-running inspections, a goroutine leak in SubscribeIndexProgress, a thundering herd risk during concurrent disk loads, and a potential nil pointer dereference in TrigramIndex.WriteTo.
kyasbal
commented
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements persistent background Trigram indexing and search optimization for Kubernetes History Inspector (KHI), enabling sub-second full-text and field-specific regex/literal log searching across large inspection datasets.
Background & Motivation
When filtering logs on large inspection files (e.g. hundreds of thousands of logs), evaluating CEL log queries (such as
body("image", "nginx")orbody("spec.containers.image", "nginx")) required resolving and parsing every log's AST or full YAML body text on the fly. This incurred high latency (several seconds per query).Key Changes
1. TrigramIndex Core & Binary Serialization (
pkg/server/workbench/cel/trigram.go)TrigramIndexusing Roaring Bitmaps (*roaring.Bitmap) mapped to 3-gram character substrings.RunOptimize()compaction.KHITRIXformat v2) with 7-byte magic prefix, zlib-compressed roaring bitmaps, and CRC32 checksums.2. Field-Path Trigram Query Optimization (
pkg/server/workbench/cel/)PathToTrigramQuery(pathKey string)which parses dot-delimited field paths and formats keys usingkhifilev6model.FormatKeyName(seg) + ":".image:), 2-letter fields (ip:), and quoted keys ("@type":) to constrain candidates before resolving log AST nodes.FindCandidateLogsWithFieldcombining field path queries and regex pattern queries.3. Background Index Manager (
pkg/server/workbench/index_manager.go)InspectionIndexManagerto manage asynchronous TrigramIndex generation and caching in the.khiinspection directory (search.index).worker.NewPool), progress tracking, and atomic file replacement (.tmp-> rename).4. Server Lifecycle Integration (
pkg/server/)5. Workbench API Streaming Synchronization (
pkg/server/api/v1/workbench.go)WorkbenchService.OpenWorkbenchConnect-RPC handler to stream index building progress to the frontend while reading.khilog chunks.Workbenchinstance receives the indexedTrigramIndexupon completion for immediate acceleration of subsequent CEL evaluations.Verification
make test-gopassed (100%).make test-webpassed (775 tests).make lint-go(0 issues).make pre-commitpassed (0 issues).