Add oom notifications and pid to create response

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-15 16:22:53 -08:00
parent ec31245f54
commit 76cf593212
13 changed files with 269 additions and 128 deletions

View file

@ -37,6 +37,7 @@ func (s *apiServer) CreateContainer(ctx context.Context, c *types.CreateContaine
e.Stderr = c.Stderr e.Stderr = c.Stderr
e.Stdin = c.Stdin e.Stdin = c.Stdin
e.Console = c.Console e.Console = c.Console
e.StartResponse = make(chan containerd.StartResponse, 1)
if c.Checkpoint != "" { if c.Checkpoint != "" {
e.Checkpoint = &runtime.Checkpoint{ e.Checkpoint = &runtime.Checkpoint{
Name: c.Checkpoint, Name: c.Checkpoint,
@ -46,7 +47,10 @@ func (s *apiServer) CreateContainer(ctx context.Context, c *types.CreateContaine
if err := <-e.Err; err != nil { if err := <-e.Err; err != nil {
return nil, err return nil, err
} }
return &types.CreateContainerResponse{}, nil sr := <-e.StartResponse
return &types.CreateContainerResponse{
Pid: uint32(sr.Pid),
}, nil
} }
func (s *apiServer) Signal(ctx context.Context, r *types.SignalRequest) (*types.SignalResponse, error) { func (s *apiServer) Signal(ctx context.Context, r *types.SignalRequest) (*types.SignalResponse, error) {
@ -223,18 +227,27 @@ func (s *apiServer) Events(r *types.EventsRequest, stream types.API_EventsServer
events := s.sv.Events() events := s.sv.Events()
defer s.sv.Unsubscribe(events) defer s.sv.Unsubscribe(events)
for evt := range events { for evt := range events {
var ev *types.Event
switch evt.Type { switch evt.Type {
case containerd.ExitEventType, containerd.ExecExitEventType: case containerd.ExitEventType, containerd.ExecExitEventType:
ev := &types.Event{ ev = &types.Event{
Type: "exit", Type: "exit",
Id: evt.ID, Id: evt.ID,
Pid: uint32(evt.Pid), Pid: uint32(evt.Pid),
Status: uint32(evt.Status), Status: uint32(evt.Status),
} }
case containerd.OOMEventType:
ev = &types.Event{
Type: "oom",
Id: evt.ID,
}
}
if ev != nil {
if err := stream.Send(ev); err != nil { if err := stream.Send(ev); err != nil {
return err return err
} }
} }
} }
return nil return nil
} }

View file

@ -78,6 +78,7 @@ func (*CreateContainerRequest) ProtoMessage() {}
func (*CreateContainerRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } func (*CreateContainerRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type CreateContainerResponse struct { type CreateContainerResponse struct {
Pid uint32 `protobuf:"varint,1,opt,name=pid" json:"pid,omitempty"`
} }
func (m *CreateContainerResponse) Reset() { *m = CreateContainerResponse{} } func (m *CreateContainerResponse) Reset() { *m = CreateContainerResponse{} }
@ -1086,96 +1087,96 @@ var _API_serviceDesc = grpc.ServiceDesc{
} }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 1450 bytes of a gzipped FileDescriptorProto // 1454 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x58, 0xe9, 0x6e, 0x1c, 0x45, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x58, 0xd9, 0x6e, 0x1c, 0x45,
0x10, 0xf6, 0xee, 0xce, 0x5e, 0xb5, 0x87, 0xed, 0x71, 0xec, 0xac, 0x17, 0x42, 0x92, 0x21, 0x40, 0x17, 0xf6, 0xcc, 0xf4, 0x6c, 0x67, 0x16, 0xdb, 0xed, 0xd8, 0x19, 0xcf, 0xff, 0x87, 0x24, 0x4d,
0x84, 0x22, 0x2b, 0x38, 0x1c, 0x21, 0xfc, 0x80, 0xe0, 0x44, 0x09, 0x28, 0x01, 0x2b, 0xb1, 0x91, 0x08, 0x11, 0x8a, 0xac, 0xe0, 0xb0, 0x84, 0x70, 0x01, 0xc1, 0x89, 0x12, 0x50, 0x02, 0x56, 0x62,
0xf8, 0xc3, 0x6a, 0x3c, 0xd3, 0xac, 0x9b, 0x9d, 0x8b, 0x99, 0x1e, 0x1f, 0xaf, 0x80, 0x78, 0x1c,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x8b, 0xba, 0x29, 0x23, 0x43, 0x10, 0x00, 0x00, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa6, 0xf1, 0xd0, 0x3c, 0x50, 0x10, 0x00, 0x00,
} }

View file

@ -26,6 +26,7 @@ message CreateContainerRequest {
} }
message CreateContainerResponse { message CreateContainerResponse {
uint32 pid = 1; // PID of the containers main process
} }
message SignalRequest { message SignalRequest {

View file

@ -62,6 +62,10 @@ var daemonFlags = []cli.Flag{
Value: "/run/containerd/containerd.sock", Value: "/run/containerd/containerd.sock",
Usage: "Address on which GRPC API will listen", Usage: "Address on which GRPC API will listen",
}, },
cli.BoolFlag{
Name: "oom-notify",
Usage: "enable oom notifications for containers",
},
} }
func main() { func main() {
@ -89,6 +93,7 @@ func main() {
context.String("listen"), context.String("listen"),
context.String("state-dir"), context.String("state-dir"),
context.Int("concurrency"), context.Int("concurrency"),
context.Bool("oom-notify"),
); err != nil { ); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -146,9 +151,9 @@ func processMetrics() {
}() }()
} }
func daemon(id, address, stateDir string, concurrency int) error { func daemon(id, address, stateDir string, concurrency int, oom bool) error {
tasks := make(chan *containerd.StartTask, concurrency*100) tasks := make(chan *containerd.StartTask, concurrency*100)
supervisor, err := containerd.NewSupervisor(id, stateDir, tasks) supervisor, err := containerd.NewSupervisor(id, stateDir, tasks, oom)
if err != nil { if err != nil {
return err return err
} }

View file

@ -15,12 +15,13 @@ func (h *StartEvent) Handle(e *Event) error {
} }
ContainersCounter.Inc(1) ContainersCounter.Inc(1)
task := &StartTask{ task := &StartTask{
Err: e.Err, Err: e.Err,
IO: io, IO: io,
Container: container, Container: container,
Stdin: e.Stdin, Stdin: e.Stdin,
Stdout: e.Stdout, Stdout: e.Stdout,
Stderr: e.Stderr, Stderr: e.Stderr,
StartResponse: e.StartResponse,
} }
if e.Checkpoint != nil { if e.Checkpoint != nil {
task.Checkpoint = e.Checkpoint.Name task.Checkpoint = e.Checkpoint.Name

View file

@ -121,7 +121,8 @@ var StartCommand = cli.Command{
} }
} }
} }
if _, err := c.CreateContainer(netcontext.Background(), r); err != nil { resp, err := c.CreateContainer(netcontext.Background(), r)
if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }
if context.Bool("attach") { if context.Bool("attach") {
@ -140,6 +141,8 @@ var StartCommand = cli.Command{
os.Exit(int(e.Status)) os.Exit(int(e.Status))
} }
} }
} else {
fmt.Println(resp.Pid)
} }
}, },
} }

