Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions clusterloader2/pkg/measurement/common/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (e *execMeasurement) Execute(config *measurement.Config) ([]measurement.Sum
if err != nil {
return nil, err
}
streamOutput, err := util.GetBoolOrDefault(config.Params, "streamOutput", false)
if err != nil {
return nil, err
}
// Make a copy of command, to avoid overriding a slice we don't own.
command = append([]string{}, command...)
for i := range command {
Expand All @@ -78,8 +82,21 @@ func (e *execMeasurement) Execute(config *measurement.Config) ([]measurement.Sum
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.CommandContext(ctx, command[0], command[1:]...)
out, err := cmd.CombinedOutput()
klog.V(2).Infof("Exec command output: %v", string(out))

var out []byte
var err error
if streamOutput {
// Stream output to stdout/stderr in real-time
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
klog.V(2).Infof("Streaming command output to stdout/stderr in real-time")
err = cmd.Run()
out = []byte("") // No captured output when streaming
} else {
// Capture output for logging
out, err = cmd.CombinedOutput()
klog.V(2).Infof("Exec command output: %v", string(out))
}
if err == nil {
klog.V(2).Infof("Command %v succeeded in attempt %v", command, i+1)
return nil, nil
Expand Down