From 7c56ac2c6770672eec2de6d21744e74cd97e3aa8 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Tue, 5 Nov 2024 10:52:52 +1300 Subject: [PATCH] feat(host): improve remote host collector speed --- pkg/supportbundle/collect.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index 7894cc935..b88fc265d 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -304,7 +304,24 @@ func getExecOutputs( if err != nil { return stdout.Bytes(), stderr.Bytes(), err } - return stdout.Bytes(), stderr.Bytes(), nil + // Set up the ticker and timeout + ticker := time.NewTicker(100 * time.Millisecond) // Polling frequency + timeout := 30 * time.Second + defer ticker.Stop() + timeoutChan := time.After(timeout) // Constant timeout + + // Loop until stdout has content or timeout is reached + for { + select { + case <-ticker.C: + if stdout.Len() > 0 { + return stdout.Bytes(), stderr.Bytes(), nil + } + case <-timeoutChan: + // Return whatever we have if the timeout is reached + return stdout.Bytes(), stderr.Bytes(), fmt.Errorf("operation timed out after %v", timeout) + } + } } func runRemoteHostCollectors(ctx context.Context, hostCollectors []*troubleshootv1beta2.HostCollect, bundlePath string, opts SupportBundleCreateOpts) (map[string][]byte, error) { @@ -384,11 +401,11 @@ func runRemoteHostCollectors(ctx context.Context, hostCollectors []*troubleshoot results[file] = []byte(data) } - time.Sleep(1 * time.Second) + // time.Sleep(1 * time.Second) } // wait for log stream to catch up - time.Sleep(1 * time.Second) + // time.Sleep(1 * time.Second) mu.Lock() nodeLogs[pod.Spec.NodeName] = results