Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs: Add container status & cruntime logs #4960

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
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
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
}