Remove stats from cache when container is destroyed
This commit is contained in:
parent
b0753a6d69
commit
675c09e296
4
cache/cache.go
vendored
4
cache/cache.go
vendored
@ -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
|
||||
|
7
cache/memory/memory.go
vendored
7
cache/memory/memory.go
vendored
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user