Merge pull request #2216 from choury/master
Support multiple storage backends
This commit is contained in:
commit
9620b8cf93
8
cache/memory/memory.go
vendored
8
cache/memory/memory.go
vendored
@ -70,7 +70,7 @@ type InMemoryCache struct {
|
|||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
containerCacheMap map[string]*containerCache
|
containerCacheMap map[string]*containerCache
|
||||||
maxAge time.Duration
|
maxAge time.Duration
|
||||||
backend storage.StorageDriver
|
backend []storage.StorageDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *InMemoryCache) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error {
|
func (self *InMemoryCache) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error {
|
||||||
@ -86,11 +86,11 @@ func (self *InMemoryCache) AddStats(cInfo *info.ContainerInfo, stats *info.Conta
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if self.backend != nil {
|
for _, backend := range self.backend {
|
||||||
// TODO(monnand): To deal with long delay write operations, we
|
// TODO(monnand): To deal with long delay write operations, we
|
||||||
// may want to start a pool of goroutines to do write
|
// may want to start a pool of goroutines to do write
|
||||||
// operations.
|
// operations.
|
||||||
if err := self.backend.AddStats(cInfo, stats); err != nil {
|
if err := backend.AddStats(cInfo, stats); err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (self *InMemoryCache) RemoveContainer(containerName string) error {
|
|||||||
|
|
||||||
func New(
|
func New(
|
||||||
maxAge time.Duration,
|
maxAge time.Duration,
|
||||||
backend storage.StorageDriver,
|
backend []storage.StorageDriver,
|
||||||
) *InMemoryCache {
|
) *InMemoryCache {
|
||||||
ret := &InMemoryCache{
|
ret := &InMemoryCache{
|
||||||
containerCacheMap: make(map[string]*containerCache, 32),
|
containerCacheMap: make(map[string]*containerCache, 32),
|
||||||
|
@ -34,19 +34,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
storageDriver = flag.String("storage_driver", "", fmt.Sprintf("Storage `driver` to use. Data is always cached shortly in memory, this controls where data is pushed besides the local cache. Empty means none. Options are: <empty>, %s", strings.Join(storage.ListDrivers(), ", ")))
|
storageDriver = flag.String("storage_driver", "", fmt.Sprintf("Storage `driver` to use. Data is always cached shortly in memory, this controls where data is pushed besides the local cache. Empty means none, multiple separated by commas. Options are: <empty>, %s", strings.Join(storage.ListDrivers(), ", ")))
|
||||||
storageDuration = flag.Duration("storage_duration", 2*time.Minute, "How long to keep data stored (Default: 2min).")
|
storageDuration = flag.Duration("storage_duration", 2*time.Minute, "How long to keep data stored (Default: 2min).")
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMemoryStorage creates a memory storage with an optional backend storage option.
|
// NewMemoryStorage creates a memory storage with an optional backend storage option.
|
||||||
func NewMemoryStorage() (*memory.InMemoryCache, error) {
|
func NewMemoryStorage() (*memory.InMemoryCache, error) {
|
||||||
backendStorage, err := storage.New(*storageDriver)
|
backendStorages := []storage.StorageDriver{}
|
||||||
if err != nil {
|
for _, driver := range strings.Split(*storageDriver, ",") {
|
||||||
return nil, err
|
if driver == "" {
|
||||||
}
|
continue
|
||||||
if *storageDriver != "" {
|
}
|
||||||
klog.V(1).Infof("Using backend storage type %q", *storageDriver)
|
storage, err := storage.New(driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
backendStorages = append(backendStorages, storage)
|
||||||
|
klog.V(1).Infof("Using backend storage type %q", driver)
|
||||||
}
|
}
|
||||||
klog.V(1).Infof("Caching stats in memory for %v", *storageDuration)
|
klog.V(1).Infof("Caching stats in memory for %v", *storageDuration)
|
||||||
return memory.New(*storageDuration, backendStorage), nil
|
return memory.New(*storageDuration, backendStorages), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user