feat(host-collector): add progress for host collector (#1659)

This commit is contained in:
Dexter Yan
2024-10-25 15:34:09 +13:00
committed by GitHub
parent eacff7112f
commit 47f391ba2e
+8 -4
View File
@@ -227,14 +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 <- fmt.Sprintf("[%s] Running host collector...", collector.Title())
msg := fmt.Sprintf("[%s] Running host collector...", collector.Title())
opts.CollectorProgressCallback(opts.ProgressChan, msg)
// Parameters for remote collection
params := &collect.RemoteCollectParams{
@@ -255,12 +257,14 @@ 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
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 {