Skip to content

perf(core,inspection): parallelize log filtering and optimize filter extractors - #940

Merged
kyasbal merged 4 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-kovqpqsynqym
Sep 2, 2026
Merged

kyasbal merged 4 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-kovqpqsynqym

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Description

This change improves log filtering performance across inspection tasks by parallelizing NewLogFilterTask and introducing lightweight extractors for filter predicates:

  1. Parallelized Log Filtering (pkg/core/inspection/taskbase/logfilter_task.go):

    • Filter logs concurrently across CPU cores using worker.NewPool.
    • Guarantee that original log order is preserved by statically partitioning logs into contiguous index slices [start, end) per worker and concatenating workerResults in ascending worker order.
    • Support thread-safe progress updates with atomic.Int32.
    • Add unit test verifying log order preservation under concurrent execution.
  2. Lightweight Extractors for Filter Predicates:

    • commonlogk8saudit, googlecloudlogk8saudit, ossclusterk8s: Introduced K8sAuditLogErrorExtractor / ExtractK8sAuditLogError to determine error status from status code alone without extracting the entire audit log field set.
    • googlecloudlogk8snode: Added ExtractK8sNodeParserType to identify node log component from syslog identifier / log name without parsing message contents.
    • googlecloudlogserialport: Added ExtractGCESerialPortMessage to extract only the message payload.
    • googlecloudclustercomposer: Added ExtractComposerComponent to extract component names directly from logName.
    • googlecloudlogk8scontrolplane: Added ExtractK8sControlplaneComponentParserType to resolve component parser types from component_name without resolving cluster/project metadata.
  3. Standardized OSS K8s Audit Log Filters:

    • Refactored EventAuditLogFilterTask and NonEventAuditLogFilterTask in ossclusterk8s to use inspectiontaskbase.NewLogFilterTask.
  4. Testing:

    • Added table-driven unit tests for all new extractor functions and concurrent log filtering.

Test Plan

  • Run make pre-commit
  • Run make lint-go and make test-go
  • Run make test-web
  • Verify that all unit tests pass including concurrent order preservation tests.
…extractors

This change improves log filtering performance across inspection tasks by parallelizing NewLogFilterTask and introducing lightweight extractors for filter predicates:

1. Parallelized Log Filtering (pkg/core/inspection/taskbase/logfilter_task.go):
   - Filter logs concurrently across CPU cores using worker.NewPool while preserving the original log order.
   - Support thread-safe progress updates with atomic.Int32.
   - Add unit test verifying log order preservation under concurrent execution.

2. Lightweight Extractors for Filter Predicates:
   - commonlogk8saudit, googlecloudlogk8saudit, ossclusterk8s: Introduced K8sAuditLogErrorExtractor / ExtractK8sAuditLogError to determine error status from status code alone without extracting the entire audit log field set.
   - googlecloudlogk8snode: Added ExtractK8sNodeParserType to identify node log component from syslog identifier / log name without parsing message contents.
   - googlecloudlogserialport: Added ExtractGCESerialPortMessage to extract only the message payload.
   - googlecloudclustercomposer: Added ExtractComposerComponent to extract component names directly from logName.
   - googlecloudlogk8scontrolplane: Added ExtractK8sControlplaneComponentParserType to resolve component parser types from component_name without resolving cluster/project metadata.

3. Standardized OSS K8s Audit Log Filters:
   - Refactored EventAuditLogFilterTask and NonEventAuditLogFilterTask in ossclusterk8s to use inspectiontaskbase.NewLogFilterTask.

4. Testing:
   - Added table-driven unit tests for all new extractor functions and concurrent log filtering.

@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 concurrency to the log filtering task (LogFilterTask) using a worker pool to process logs in parallel while preserving their original order. To further optimize performance, it introduces lightweight extractors across various log types (including GCP/OSS K8s Audit, Composer, K8s Controlplane, K8s Node, and GCE Serial Port) to extract only the necessary fields (such as error status, component name, or parser type) for filtering, avoiding full log parsing. Additionally, it refactors several filter tasks to use the simplified NewLogFilterTask helper. There are no review comments, and I have no feedback to provide.

@kyasbal
kyasbal merged commit e0603e9 into GoogleCloudPlatform:main Sep 2, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-kovqpqsynqym branch September 2, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant