report error if there's a nil storage driver
This commit is contained in:
parent
e65fc89270
commit
e18c7fbf8f
@ -17,6 +17,7 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
@ -81,6 +82,9 @@ func (c *containerData) GetInfo() (*containerInfo, error) {
|
||||
}
|
||||
|
||||
func NewContainerData(containerName string, driver storage.StorageDriver) (*containerData, error) {
|
||||
if driver == nil {
|
||||
return nil, fmt.Errorf("nil storage driver")
|
||||
}
|
||||
cont := &containerData{}
|
||||
handler, err := container.NewContainerHandler(containerName)
|
||||
if err != nil {
|
||||
@ -147,15 +151,13 @@ func (c *containerData) updateStats() error {
|
||||
if stats == nil {
|
||||
return nil
|
||||
}
|
||||
if c.storageDriver != nil {
|
||||
ref, err := c.handler.ContainerReference()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.storageDriver.AddStats(ref, stats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ref, err := c.handler.ContainerReference()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.storageDriver.AddStats(ref, stats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ type Manager interface {
|
||||
}
|
||||
|
||||
func New(driver storage.StorageDriver) (Manager, error) {
|
||||
if driver == nil {
|
||||
return nil, fmt.Errorf("nil storage driver!")
|
||||
}
|
||||
newManager := &manager{}
|
||||
newManager.containers = make(map[string]*containerData)
|
||||
|
||||
@ -127,25 +130,23 @@ func (m *manager) GetContainerInfo(containerName string) (*info.ContainerInfo, e
|
||||
var percentiles *info.ContainerStatsPercentiles
|
||||
var samples []*info.ContainerStatsSample
|
||||
var stats []*info.ContainerStats
|
||||
if m.storageDriver != nil {
|
||||
// XXX(monnand): These numbers should not be hard coded
|
||||
percentiles, err = m.storageDriver.Percentiles(
|
||||
cinfo.Name,
|
||||
[]int{50, 80, 90, 99},
|
||||
[]int{50, 80, 90, 99},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
samples, err = m.storageDriver.Samples(cinfo.Name, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO(monnand): These numbers should not be hard coded
|
||||
percentiles, err = m.storageDriver.Percentiles(
|
||||
cinfo.Name,
|
||||
[]int{50, 80, 90, 99},
|
||||
[]int{50, 80, 90, 99},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
samples, err = m.storageDriver.Samples(cinfo.Name, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stats, err = m.storageDriver.RecentStats(cinfo.Name, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stats, err = m.storageDriver.RecentStats(cinfo.Name, 1024)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make a copy of the info for the user.
|
||||
|
Loading…
Reference in New Issue
Block a user