Skip to content

Commit b850829

Browse files
authored
Merge pull request #11274 from spowelljr/improveLogsCommand
Batch logs output to speedup `minikube logs` command
2 parents b7dc955 + 9d98c09 commit b850829

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pkg/minikube/logs/logs.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
184184
failed = append(failed, name)
185185
continue
186186
}
187+
l := ""
187188
scanner := bufio.NewScanner(&b)
188189
for scanner.Scan() {
189-
out.Styled(style.Empty, scanner.Text())
190+
l += scanner.Text() + "\n"
190191
}
192+
out.Styled(style.Empty, l)
191193
}
192194

193195
if len(failed) > 0 {
@@ -223,10 +225,12 @@ func outputLastStart() error {
223225
return fmt.Errorf("failed to open file %s: %v", fp, err)
224226
}
225227
defer f.Close()
228+
l := ""
226229
s := bufio.NewScanner(f)
227230
for s.Scan() {
228-
out.Styled(style.Empty, s.Text())
231+
l += s.Text() + "\n"
229232
}
233+
out.Styled(style.Empty, l)
230234
if err := s.Err(); err != nil {
231235
return fmt.Errorf("failed to read file %s: %v", fp, err)
232236
}

test/integration/aaa_download_only_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ func TestDownloadOnly(t *testing.T) {
158158
}
159159
})
160160

161+
// checks if the duration of `minikube logs` takes longer than 5 seconds
162+
t.Run("LogsDuration", func(t *testing.T) {
163+
ctx, cancel := context.WithTimeout(context.Background(), Seconds(5))
164+
defer cancel()
165+
args := []string{"logs", "-p", profile}
166+
if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil {
167+
t.Logf("minikube logs failed with error: %v", err)
168+
}
169+
if err := ctx.Err(); err == context.DeadlineExceeded {
170+
t.Error("minikube logs expected to finish by 5 seconds, but took longer")
171+
}
172+
})
173+
161174
})
162175
}
163176

0 commit comments

Comments
 (0)