Skip to content

Commit

Permalink
agent: add grpc endpoint to retrieve oom events
Browse files Browse the repository at this point in the history
fixes kata-containers#751

Signed-off-by: Alex Price <[email protected]>
  • Loading branch information
awprice committed Mar 3, 2020
1 parent d40e3d0 commit f56fcc3
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 180 deletions.
15 changes: 15 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type sandbox struct {
sandboxPidNs bool
storages map[string]*sandboxStorage
stopServer chan struct{}
oomEvents chan string
}

var agentFields = logrus.Fields{
Expand Down Expand Up @@ -787,6 +788,19 @@ func (s *sandbox) listenToUdevEvents() {
}
}

func (s *sandbox) runOOMEventMonitor(ch <-chan struct{}, containerID string) {
go func() {
for {
_, ok := <-ch
if !ok {
return
}
agentLog.WithField("container_id", containerID).Info("Received OOM event")
s.oomEvents <- containerID
}
}()
}

// This loop is meant to be run inside a separate Go routine.
func (s *sandbox) signalHandlerLoop(sigCh chan os.Signal, errCh chan error) {
// Lock OS thread as subreaper is a thread local capability
Expand Down Expand Up @@ -1492,6 +1506,7 @@ func realMain() error {
deviceWatchers: make(map[string](chan string)),
storages: make(map[string]*sandboxStorage),
stopServer: make(chan struct{}),
oomEvents: make(chan string, 128),
}

rootSpan, rootContext, err = setupTracing(agentName)
Expand Down
12 changes: 12 additions & 0 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@ func (a *agentGRPC) StartContainer(ctx context.Context, req *pb.StartContainerRe
return emptyResp, err
}

// Add the container to the OOM event monitor
oomCh, err := ctr.container.NotifyOOM()
if err != nil {
return emptyResp, err
}
a.sandbox.runOOMEventMonitor(oomCh, req.ContainerId)

return emptyResp, nil
}

Expand Down Expand Up @@ -1791,3 +1798,8 @@ func (a *agentGRPC) StopTracing(ctx context.Context, req *pb.StopTracingRequest)

return emptyResp, nil
}

func (a *agentGRPC) GetOOMEvent(ctx context.Context, req *pb.GetOOMEventRequest) (*pb.OOMEvent, error) {
containerID := <-a.sandbox.oomEvents
return &pb.OOMEvent{ContainerId: containerID}, nil
}
Loading

0 comments on commit f56fcc3

Please sign in to comment.