Skip to content

Commit

Permalink
Merge pull request #11274 from spowelljr/improveLogsCommand
Browse files Browse the repository at this point in the history
Batch logs output to speedup `minikube logs` command
  • Loading branch information
medyagh authored May 5, 2021
2 parents b7dc955 + 9d98c09 commit b850829
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
failed = append(failed, name)
continue
}
l := ""
scanner := bufio.NewScanner(&b)
for scanner.Scan() {
out.Styled(style.Empty, scanner.Text())
l += scanner.Text() + "\n"
}
out.Styled(style.Empty, l)
}

if len(failed) > 0 {
Expand Down Expand Up @@ -223,10 +225,12 @@ func outputLastStart() error {
return fmt.Errorf("failed to open file %s: %v", fp, err)
}
defer f.Close()
l := ""
s := bufio.NewScanner(f)
for s.Scan() {
out.Styled(style.Empty, s.Text())
l += s.Text() + "\n"
}
out.Styled(style.Empty, l)
if err := s.Err(); err != nil {
return fmt.Errorf("failed to read file %s: %v", fp, err)
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/aaa_download_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ func TestDownloadOnly(t *testing.T) {
}
})

// checks if the duration of `minikube logs` takes longer than 5 seconds
t.Run("LogsDuration", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), Seconds(5))
defer cancel()
args := []string{"logs", "-p", profile}
if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil {
t.Logf("minikube logs failed with error: %v", err)
}
if err := ctx.Err(); err == context.DeadlineExceeded {
t.Error("minikube logs expected to finish by 5 seconds, but took longer")
}
})

})
}

Expand Down

0 comments on commit b850829

Please sign in to comment.