Repository navigation
feat(googlecloudcommon): parallelize Cloud Logging conversion with k-way merge and display fetch ETA - #936
Merged
Conversation
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 2, 2026 01:30
Contributor
There was a problem hiding this comment.
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.
…and partition concatenation
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.
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:
Generic K-Way Merge Sort (
pkg/common/kwaymerge):kwaymerge.Merge[T any](slices [][]T, cmp func(a, b T) int) []Tutility using a min-heap (container/heap).Parallelize Proto-to-Log Conversion (
pkg/task/inspection/googlecloudcommon/contract):ProgressReportableLogFetcherinterface andTimePartitioningProgressReportableLogFetcherto convert*loggingpb.LogEntryinto*log.Logdirectly in parallel within each partition worker goroutine.kwaymerge.Mergeat the end ofFetchLogsWithProgress, eliminating the single-goroutine conversion bottleneck.ListLogEntriesTaskandStructuredListLogEntriesTaskto merge log slices across multiple queries and resource groups.Display ETA in Fetch Progress:
formatETAandcalculateETAto estimate remaining time based on elapsed time and completion ratio (completeRatio), with warm-up threshold.monitorProgressto maintain smooth, continuous LPS and ETA without resets at partition boundaries."%d logs fetched(%.2f lps, ETA %s)[%d/%d]".Test Plan
make pre-commitmake lint-goandmake test-gopkg/common/kwaymergeandpkg/task/inspection/googlecloudcommon/contract