Skip to content

Commit

Permalink
Merge pull request #4960 from tstromberg/cherry-3a96b
Browse files Browse the repository at this point in the history
logs: Add container status & cruntime logs
  • Loading branch information
tstromberg authored Aug 2, 2019
2 parents aabe45b + be61eb7 commit de84f83
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ var logsCmd = &cobra.Command{
func init() {
logsCmd.Flags().BoolVarP(&followLogs, "follow", "f", false, "Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.")
logsCmd.Flags().BoolVar(&showProblems, "problems", false, "Show only log entries which point to known problems")
logsCmd.Flags().IntVarP(&numberOfLines, "length", "n", 50, "Number of lines back to go within the log")
logsCmd.Flags().IntVarP(&numberOfLines, "length", "n", 30, "Number of lines back to go within the log")
}
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ func (r *Containerd) StopContainers(ids []string) error {
func (r *Containerd) ContainerLogCmd(id string, len int, follow bool) string {
return criContainerLogCmd(id, len, follow)
}

// SystemLogCmd returns the command to retrieve system logs
func (r *Containerd) SystemLogCmd(len int) string {
return fmt.Sprintf("sudo journalctl -u containerd -n %d", len)
}
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ func (r *CRIO) StopContainers(ids []string) error {
func (r *CRIO) ContainerLogCmd(id string, len int, follow bool) string {
return criContainerLogCmd(id, len, follow)
}

// SystemLogCmd returns the command to retrieve system logs
func (r *CRIO) SystemLogCmd(len int) string {
return fmt.Sprintf("sudo journalctl -u crio -n %d", len)
}
2 changes: 2 additions & 0 deletions pkg/minikube/cruntime/cruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type Manager interface {
StopContainers([]string) error
// ContainerLogCmd returns the command to retrieve the log for a container based on ID
ContainerLogCmd(string, int, bool) string
// SystemLogCmd returns the command to return the system logs
SystemLogCmd(int) string
}

// Config is runtime configuration
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,8 @@ func (r *Docker) ContainerLogCmd(id string, len int, follow bool) string {
cmd.WriteString(id)
return cmd.String()
}

// SystemLogCmd returns the command to retrieve system logs
func (r *Docker) SystemLogCmd(len int) string {
return fmt.Sprintf("sudo journalctl -u docker -n %d", len)
}
9 changes: 6 additions & 3 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,22 @@ func OutputProblems(problems map[string][]string, maxLines int) {
// Output displays logs from multiple sources in tail(1) format
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Runner, lines int) error {
cmds := logCommands(r, bs, lines, false)

// These are not technically logs, but are useful to have in bug reports.
cmds["kernel"] = "uptime && uname -a && grep PRETTY /etc/os-release"

names := []string{}
for k := range cmds {
names = append(names, k)
}
sort.Strings(names)

sort.Strings(names)
failed := []string{}
for i, name := range names {
if i > 0 {
out.T(out.Empty, "")
}
out.T(out.Empty, "==> {{.name}} <==", out.V{"name": name})
var b bytes.Buffer

err := runner.CombinedOutputTo(cmds[name], &b)
if err != nil {
glog.Errorf("failed: %v", err)
Expand All @@ -141,6 +140,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run
out.T(out.Empty, scanner.Text())
}
}

if len(failed) > 0 {
return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", "))
}
Expand All @@ -163,5 +163,8 @@ func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, length int, f
}
cmds[pod] = r.ContainerLogCmd(ids[0], length, follow)
}
cmds[r.Name()] = r.SystemLogCmd(length)
// Works across container runtimes with good formatting
cmds["container status"] = "sudo crictl ps -a"
return cmds
}

0 comments on commit de84f83

Please sign in to comment.