From 188eeae376b2729ffa38e8a1db9bf5b2ba6bb829 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Wed, 16 Dec 2015 09:39:28 -0800 Subject: [PATCH] Stop stats collection on container exit Signed-off-by: Alexander Morozov --- event.go | 3 ++- exit.go | 4 ++++ stats.go | 13 +++++++++++++ supervisor.go | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/event.go b/event.go index 4ab5041..c21ef6c 100644 --- a/event.go +++ b/event.go @@ -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" ) diff --git a/exit.go b/exit.go index e4858a8..3163878 100644 --- a/exit.go +++ b/exit.go @@ -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 } diff --git a/stats.go b/stats.go index 83d84ae..c4c23f8 100644 --- a/stats.go +++ b/stats.go @@ -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 { @@ -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 +} diff --git a/supervisor.go b/supervisor.go index 21ce252..2ac9a8c 100644 --- a/supervisor.go +++ b/supervisor.go @@ -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