Skip to content

feat(googlecloudcommon): parallelize Cloud Logging conversion with k-way merge and display fetch ETA - #936

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

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

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 2, 2026

Copy link
Copy Markdown
Member

Description

This PR refactors Cloud Logging log retrieval to parallelize proto-to-log conversion, introduces a generic k-way merge sort, and displays estimated time remaining (ETA) in the progress reporter:

  1. Generic K-Way Merge Sort (pkg/common/kwaymerge):

    • Implemented a generic kwaymerge.Merge[T any](slices [][]T, cmp func(a, b T) int) []T utility using a min-heap (container/heap).
    • Added unit tests covering integers, strings, timestamps, and stability.
  2. Parallelize Proto-to-Log Conversion (pkg/task/inspection/googlecloudcommon/contract):

    • Updated ProgressReportableLogFetcher interface and TimePartitioningProgressReportableLogFetcher to convert *loggingpb.LogEntry into *log.Log directly in parallel within each partition worker goroutine.
    • Merged partition slices using kwaymerge.Merge at the end of FetchLogsWithProgress, eliminating the single-goroutine conversion bottleneck.
    • Updated ListLogEntriesTask and StructuredListLogEntriesTask to merge log slices across multiple queries and resource groups.
  3. Display ETA in Fetch Progress:

    • Added formatETA and calculateETA to estimate remaining time based on elapsed time and completion ratio (completeRatio), with warm-up threshold.
    • Tracked task start time and accumulated log count across multiple list calls in monitorProgress to maintain smooth, continuous LPS and ETA without resets at partition boundaries.
    • Updated progress message format to "%d logs fetched(%.2f lps, ETA %s)[%d/%d]".

Test Plan

  • Run make pre-commit
  • Run make lint-go and make test-go
  • Unit tests pass including pkg/common/kwaymerge and pkg/task/inspection/googlecloudcommon/contract
@kyasbal kyasbal added the area:backend-core Core backend frameworks, DAG task runner, and server API label Sep 2, 2026

@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 new kwaymerge package to merge multiple pre-sorted slices using a heap-based approach. It refactors the log fetching task to fetch logs in parallel partitions, convert them to structured log objects concurrently, and merge them using the new package. It also adds ETA estimation to the progress reporting. The code review feedback is highly valuable and points out a concurrent data race on the subProgresses slice, a potential memory leak in the heap's Pop method, and an optimization opportunity to use simple slice concatenation instead of k-way merging since the time partitions are contiguous and non-overlapping.

Comment thread pkg/common/kwaymerge/kway_merge.go Resolved
@kyasbal
kyasbal merged commit 465e5f3 into GoogleCloudPlatform:main Sep 2, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-kzyzlsrwmwzs branch September 2, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API

1 participant