diff --git a/containerd/main.go b/containerd/main.go index 6e9af13..88a5bc8 100644 --- a/containerd/main.go +++ b/containerd/main.go @@ -103,6 +103,9 @@ func daemon(id, stateDir string, concurrency, bufferSize int) error { } // only set containerd as the subreaper if it is not an init process if pid := os.Getpid(); pid != 1 { + logrus.WithFields(logrus.Fields{ + "pid": pid, + }).Debug("containerd is not init, set as subreaper") if err := setSubReaper(); err != nil { return err } diff --git a/containerd/reap_linux.go b/containerd/reap_linux.go index 33a5447..d739287 100644 --- a/containerd/reap_linux.go +++ b/containerd/reap_linux.go @@ -14,7 +14,9 @@ import ( ) func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) { - logrus.Debug("containerd: starting signal handler") + logrus.WithFields(logrus.Fields{ + "bufferSize": bufferSize, + }).Debug("containerd: starting signal handler") signals := make(chan os.Signal, bufferSize) signal.Notify(signals) for s := range signals { diff --git a/linux/linux.go b/linux/linux.go index 0c35a58..3410bc3 100644 --- a/linux/linux.go +++ b/linux/linux.go @@ -15,6 +15,7 @@ import ( "syscall" "time" + "github.com/Sirupsen/logrus" "github.com/docker/containerd/runtime" "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/configs" @@ -356,6 +357,10 @@ type libcontainerRuntime struct { factory libcontainer.Factory } +func (r *libcontainerRuntime) Type() string { + return "libcontainer" +} + func (r *libcontainerRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runtime.Container, error) { spec, rspec, err := r.loadSpec( filepath.Join(bundlePath, "config.json"), @@ -364,13 +369,17 @@ func (r *libcontainerRuntime) Create(id, bundlePath string, stdio *runtime.Stdio if err != nil { return nil, err } + logrus.WithFields(logrus.Fields{ + "id": id, + "bundlePath": bundlePath, + }).Debugf("create container") config, err := r.createLibcontainerConfig(id, bundlePath, spec, rspec) if err != nil { return nil, err } container, err := r.factory.Create(id, config) if err != nil { - return nil, err + return nil, fmt.Errorf("create container: %v", err) } process, err := r.newProcess(spec.Process, stdio) if err != nil { @@ -422,14 +431,14 @@ func (r *libcontainerRuntime) newProcess(p specs.Process, stdio *runtime.Stdio) if stdio.Stdout != "" { f, err := os.OpenFile(stdio.Stdout, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { - return nil, err + return nil, fmt.Errorf("open stdout: %v", err) } stdout = f } if stdio.Stderr != "" { f, err := os.OpenFile(stdio.Stderr, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { - return nil, err + return nil, fmt.Errorf("open stderr: %v", err) } stderr = f } @@ -467,10 +476,10 @@ func (r *libcontainerRuntime) loadSpec(cPath, rPath string) (spec *specs.LinuxSp defer rf.Close() if err = json.NewDecoder(cf).Decode(&spec); err != nil { - return spec, rspec, err + return spec, rspec, fmt.Errorf("unmarshal %s: %v", cPath, err) } if err = json.NewDecoder(rf).Decode(&rspec); err != nil { - return spec, rspec, err + return spec, rspec, fmt.Errorf("unmarshal %s: %v", rPath, err) } return spec, rspec, r.checkSpecVersion(spec) } diff --git a/runc/runc.go b/runc/runc.go index bcf6eaa..c5520ea 100644 --- a/runc/runc.go +++ b/runc/runc.go @@ -139,6 +139,10 @@ type runcRuntime struct { stateDir string } +func (r *runcRuntime) Type() string { + return "runc" +} + func (r *runcRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runtime.Container, error) { cmd := exec.Command("runc", "--root", r.stateDir, "--id", id, "start") cmd.Dir = bundlePath diff --git a/runtime/runtime.go b/runtime/runtime.go index 5a81193..883d7c4 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -20,4 +20,5 @@ type Runtime interface { Create(id, bundlePath string, stdio *Stdio) (Container, error) // StartProcess adds a new process to the container StartProcess(Container, specs.Process, *Stdio) (Process, error) + Type() string } diff --git a/supervisor.go b/supervisor.go index d411a30..9291c68 100644 --- a/supervisor.go +++ b/supervisor.go @@ -133,6 +133,12 @@ func (s *Supervisor) Start() error { // so that nothing else is scheduled over the top of it. goruntime.LockOSThread() for e := range s.events { + logrus.WithFields(logrus.Fields{ + "type": e.Type, + "timestamp": e.Timestamp, + "id": e.ID, + "bundlePath": e.BundlePath, + }).Debug("event received") EventsCounter.Inc(1) h, ok := s.handlers[e.Type] if !ok { @@ -149,6 +155,10 @@ func (s *Supervisor) Start() error { close(e.Err) } }() + logrus.WithFields(logrus.Fields{ + "runtime": s.runtime.Type(), + "stateDir": s.stateDir, + }).Debug("Supervisor started") return nil } diff --git a/worker.go b/worker.go index d77ebef..244b91e 100644 --- a/worker.go +++ b/worker.go @@ -4,6 +4,7 @@ import ( "sync" "time" + "github.com/Sirupsen/logrus" "github.com/docker/containerd/runtime" ) @@ -33,6 +34,11 @@ func (w *worker) Start() { defer w.wg.Done() for t := range w.s.tasks { started := time.Now() + logrus.WithFields(logrus.Fields{ + "containerID": t.Container.ID(), + "checkpoint": t.Checkpoint, + "started": started, + }).Debug("worker received task") if t.Checkpoint != "" { if err := t.Container.Restore(t.Checkpoint); err != nil { evt := NewEvent(DeleteEventType)