From 5d599d7d275a76083f30af5c2432b9e62d08fe2c Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Wed, 23 Oct 2024 18:07:14 +1300 Subject: [PATCH 1/2] feat(host-collector): add progress for host collector --- pkg/supportbundle/collect.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index ec8e680c2..bdc9d1728 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -214,7 +214,7 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. opts.KubernetesRestConfig.UserAgent = fmt.Sprintf("%s/%s", constants.DEFAULT_CLIENT_USER_AGENT, version.Version()) // Run remote collectors sequentially - for _, spec := range collectSpecs { + for i, spec := range collectSpecs { collector, ok := collect.GetHostCollector(spec, bundlePath) if !ok { opts.ProgressChan <- "Host collector not found" @@ -234,7 +234,12 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. } // Send progress event: starting the collector - opts.ProgressChan <- fmt.Sprintf("[%s] Running host collector...", collector.Title()) + opts.ProgressChan <- collect.CollectProgress{ + CurrentName: collector.Title(), + CurrentStatus: "running", + CompletedCount: i, + TotalCount: len(collectSpecs), + } // Parameters for remote collection params := &collect.RemoteCollectParams{ @@ -260,7 +265,9 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. } // Send progress event: completed successfully - opts.ProgressChan <- fmt.Sprintf("[%s] Completed host collector", collector.Title()) + msg := fmt.Sprintf("[%s] Completed host collector", collector.Title()) + + opts.CollectorProgressCallback(opts.ProgressChan, msg) // Aggregate the results for k, v := range result { From 8d563daa2cddce3279806976901f7ea00dc3fa57 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Thu, 24 Oct 2024 11:54:15 +1300 Subject: [PATCH 2/2] add CollectorProgressCallback for error --- pkg/supportbundle/collect.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index bdc9d1728..87ff2fcfb 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -214,7 +214,7 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. opts.KubernetesRestConfig.UserAgent = fmt.Sprintf("%s/%s", constants.DEFAULT_CLIENT_USER_AGENT, version.Version()) // Run remote collectors sequentially - for i, spec := range collectSpecs { + for _, spec := range collectSpecs { collector, ok := collect.GetHostCollector(spec, bundlePath) if !ok { opts.ProgressChan <- "Host collector not found" @@ -227,19 +227,16 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. isExcluded, _ := collector.IsExcluded() if isExcluded { - opts.ProgressChan <- fmt.Sprintf("[%s] Excluding host collector", collector.Title()) + msg := fmt.Sprintf("[%s] Excluding host collector", collector.Title()) + opts.CollectorProgressCallback(opts.ProgressChan, msg) span.SetAttributes(attribute.Bool(constants.EXCLUDED, true)) span.End() continue } // Send progress event: starting the collector - opts.ProgressChan <- collect.CollectProgress{ - CurrentName: collector.Title(), - CurrentStatus: "running", - CompletedCount: i, - TotalCount: len(collectSpecs), - } + msg := fmt.Sprintf("[%s] Running host collector...", collector.Title()) + opts.CollectorProgressCallback(opts.ProgressChan, msg) // Parameters for remote collection params := &collect.RemoteCollectParams{ @@ -260,13 +257,13 @@ func collectRemoteHost(ctx context.Context, collectSpecs []*troubleshootv1beta2. result, err := collect.RemoteHostCollect(ctx, *params) if err != nil { span.SetStatus(codes.Error, err.Error()) - opts.ProgressChan <- fmt.Sprintf("[%s] Error: %v", collector.Title(), err) + msg = fmt.Sprintf("[%s] Error: %v", collector.Title(), err) + opts.CollectorProgressCallback(opts.ProgressChan, msg) return errors.Wrap(err, "failed to run remote host collector") } // Send progress event: completed successfully - msg := fmt.Sprintf("[%s] Completed host collector", collector.Title()) - + msg = fmt.Sprintf("[%s] Completed host collector", collector.Title()) opts.CollectorProgressCallback(opts.ProgressChan, msg) // Aggregate the results