Skip to content

perf(workbench): accelerate regex log filtering with Roaring Bitmap TrigramIndex and optimized SearchIndex - #899

Merged
kyasbal merged 5 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-rmpoutmxvnxv
Aug 25, 2026
Merged

kyasbal merged 5 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-rmpoutmxvnxv

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

This PR optimizes log filtering performance in the KHI Workbench by introducing a precomputed in-memory SearchIndex and accelerating regular expression evaluation using a Roaring Bitmap-based TrigramIndex. It also adds real-time search index construction progress streaming via Connect-RPC and optimizes memory consumption during workbench ingestion.

Background & Motivation

  1. High CEL Log Filtering Latency on Large Datasets: Evaluating regex filters (e.g., 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.
  2. Sub-string Pruning with Roaring Bitmaps: Most regex patterns specify fixed literal substrings (e.g., 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.
  3. Memory Footprint Optimization: Precomputing full path maps and log ID lists for every timeline previously created significant heap overhead. Storing LogData directly in a flat slice and resolving paths and log IDs on demand keeps memory consumption minimal while retaining O(1) log lookups.
  4. User Experience During Ingestion: Constructing the search index and trigram index can take several seconds for massive files. A dedicated streaming RPC (StreamIndexProgress) and frontend progress UI provide clear feedback to the user.

API Endpoint Path Changes

Change Protocol / Type HTTP Method Endpoint Path Description
➕ Added Connect-RPC (Streaming) POST /api.v1.WorkbenchService/StreamIndexProgress Streams search index construction progress percentages and lifecycle states (BUILDING, READY, FAILED).

Key Changes

1. Protobuf (proto/api/v1/workbench.proto)

  • Defined StreamIndexProgress RPC returning server-streaming StreamIndexProgressResponse with IndexState (INDEX_STATE_BUILDING, INDEX_STATE_READY, INDEX_STATE_FAILED).
  • Generated Go and TypeScript Connect stubs.

2. Go Backend

  • pkg/common/worker:
    • Implemented ParallelChunkMap supporting concurrent chunk processing, fine-grained progress reporting, error aggregation, and context cancellation.
  • pkg/server/workbench (index.go, reader.go, workbench.go):
    • Introduced SearchIndex precomputing timeline hierarchies, log severities, and interned string references.
    • Flattened LogData into []cel.LogData with O(1) index access (GetLog), eliminating LogMap pointer overhead.
    • Replaced static timeline LogIDs and Path maps with on-demand traversal (ForEachLogID, ComputePath).
    • Implemented StreamIndexProgress Connect-RPC handler streaming index generation progress.
    • Released raw logChunks and timelineChunks after search index construction to reclaim heap memory.
  • pkg/server/workbench/cel (trigram.go, trigram_query.go, functions.go, env.go):
    • Implemented TrigramIndex using Roaring Bitmaps (github.com/RoaringBitmap/roaring) for fast substring candidate pruning.
    • Implemented 2-stage Boolean AST (TrigramQuery) with AST simplification (AND, OR, NOT pruning) from regex patterns.
    • Accelerated CEL matches and contains functions by executing trigram candidate pruning before RE2 regex matching.

3. Angular Frontend

  • src/app/index-progress:
    • Implemented IndexProgressSmartComponent and IndexProgressLayoutComponent following the Smart-Dumb component pattern.
    • Added Storybook stories (index-progress.stories.ts) and unit tests (index-progress-smart.component.spec.ts, index-progress-layout.component.spec.ts).
  • src/app/services/api/workbench:
    • Added StreamIndexProgress client method in WorkbenchClientService.
  • src/app/pages/main:
    • Integrated khi-index-progress-smart into the main application layout.

Verification

  • Backend Unit Tests: make test-go passed across all packages.
  • Frontend Unit Tests: make test-web passed (760/760 tests).
  • Linters & Formatters: make lint-go, make lint-web, make lint-md, make format-go, make format-web, and make pre-commit passed with 0 issues.
…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.

@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 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.

Comment thread pkg/common/worker/parallel.go Resolved
Comment thread pkg/server/workbench/filter_log_cel.go Resolved
Comment thread pkg/server/workbench/index.go Resolved
Comment thread proto/api/v1/workbench.proto Resolved
@kyasbal kyasbal added the type:feature New feature or request label Aug 25, 2026
@kyasbal
kyasbal merged commit 07b56be into GoogleCloudPlatform:main Aug 25, 2026
23 of 24 checks passed
@kyasbal
kyasbal deleted the push-rmpoutmxvnxv branch August 25, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature or request

1 participant