adding error output to NewInformerWithMetric
This commit is contained in:
parent
32984611ec
commit
456603f7a8
|
@ -54,15 +54,15 @@ func NewInformer(name string) *Informer {
|
||||||
|
|
||||||
// NewInformerWithMetric returns an Informer that uses the input MetricType. The
|
// NewInformerWithMetric returns an Informer that uses the input MetricType. The
|
||||||
// name argument has the same purpose as in NewInformer.
|
// name argument has the same purpose as in NewInformer.
|
||||||
func NewInformerWithMetric(metric MetricType, name string) *Informer {
|
func NewInformerWithMetric(metric MetricType, name string) (*Informer, error) {
|
||||||
// check whether specified metric is supported
|
// check whether specified metric is supported
|
||||||
if rpc, valid := metricToRPC[metric]; valid {
|
if rpc, valid := metricToRPC[metric]; valid {
|
||||||
return &Informer{
|
return &Informer{
|
||||||
name: name,
|
name: name,
|
||||||
rpcName: rpc,
|
rpcName: rpc,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil, fmt.Error("Error creating Informer: invalid MetricType")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the user-facing name of this informer.
|
// Name returns the user-facing name of this informer.
|
||||||
|
|
|
@ -73,8 +73,8 @@ func Test(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFreeSpace(t *testing.T) {
|
func TestFreeSpace(t *testing.T) {
|
||||||
inf := NewInformerWithMetric(MetricFreeSpace, "disk-freespace")
|
inf, err := NewInformerWithMetric(MetricFreeSpace, "disk-freespace")
|
||||||
if inf == nil {
|
if err != nil {
|
||||||
t.Error("informer not initialized properly")
|
t.Error("informer not initialized properly")
|
||||||
}
|
}
|
||||||
defer inf.Shutdown()
|
defer inf.Shutdown()
|
||||||
|
@ -94,8 +94,8 @@ func TestFreeSpace(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepoSize(t *testing.T) {
|
func TestRepoSize(t *testing.T) {
|
||||||
inf := NewInformerWithMetric(MetricRepoSize, "disk-reposize")
|
inf, err := NewInformerWithMetric(MetricRepoSize, "disk-reposize")
|
||||||
if inf == nil {
|
if err != nil {
|
||||||
t.Error("informer not initialized properly")
|
t.Error("informer not initialized properly")
|
||||||
}
|
}
|
||||||
defer inf.Shutdown()
|
defer inf.Shutdown()
|
||||||
|
|
|
@ -349,10 +349,12 @@ func setupAllocation(name string) (ipfscluster.Informer, ipfscluster.PinAllocato
|
||||||
name = "disk-freespace"
|
name = "disk-freespace"
|
||||||
fallthrough
|
fallthrough
|
||||||
case "disk-freespace":
|
case "disk-freespace":
|
||||||
informer := disk.NewInformerWithMetric(disk.MetricFreeSpace, name)
|
informer, err := disk.NewInformerWithMetric(disk.MetricFreeSpace, name)
|
||||||
|
checkErr("Setting up allocation strategy", err)
|
||||||
return informer, descendalloc.NewAllocator()
|
return informer, descendalloc.NewAllocator()
|
||||||
case "disk-reposize":
|
case "disk-reposize":
|
||||||
informer := disk.NewInformerWithMetric(disk.MetricRepoSize, name)
|
informer, err := disk.NewInformerWithMetric(disk.MetricRepoSize, name)
|
||||||
|
checkErr("Setting up allocation strategy", err)
|
||||||
return informer, ascendalloc.NewAllocator()
|
return informer, ascendalloc.NewAllocator()
|
||||||
case "numpin", "pincount":
|
case "numpin", "pincount":
|
||||||
informer := numpin.NewInformer()
|
informer := numpin.NewInformer()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user