Skip to content

Commit

Permalink
feat(host): improve remote host collector speed
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterYan committed Nov 4, 2024
1 parent 80d9964 commit 7c56ac2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/supportbundle/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c56ac2

Please sign in to comment.