Skip to content

Commit 70ad99d

Browse files
authored
Added progress reporting feature on ManifestGeneratorTask (#415)
1 parent 05605da commit 70ad99d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

pkg/task/inspection/commonlogk8sauditv2/impl/manifest_generator_task.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"runtime"
2222
"strings"
2323
"sync"
24+
"sync/atomic"
25+
"time"
26+
27+
"github.com/GoogleCloudPlatform/khi/pkg/core/inspection/progressutil"
2428

2529
"github.com/GoogleCloudPlatform/khi/pkg/common/structured"
2630
inspectionmetadata "github.com/GoogleCloudPlatform/khi/pkg/core/inspection/metadata"
@@ -52,13 +56,28 @@ var ManifestGeneratorTask = inspectiontaskbase.NewProgressReportableInspectionTa
5256
result := commonlogk8sauditv2_contract.ResourceManifestLogGroupMap{}
5357
resultLock := sync.Mutex{}
5458

59+
doneGroupCount := atomic.Int32{}
60+
updator := progressutil.NewProgressUpdator(progress, time.Second, func(tp *inspectionmetadata.TaskProgressMetadata) {
61+
current := doneGroupCount.Load()
62+
total := len(logGroups)
63+
if total > 0 {
64+
tp.Percentage = float32(current) / float32(total)
65+
} else {
66+
tp.Percentage = 1.0
67+
}
68+
tp.Message = fmt.Sprintf("%d/%d", current, total)
69+
})
70+
updator.Start(ctx)
71+
defer updator.Done()
72+
5573
grp, childCtx := errgroup.WithContext(ctx)
5674
grp.SetLimit(runtime.GOMAXPROCS(0))
5775

5876
for path, group := range logGroups {
5977
path := path
6078
group := group
6179
grp.Go(func() error {
80+
defer doneGroupCount.Add(1)
6281
resourceLogs := []*commonlogk8sauditv2_contract.ResourceManifestLog{}
6382
generator := groupManifestGenerator{
6483
mergeConfigRegistry: mergeConfigRegistry,

0 commit comments

Comments
 (0)