Repository navigation
perf(workbench): accelerate regex log filtering with Roaring Bitmap TrigramIndex and optimized SearchIndex - #899
Conversation
…uation - Introduce SearchIndex to precompute timeline hierarchies, resource paths, and log severities during workbench ingestion. - Optimize log and timeline CEL filtering by evaluating queries against precomputed search indexes. - Add unit tests for SearchIndex building and timeline path computation.
… index - Add worker.ParallelChunkMap utility supporting concurrent chunk processing, fine-grained progress reporting, and context cancellation. - Implement TrigramIndex using Roaring Bitmaps for fast sub-string candidate pruning on interned structs. - Implement a 2-stage Boolean AST (TrigramQuery) with AST simplification to support complex regex patterns (AND, OR, nested expressions) without false negatives. - Integrate trigram index construction and periodic progress reporting into workbench data indexing.
…nstruction - Store LogData directly in a flat slice and replace LogMap with O(1) index lookup via GetLog. - Remove wrapper types IndexedLog and IndexedTimeline, consolidating timeline metadata into TimelineData. - Eliminate precomputed timeline LogIDs and Path maps, resolving them on demand (ForEachLogID, ComputePath). - Optimize trigram index construction with zero-allocation UTF-8 rune decoding and batch bitmap insertion. - Release raw log and timeline chunks after building the search index to reclaim memory.
There was a problem hiding this comment.
Code Review
This pull request introduces a background search index construction pipeline for the workbench, utilizing a concurrent trigram index (TrigramIndex) built over pre-serialized struct YAMLs with roaring bitmaps to accelerate log body CEL regex queries. It also adds a new StreamIndexProgress RPC to stream indexing progress to the frontend, which displays a floating progress overlay. The review feedback identifies several critical issues: a potential bug in the parallel worker where skipped workers leave trailing zero values in the results slice, leftover CPU profiling code in the log filter, and a lack of context propagation in the async indexing pipeline that could leak goroutines. On the frontend, writing to signals inside an Angular effect will cause a runtime error unless allowSignalWrites is enabled, and the workbench client service requires AbortController integration to properly cancel active progress streams and prevent race conditions.
…ode trigram tests
Summary
This PR optimizes log filtering performance in the KHI Workbench by introducing a precomputed in-memory
SearchIndexand accelerating regular expression evaluation using a Roaring Bitmap-basedTrigramIndex. It also adds real-time search index construction progress streaming via Connect-RPC and optimizes memory consumption during workbench ingestion.Background & Motivation
has(log.body.message) && log.body.message.matches("...")) across hundreds of thousands of logs previously required full RE2 regex evaluations on serialized YAML strings for every single log entry.pod-name.*failed). By indexing 3-character n-grams (trigrams) of interned YAML strings into compressed bitsets (roaring.Bitmap), candidate structs/logs can be filtered with high precision in microseconds before invoking RE2.LogDatadirectly in a flat slice and resolving paths and log IDs on demand keeps memory consumption minimal while retaining O(1) log lookups.StreamIndexProgress) and frontend progress UI provide clear feedback to the user.API Endpoint Path Changes
POST/api.v1.WorkbenchService/StreamIndexProgressBUILDING,READY,FAILED).Key Changes
1. Protobuf (
proto/api/v1/workbench.proto)StreamIndexProgressRPC returning server-streamingStreamIndexProgressResponsewithIndexState(INDEX_STATE_BUILDING,INDEX_STATE_READY,INDEX_STATE_FAILED).2. Go Backend
pkg/common/worker:ParallelChunkMapsupporting concurrent chunk processing, fine-grained progress reporting, error aggregation, and context cancellation.pkg/server/workbench(index.go,reader.go,workbench.go):SearchIndexprecomputing timeline hierarchies, log severities, and interned string references.LogDatainto[]cel.LogDatawith O(1) index access (GetLog), eliminatingLogMappointer overhead.LogIDsandPathmaps with on-demand traversal (ForEachLogID,ComputePath).StreamIndexProgressConnect-RPC handler streaming index generation progress.logChunksandtimelineChunksafter search index construction to reclaim heap memory.pkg/server/workbench/cel(trigram.go,trigram_query.go,functions.go,env.go):TrigramIndexusing Roaring Bitmaps (github.com/RoaringBitmap/roaring) for fast substring candidate pruning.TrigramQuery) with AST simplification (AND, OR, NOT pruning) from regex patterns.matchesandcontainsfunctions by executing trigram candidate pruning before RE2 regex matching.3. Angular Frontend
src/app/index-progress:IndexProgressSmartComponentandIndexProgressLayoutComponentfollowing the Smart-Dumb component pattern.index-progress.stories.ts) and unit tests (index-progress-smart.component.spec.ts,index-progress-layout.component.spec.ts).src/app/services/api/workbench:StreamIndexProgressclient method inWorkbenchClientService.src/app/pages/main:khi-index-progress-smartinto the main application layout.Verification
make test-gopassed across all packages.make test-webpassed (760/760 tests).make lint-go,make lint-web,make lint-md,make format-go,make format-web, andmake pre-commitpassed with 0 issues.