Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Fixes #1229: Empty metric catalog no longer errors #1232

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions control/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ import (
)

var (
errMetricNotFound = errors.New("metric not found")
errEmptyMetricCatalog = errors.New("metric catalog is empty, no plugin loaded")
errNegativeSubCount = serror.New(errors.New("subscription count cannot be < 0"))
hostnameReader hostnamer
errMetricNotFound = errors.New("metric not found")
errNegativeSubCount = serror.New(errors.New("subscription count cannot be < 0"))
hostnameReader hostnamer
)

// hostnameReader, hostnamer created for mocking
Expand Down Expand Up @@ -96,10 +95,6 @@ func errorMetricNotFound(ns string, ver ...int) error {
}

func errorMetricsNotFound(ns string, ver ...int) error {
if ns == "/" {
// when fetching all cataloged metrics failed
return errEmptyMetricCatalog
}
if len(ver) > 0 {
return fmt.Errorf("No metric found below the given namespace: %s (version: %d)", ns, ver[0])
}
Expand Down Expand Up @@ -428,9 +423,7 @@ func (mc *metricCatalog) GetMetrics(requested core.Namespace, version int) ([]*m
returnedmts = append(returnedmts, returnedmt)
}
}
if len(returnedmts) == 0 {
return nil, errorMetricsNotFound(requested.String(), version)
}

return returnedmts, nil
}

Expand Down
2 changes: 1 addition & 1 deletion control/mttrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (mtt *mttNode) Fetch(ns []string) ([]*metricType, error) {
mts = append(mts, mt)
}
}
if len(mts) == 0 {
if len(mts) == 0 && len(ns) > 0 {
return nil, errorMetricsNotFound("/" + strings.Join(ns, "/"))
}
return mts, nil
Expand Down
3 changes: 1 addition & 2 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ func TestSnapClient(t *testing.T) {
})
Convey("empty catalog", func() {
m := c.GetMetricCatalog()
So(m.Err, ShouldNotBeNil)
So(m.Err, ShouldBeNil)
So(m.Len(), ShouldEqual, 0)
So(m.Err.Error(), ShouldEqual, "metric catalog is empty, no plugin loaded")
})
Convey("load directory error", func() {
p := c.LoadPlugin(DIRECTORY_PATH)
Expand Down