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

Fixes #1550, checking number of namespace elements in requested metric #1551

Merged
merged 1 commit into from
Mar 20, 2017
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
4 changes: 4 additions & 0 deletions control/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func errorMetricElementHasTuple(value, ns string) error {
return fmt.Errorf("A element %s should not define tuple for namespace %s.", value, ns)
}

func errorEmptyNamespace() error {
return fmt.Errorf("Incorrect format of requested metric, empty list of namespace elements")
}

type metricCatalogItem struct {
namespace string
versions map[int]core.Metric
Expand Down
7 changes: 7 additions & 0 deletions control/mttrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func (mtt *mttNode) GetMetrics(ns []string, ver int) ([]*metricType, error) {
nodes := []*mttNode{}
mts := []*metricType{}

if len(ns) == 0 {
return nil, errorEmptyNamespace()
}
// search returns all of the nodes fulfilling the 'ns'
// even for some of them there is no metric (empty node.mts)
nodes = mtt.search(nodes, ns)
Expand All @@ -220,6 +223,10 @@ func (mtt *mttNode) GetVersions(ns []string) ([]*metricType, error) {
var nodes []*mttNode
var mts []*metricType

if len(ns) == 0 {
return nil, errorEmptyNamespace()
}

nodes = mtt.search(nodes, ns)

for _, node := range nodes {
Expand Down
18 changes: 18 additions & 0 deletions control/mttrie_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ func TestTrie_GetMetric(t *testing.T) {
So(err.Error(), ShouldContainSubstring, "Metric not found: /intel/mock/*/invalid (version: -1)")
})
})

Convey("for incorrect format of namespace", func() {
Convey("error: incorrect format of requested metric", func() {
mt, err := trie.GetMetric([]string{}, 6)
So(err, ShouldNotBeNil)
So(mt, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Incorrect format of requested metric, empty list of namespace elements")
})
})
})
})
Convey("improper usage of GetMetric - requested namespace fulfills more than one metric's namespace", t, func() {
Expand Down Expand Up @@ -526,5 +535,14 @@ func TestTrie_GetVersions(t *testing.T) {
So(err.Error(), ShouldContainSubstring, "Metric not found: /invalid/*")
})
})

Convey("for incorrect format of namespace", func() {
Convey("error: incorrect format of requested metric", func() {
mts, err := trie.GetVersions([]string{})
So(err, ShouldNotBeNil)
So(mts, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Incorrect format of requested metric, empty list of namespace elements")
})
})
})
}