Skip to content

Commit

Permalink
Merge pull request containerd#32 from LK4D4/stop_collection
Browse files Browse the repository at this point in the history
Stop stats collection on container exit
  • Loading branch information
crosbymichael committed Dec 16, 2015
2 parents ab9be56 + 188eeae commit c35cf68
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
CreateCheckpointEventType EventType = "createCheckpoint"
DeleteCheckpointEventType EventType = "deleteCheckpoint"
StatsEventType EventType = "events"
UnsubscribeStatsEventType EventType = "unsubscribeEvents"
UnsubscribeStatsEventType EventType = "unsubscribeStats"
StopStatsEventType EventType = "stopStats"
OOMEventType EventType = "oom"
)

Expand Down
4 changes: 4 additions & 0 deletions exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (h *ExitEvent) Handle(e *Event) error {
ne.Pid = e.Pid
ne.Status = e.Status
h.s.SendEvent(ne)

stopCollect := NewEvent(StopStatsEventType)
stopCollect.ID = container.ID()
h.s.SendEvent(stopCollect)
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type UnsubscribeStatsEvent struct {
s *Supervisor
}

type StopStatsEvent struct {
s *Supervisor
}

func (h *StatsEvent) Handle(e *Event) error {
i, ok := h.s.containers[e.ID]
if !ok {
Expand All @@ -43,3 +47,12 @@ func (h *UnsubscribeStatsEvent) Handle(e *Event) error {
h.s.statsCollector.unsubscribe(i.container, e.Stats)
return nil
}

func (h *StopStatsEvent) Handle(e *Event) error {
i, ok := h.s.containers[e.ID]
if !ok {
return ErrContainerNotFound
}
h.s.statsCollector.stopCollection(i.container)
return nil
}
1 change: 1 addition & 0 deletions supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewSupervisor(id, stateDir string, tasks chan *StartTask, oom bool) (*Super
DeleteCheckpointEventType: &DeleteCheckpointEvent{s},
StatsEventType: &StatsEvent{s},
UnsubscribeStatsEventType: &UnsubscribeStatsEvent{s},
StopStatsEventType: &StopStatsEvent{s},
}
// start the container workers for concurrent container starts
return s, nil
Expand Down

0 comments on commit c35cf68

Please sign in to comment.