From 675c09e296b4bd4ff4efef878f95095b024c87f6 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Wed, 10 Jun 2015 07:53:46 -0700 Subject: [PATCH] Remove stats from cache when container is destroyed --- cache/cache.go | 4 ++++ cache/memory/memory.go | 7 +++++++ manager/container.go | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/cache/cache.go b/cache/cache.go index 16ea5fe1..4b2b5880 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -17,8 +17,12 @@ package cache import info "github.com/google/cadvisor/info/v1" type Cache interface { + // Add a ContainerStats for the specified container. AddStats(ref info.ContainerReference, stats *info.ContainerStats) error + // Remove all cached information for the specified container. + RemoveContainer(containerName string) error + // Read most recent stats. numStats indicates max number of stats // returned. The returned stats must be consecutive observed stats. If // numStats < 0, then return all stats stored in the storage. The diff --git a/cache/memory/memory.go b/cache/memory/memory.go index 603cf0c3..d3c23dcf 100644 --- a/cache/memory/memory.go +++ b/cache/memory/memory.go @@ -118,6 +118,13 @@ func (self *InMemoryCache) Close() error { return nil } +func (self *InMemoryCache) RemoveContainer(containerName string) error { + self.lock.Lock() + delete(self.containerCacheMap, containerName) + self.lock.Unlock() + return nil +} + func New( maxAge time.Duration, backend storage.StorageDriver, diff --git a/manager/container.go b/manager/container.go index e19e8b5c..5498c674 100644 --- a/manager/container.go +++ b/manager/container.go @@ -81,6 +81,10 @@ func (c *containerData) Start() error { } func (c *containerData) Stop() error { + err := c.memoryCache.RemoveContainer(c.info.Name) + if err != nil { + return err + } c.stop <- true return nil }