View file

@ -23,6 +23,7 @@ const (
DeleteCheckpointEventType EventType = "deleteCheckpoint" DeleteCheckpointEventType EventType = "deleteCheckpoint"
StatsEventType EventType = "events" StatsEventType EventType = "events"
UnsubscribeStatsEventType EventType = "unsubscribeEvents" UnsubscribeStatsEventType EventType = "unsubscribeEvents"
OOMEventType EventType = "oom"
) )
func NewEvent(t EventType) *Event { func NewEvent(t EventType) *Event {
@ -33,24 +34,29 @@ func NewEvent(t EventType) *Event {
} }
} }
type StartResponse struct {
Pid int
}
type Event struct { type Event struct {
Type EventType Type EventType
Timestamp time.Time Timestamp time.Time
ID string ID string
BundlePath string BundlePath string
Stdout string Stdout string
Stderr string Stderr string
Stdin string Stdin string
Console string Console string
Pid int Pid int
Status int Status int
Signal os.Signal Signal os.Signal
Process *specs.Process Process *specs.Process
State *runtime.State State *runtime.State
Containers []runtime.Container Containers []runtime.Container
Checkpoint *runtime.Checkpoint Checkpoint *runtime.Checkpoint
Err chan error Err chan error
Stats chan interface{} StartResponse chan StartResponse
Stats chan interface{}
} }
type Handler interface { type Handler interface {

View file

@ -363,6 +363,10 @@ func (c *libcontainerContainer) RemoveProcess(pid int) error {
return err return err
} }
func (c *libcontainerContainer) OOM() (<-chan struct{}, error) {
return c.c.NotifyOOM()
}
func NewRuntime(stateDir string) (runtime.Runtime, error) { func NewRuntime(stateDir string) (runtime.Runtime, error) {
f, err := libcontainer.New(stateDir, libcontainer.Cgroupfs, func(l *libcontainer.LinuxFactory) error { f, err := libcontainer.New(stateDir, libcontainer.Cgroupfs, func(l *libcontainer.LinuxFactory) error {
//l.CriuPath = context.GlobalString("criu") //l.CriuPath = context.GlobalString("criu")

80
oom.go Normal file
View file

@ -0,0 +1,80 @@
package containerd
import (
"reflect"
"sync"
)
func newNotifier(s *Supervisor) *notifier {
n := &notifier{
s: s,
channels: make(map[<-chan struct{}]string),
controller: make(chan struct{}),
}
go n.start()
return n
}
type notifier struct {
m sync.Mutex
channels map[<-chan struct{}]string
controller chan struct{}
s *Supervisor
}
func (n *notifier) start() {
for {
c := n.createCase()
i, _, ok := reflect.Select(c)
if i == 0 {
continue
}
if ok {
ch := c[i].Chan.Interface().(<-chan struct{})
id := n.channels[ch]
e := NewEvent(OOMEventType)
e.ID = id
n.s.SendEvent(e)
continue
}
// the channel was closed and we should remove it
ch := c[i].Chan.Interface().(<-chan struct{})
n.removeChan(ch)
}
}
func (n *notifier) Add(ch <-chan struct{}, id string) {
n.m.Lock()
n.channels[ch] = id
n.m.Unlock()
// signal the main loop to break and add the new
// channels
n.controller <- struct{}{}
}
func (n *notifier) createCase() []reflect.SelectCase {
var out []reflect.SelectCase
// add controller chan so that we can signal when we need to make
// changes in the select. The controller chan will always be at
// index 0 in the slice
out = append(out, reflect.SelectCase{
Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(n.controller),
})
n.m.Lock()
for ch := range n.channels {
v := reflect.ValueOf(ch)
out = append(out, reflect.SelectCase{
Dir: reflect.SelectRecv,
Chan: v,
})
}
n.m.Unlock()
return out
}
func (n *notifier) removeChan(ch <-chan struct{}) {
n.m.Lock()
delete(n.channels, ch)
n.m.Unlock()
}

View file

@ -111,6 +111,10 @@ func (c *runcContainer) Checkpoints() ([]runtime.Checkpoint, error) {
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
func (c *runcContainer) OOM() (<-chan struct{}, error) {
return nil, errors.New("not implemented")
}
func (c *runcContainer) newCommand(args ...string) *exec.Cmd { func (c *runcContainer) newCommand(args ...string) *exec.Cmd {
cmd := exec.Command("runc", append([]string{"--root", c.stateDir, "--id", c.id}, args...)...) cmd := exec.Command("runc", append([]string{"--root", c.stateDir, "--id", c.id}, args...)...)
cmd.Dir = c.path cmd.Dir = c.path

View file

@ -111,4 +111,6 @@ type Container interface {
Restore(name string) error Restore(name string) error
// Stats returns realtime container stats and resource information // Stats returns realtime container stats and resource information
Stats() (*Stat, error) Stats() (*Stat, error)
// OOM signals the channel if the container received an OOM notification
OOM() (<-chan struct{}, error)
} }

View file

@ -17,7 +17,7 @@ import (
const statsInterval = 1 * time.Second const statsInterval = 1 * time.Second
// NewSupervisor returns an initialized Process supervisor. // NewSupervisor returns an initialized Process supervisor.
func NewSupervisor(id, stateDir string, tasks chan *StartTask) (*Supervisor, error) { func NewSupervisor(id, stateDir string, tasks chan *StartTask, oom bool) (*Supervisor, error) {
if err := os.MkdirAll(stateDir, 0755); err != nil { if err := os.MkdirAll(stateDir, 0755); err != nil {
return nil, err return nil, err
} }
@ -41,6 +41,9 @@ func NewSupervisor(id, stateDir string, tasks chan *StartTask) (*Supervisor, err
subscribers: make(map[chan *Event]struct{}), subscribers: make(map[chan *Event]struct{}),
statsCollector: newStatsCollector(statsInterval), statsCollector: newStatsCollector(statsInterval),
} }
if oom {
s.notifier = newNotifier(s)
}
// register default event handlers // register default event handlers
s.handlers = map[EventType]Handler{ s.handlers = map[EventType]Handler{
ExecExitEventType: &ExecExitEvent{s}, ExecExitEventType: &ExecExitEvent{s},
@ -81,6 +84,7 @@ type Supervisor struct {
machine Machine machine Machine
containerGroup sync.WaitGroup containerGroup sync.WaitGroup
statsCollector *statsCollector statsCollector *statsCollector
notifier *notifier
} }
// Stop closes all tasks and sends a SIGTERM to each container's pid1 then waits for they to // Stop closes all tasks and sends a SIGTERM to each container's pid1 then waits for they to

View file

@ -4,6 +4,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/Sirupsen/logrus"
"github.com/docker/containerd/runtime" "github.com/docker/containerd/runtime"
) )
@ -12,13 +13,14 @@ type Worker interface {
} }
type StartTask struct { type StartTask struct {
Container runtime.Container Container runtime.Container
Checkpoint string Checkpoint string
IO *runtime.IO IO *runtime.IO
Stdin string Stdin string
Stdout string Stdout string
Stderr string Stderr string
Err chan error Err chan error
StartResponse chan StartResponse
} }
func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker { func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker {
@ -63,7 +65,22 @@ func (w *worker) Start() {
continue continue
} }
} }
pid, err := t.Container.Pid()
if err != nil {
logrus.WithField("error", err).Error("containerd: get container main pid")
}
if w.s.notifier != nil {
n, err := t.Container.OOM()
if err != nil {
logrus.WithField("error", err).Error("containerd: notify OOM events")
} else {
w.s.notifier.Add(n, t.Container.ID())
}
}
ContainerStartTimer.UpdateSince(started) ContainerStartTimer.UpdateSince(started)
t.Err <- nil t.Err <- nil
t.StartResponse <- StartResponse{
Pid: pid,
}
} }
} }