Skip to content

refactor(progress): unify task progress reporting via context and centralize ETA calculation - #1008

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-wznlsrnvpmpr
Sep 16, 2026
Merged

kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-wznlsrnvpmpr

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace legacy NewProgressReportableInspectionTask and progressutil with a unified context-based progress package (progress.Report, progress.ReportIndeterminate, progress.NewTracker, progress.NewRatioTracker, progress.ForEach).
  • Encapsulate TaskProgressMetadata and Progress fields with thread-safe Snapshot methods.
  • Extract shared progress.TaskInterceptor for runner and test harnesses.
  • Centralize throughput and ETA calculation in progress trackers.
  • Update task system documentation (EN/JA) to reflect unified context-based progress reporting.
…tralize ETA calculation

- Replace legacy NewProgressReportableInspectionTask and progressutil with context-based progress package (progress.Report, progress.ReportIndeterminate, progress.NewTracker, progress.NewRatioTracker, progress.ForEach).
- Encapsulate TaskProgressMetadata and Progress fields with thread-safe Snapshot methods.
- Extract shared progress.TaskInterceptor for runner and test harnesses.
- Centralize throughput and ETA calculation in progress trackers.
- Update task system documentation (EN/JA) to reflect unified context-based progress reporting.

TAG=agy
@kyasbal
kyasbal requested review from RyuSA and jyane as code owners September 16, 2026 01:05
@kyasbal kyasbal added the area:backend-core Core backend frameworks, DAG task runner, and server API label Sep 16, 2026
@kyasbal
kyasbal requested a review from kkuchima as a code owner September 16, 2026 01:05
@kyasbal kyasbal added the area:backend-parser Log parsers and log timeline mapper tasks label Sep 16, 2026
@kyasbal
kyasbal requested a review from renamoo as a code owner September 16, 2026 01:05
@kyasbal kyasbal added area:frontend Web frontend application and UI components type:refactor Code refactoring without behavioral change labels Sep 16, 2026
@kyasbal
kyasbal requested a review from K53 as a code owner September 16, 2026 01:05

@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 refactors the progress reporting system in KHI, replacing the legacy NewProgressReportableInspectionTask and progressutil package with a new context-bound progress package featuring Tracker, ForEach, and RatioTracker for cleaner, thread-safe progress updates. A TaskInterceptor was introduced to automatically manage task progress metadata. Various inspection tasks, tests, and documentation in English and Japanese were updated to align with this new architecture, and the frontend layout was adjusted to display the updated progress labels. The review feedback highlights two critical division-by-zero issues in fetchClusterResourceSnapshots and fetchGKEResourceSnapshots when totalChunks is zero, which would produce NaN or +Inf and cause JSON marshaling to fail.

Comment on lines 274 to 276
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, lookup.scope, matchedAssetNames, assetpb.ContentType_RESOURCE, lookup.timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames)))
})

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.

high

If totalChunks is 0 (e.g., when matchedAssetNames is empty), dividing completedChunks by totalChunks will result in NaN or +Inf. When this value is passed to progress.Report and subsequently marshaled to JSON, json.Marshal will fail with json.UnsupportedValueError because JSON does not support NaN or Inf values. Guard against division by zero by checking if totalChunks > 0.

Suggested change
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, lookup.scope, matchedAssetNames, assetpb.ContentType_RESOURCE, lookup.timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames)))
})
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, lookup.scope, matchedAssetNames, assetpb.ContentType_RESOURCE, lookup.timeWindow, func(completedChunks, totalChunks int) {
ratio := float32(0)
if totalChunks > 0 {
ratio = float32(completedChunks) / float32(totalChunks)
}
progress.Report(ctx, ratio, fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames)))
})
Comment on lines 110 to 112
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, scope, assetNames, assetpb.ContentType_RESOURCE, timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames)))
})

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.

high

If totalChunks is 0 (e.g., when assetNames is empty), dividing completedChunks by totalChunks will result in NaN or +Inf. When this value is passed to progress.Report and subsequently marshaled to JSON, json.Marshal will fail with json.UnsupportedValueError because JSON does not support NaN or Inf values. Guard against division by zero by checking if totalChunks > 0.

Suggested change
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, scope, assetNames, assetpb.ContentType_RESOURCE, timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames)))
})
temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, scope, assetNames, assetpb.ContentType_RESOURCE, timeWindow, func(completedChunks, totalChunks int) {
ratio := float32(0)
if totalChunks > 0 {
ratio = float32(completedChunks) / float32(totalChunks)
}
progress.Report(ctx, ratio, fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames)))
})
Comment thread pkg/core/inspection/progress/tracker.go Outdated
Comment on lines +250 to +252
if strings.Contains(lower, "log") {
return "lps"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use log/s instead and the logic become simpler.

Comment on lines +92 to +95
unit := "logs"
if passCount > 0 {
unit = "steps"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use steps. Let's keep it simpler.

Comment on lines +108 to +111
unit := "logs"
if passCount > 0 {
unit = "steps"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +272 to +275
progress.Report(ctx, 0.0, fmt.Sprintf("Fetching asset history (0/%d chunks, %d assets)...", totalChunks, len(matchedAssetNames)))

temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, lookup.scope, matchedAssetNames, assetpb.ContentType_RESOURCE, lookup.timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(matchedAssetNames)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we use the tracker? Then we can show ETA as well.

Comment on lines +103 to +111
progress.Report(ctx, 0.0, fmt.Sprintf("Fetching GKE asset history (0/%d chunks, %d assets)...", totalChunks, len(assetNames)))

timeWindow := &assetpb.TimeWindow{
StartTime: timestamppb.New(startTime),
EndTime: timestamppb.New(endTime),
}

temporalAssets, err := fetcher.BatchGetAssetsHistory(ctx, scope, assetNames, assetpb.ContentType_RESOURCE, timeWindow, func(completedChunks, totalChunks int) {
progress.Percentage = float32(completedChunks) / float32(totalChunks)
progress.Message = fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames))
progress.Report(ctx, float32(completedChunks)/float32(totalChunks), fmt.Sprintf("Fetching GKE asset history (%d/%d chunks, %d assets)...", completedChunks, totalChunks, len(assetNames)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


// 3. Build KHI v6 format and flush remaining chunks
if err := builder.Build(&taskProgressReporter{progress: progress}); err != nil {
if err := builder.Build(&taskProgressReporter{progressMeta: progress.FromContext(ctx)}); err != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just pass context then use the new APIs from the context inside Build func.

…s, and Builder.Build context

- Update progress tracker unit labels across log ingester and mapper tasks ('logs' -> 'groups' or omit unit).
- Pass ctx to khifilev6.Builder.Build(ctx) and manage progress tracker internally in Builder.Build.
- Encapsulate progress tracker creation inside CAIFetcher.BatchGetAssetsHistory via ctx and remove onProgress callback.
- Move metadata map context key to inspectionmetadata.MapContextKey and remove inspectioncore.InspectionRunMetadata alias.

TAG=agy
@kyasbal
kyasbal added this pull request to the merge queue Sep 16, 2026
Merged via the queue into GoogleCloudPlatform:main with commit 49035f3 Sep 16, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-wznlsrnvpmpr branch September 16, 2026 02:38
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 area:backend-parser Log parsers and log timeline mapper tasks area:frontend Web frontend application and UI components type:refactor Code refactoring without behavioral change

1 participant