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

Commit

Permalink
SDI-1394 a metric can be changed from static to dynamic by setting na…
Browse files Browse the repository at this point in the history
…me parameter
  • Loading branch information
candysmurf committed Jun 13, 2016
1 parent 5192dc4 commit 7754a41
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 78 deletions.
2 changes: 1 addition & 1 deletion control/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (mc *metricCatalog) removeMatchedKey(key string) {
func validateMetricNamespace(ns core.Namespace) error {
name := ""
for _, i := range ns {
name += i.Value
name += i.Value()
}
for _, chars := range notAllowedChars {
for _, ch := range chars {
Expand Down
36 changes: 36 additions & 0 deletions control/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,39 @@ func TestMetricNamespaceValidation(t *testing.T) {
})
})
}

func TestIsDynamicNamespace(t *testing.T) {
Convey("isDynamicNamespace()", t, func() {
Convey("has dynamic element", func() {
ns := core.NewNamespace("mock", "foo", "bar").AddDynamicElement("version", "the number of the version")
isDynamic, _ := ns.IsDynamic()
So(isDynamic, ShouldEqual, true)
})
Convey("has no dynamic element", func() {
ns := core.NewNamespace("mock", "foo").AddStaticElement("bar")
isDynamic, _ := ns.IsDynamic()
So(isDynamic, ShouldEqual, false)
})
Convey("is static but try to set name and desc", func() {
ns := core.NewNamespace("mock", "foo").AddStaticElement("bar")
nse := ns.Element(0)
nse.SetName("fake name")
nse.SetDescription("fake desc")
isDynamic, _ := ns.IsDynamic()
So(isDynamic, ShouldEqual, false)
})
Convey("is dynamic but try to change name and desc", func() {
ns := core.NewNamespace("mock", "foo").AddDynamicElement("bar", "the value of bar")
nse := ns.Element(2)
So(nse.Name(), ShouldEqual, "bar")
So(nse.Description(), ShouldEqual, "the value of bar")

nse.SetName("fake name")
nse.SetDescription("fake desc")
isDynamic, _ := ns.IsDynamic()
So(isDynamic, ShouldEqual, true)
So(nse.Name(), ShouldEqual, "fake name")
So(nse.Description(), ShouldEqual, "fake desc")
})
})
}
4 changes: 2 additions & 2 deletions control/mttrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (mtt *mttNode) Add(mt *metricType) {
if node.children == nil {
node.children = make(map[string]*mttNode)
}
node.children[n.Value] = &mttNode{}
node = node.children[n.Value]
node.children[n.Value()] = &mttNode{}
node = node.children[n.Value()]
}
node.mts = make(map[int]*metricType)
node.mts[mt.Version()] = mt
Expand Down
1 change: 1 addition & 0 deletions control/plugin/client/httpjsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (h *httpJSONRPCClient) GetMetricTypes(config plugin.ConfigType) ([]core.Met
if err != nil {
return nil, err
}

metrics := make([]core.Metric, len(mtr.MetricTypes))
for i, mt := range mtr.MetricTypes {
mt.LastAdvertisedTime_ = time.Now()
Expand Down
3 changes: 3 additions & 0 deletions control/plugin/client/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"crypto/rsa"
"encoding/gob"
"errors"
"fmt"
"net"
"net/rpc"
"time"
Expand Down Expand Up @@ -181,6 +182,8 @@ func (p *PluginNativeClient) GetMetricTypes(config plugin.ConfigType) ([]core.Me

args := plugin.GetMetricTypesArgs{PluginConfig: config}

fmt.Println("---args NATIVE---", args)

out, err := p.encoder.Encode(args)
if err != nil {
log.Error("error while encoding args for getmetrictypes :(")
Expand Down
2 changes: 1 addition & 1 deletion control/plugin/collector_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *mockPlugin) GetMetricTypes(cfg ConfigType) ([]MetricType, error) {
func (p *mockPlugin) CollectMetrics(mockMetricTypes []MetricType) ([]MetricType, error) {
for i := range mockMetricTypes {
if mockMetricTypes[i].Namespace().String() == "/foo/*/bar" {
mockMetricTypes[i].Namespace_[1].Value = "test"
mockMetricTypes[i].Namespace_[1].SetValue("test")
}
}
return mockMetricTypes, nil
Expand Down
4 changes: 2 additions & 2 deletions control/plugin/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func NewPluginConfigType() ConfigType {
// Represents a metric type. Only used within plugins and across plugin calls.
// Converted to core.MetricType before being used within modules.
type MetricType struct {
// Namespace is the identifier for a metric.
Namespace_ []core.NamespaceElement `json:"namespace"`
// Namespace_ is the identifier for a metric.
Namespace_ core.Namespace `json:"namespace"`

// Last advertised time is the last time the snap agent was told about
// a metric.
Expand Down
Loading

0 comments on commit 7754a41

Please sign in to comment.