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

Commit

Permalink
Fixes #1229: Empty metric catalog no longer errors
Browse files Browse the repository at this point in the history
Empty metric catalog no longer logs or returns an error when queried
via the rest API (or any other method). Will instead return an empty
list of metrics, leaving choice of how to display that to the caller.

Removes the empty metric catalog error and modifies client_func_test to
reflect the changes in behavior.
  • Loading branch information
IRCody committed Sep 22, 2016
1 parent cc27afd commit b6427d0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
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

0 comments on commit b6427d0

Please sign in to comment.