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

Commit

Permalink
Fixes #1550, checking number of namespace elements in requested metric
Browse files Browse the repository at this point in the history
  • Loading branch information
katarzyna-z committed Mar 15, 2017
1 parent 0b2c031 commit 89c7f33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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")
})
})
})
}

0 comments on commit 89c7f33

Please sign in to comment.