From cdac3ca125bbe2175472fc071d8e39e9470f5261 Mon Sep 17 00:00:00 2001 From: Joel Cooklin Date: Fri, 16 Oct 2015 16:34:44 -0700 Subject: [PATCH] Merges global plugin config when validating a task --- Makefile | 2 +- README.md | 2 +- cmd/pulsectl/README.md | 2 +- control/config.go | 19 ++++++ control/config_test.go | 19 ++++++ control/control.go | 13 ++++ control/control_test.go | 64 +++++++++++++------ control/plugin_manager_test.go | 2 +- docs/PULSED.md | 2 +- examples/README.md | 2 +- examples/influxdb-grafana/README.md | 2 +- examples/influxdb-grafana/influxdb/0.9/run.sh | 2 +- examples/influxdb-grafana/run-pcm.sh | 2 +- examples/influxdb-grafana/run-psutil.sh | 2 +- examples/influxdb-grafana/run.sh | 2 +- examples/linux_prep.sh | 2 +- examples/riemann/Vagrantfile | 2 +- examples/riemann/script/init.sh | 2 +- examples/tasks/README.md | 2 +- examples/videos.md | 2 +- mgmt/rest/client/README.md | 2 +- mgmt/rest/config.go | 2 +- mgmt/rest/rbody/config.go | 2 +- mgmt/rest/readme.md | 2 +- .../pulse-collector-dummy1/README.md | 2 +- .../pulse-collector-dummy2/README.md | 2 +- .../publisher/pulse-publisher-file/README.md | 2 +- scripts/build-plugin.sh | 2 +- scripts/build.sh | 2 +- scripts/deps.sh | 2 +- scripts/release.sh | 2 +- scripts/run_tests_with_docker.sh | 2 +- scripts/test.sh | 2 +- 33 files changed, 123 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 0abd12151..194bcee7e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index c6c8f8439..28c6d0ce3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cmd/pulsectl/README.md b/cmd/pulsectl/README.md index 120fadd8b..cdfee0678 100644 --- a/cmd/pulsectl/README.md +++ b/cmd/pulsectl/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/control/config.go b/control/config.go index 137cc605e..0b770e849 100644 --- a/control/config.go +++ b/control/config.go @@ -1,3 +1,22 @@ +/* +http://www.apache.org/licenses/LICENSE-2.0.txt + + +Copyright 2015 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package control import ( diff --git a/control/config_test.go b/control/config_test.go index 48cc15d33..09d79d982 100644 --- a/control/config_test.go +++ b/control/config_test.go @@ -1,3 +1,22 @@ +/* +http://www.apache.org/licenses/LICENSE-2.0.txt + + +Copyright 2015 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package control import ( diff --git a/control/control.go b/control/control.go index 1140b2566..ca9aa4252 100644 --- a/control/control.go +++ b/control/control.go @@ -348,6 +348,11 @@ func (p *pluginControl) ValidateDeps(mts []core.Metric, plugins []core.Subscribe //validate plugins for _, plg := range plugins { + typ, err := core.ToPluginType(plg.TypeName()) + if err != nil { + return []perror.PulseError{perror.New(err)} + } + plg.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(typ, plg.Name(), plg.Version())) errs := p.validatePluginSubscription(plg) if len(errs) > 0 { perrs = append(perrs, errs...) @@ -408,8 +413,16 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("no metric found cannot subscribe: (%s) version(%d)", mt.Namespace(), mt.Version())))) return nil, perrs } + m.config = cd + // merge global plugin config + typ, perr := core.ToPluginType(m.Plugin.TypeName()) + if perr != nil { + return nil, []perror.PulseError{perror.New(err)} + } + m.config.Merge(p.Config.Plugins.getPluginConfigDataNode(typ, m.Plugin.Name(), m.Plugin.Version())) + // When a metric is added to the MetricCatalog, the policy of rules defined by the plugin is added to the metric's policy. // If no rules are defined for a metric, we set the metric's policy to an empty ConfigPolicyNode. // Checking m.policy for nil will not work, we need to check if rules are nil. diff --git a/control/control_test.go b/control/control_test.go index 4168b79dc..08f87d9b6 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -658,26 +658,47 @@ func (m MockMetricType) Data() interface{} { } func TestMetricConfig(t *testing.T) { - c := New() - c.Start() - lpe := newListenToPluginEvent() - c.eventManager.RegisterHandler("Control.PluginLoaded", lpe) - c.Load(JSONRPC_PluginPath) - <-lpe.done - cd := cdata.NewNode() - m1 := MockMetricType{ - namespace: []string{"intel", "dummy", "foo"}, - } - metric, errs := c.validateMetricTypeSubscription(m1, cd) - Convey("So metric should not be valid without config", t, func() { - So(metric, ShouldBeNil) - So(errs, ShouldNotBeNil) + Convey("required config provided by task", t, func() { + c := New() + c.Start() + lpe := newListenToPluginEvent() + c.eventManager.RegisterHandler("Control.PluginLoaded", lpe) + c.Load(JSONRPC_PluginPath) + <-lpe.done + cd := cdata.NewNode() + m1 := MockMetricType{ + namespace: []string{"intel", "dummy", "foo"}, + } + metric, errs := c.validateMetricTypeSubscription(m1, cd) + Convey("So metric should not be valid without config", func() { + So(metric, ShouldBeNil) + So(errs, ShouldNotBeNil) + }) + cd.AddItem("password", ctypes.ConfigValueStr{Value: "testval"}) + metric, errs = c.validateMetricTypeSubscription(m1, cd) + Convey("So metric should be valid with config", func() { + So(errs, ShouldBeNil) + So(metric, ShouldNotBeNil) + }) }) - cd.AddItem("password", ctypes.ConfigValueStr{Value: "testval"}) - metric, errs = c.validateMetricTypeSubscription(m1, cd) - Convey("So metric should be valid with config", t, func() { - So(errs, ShouldBeNil) - So(metric, ShouldNotBeNil) + Convey("required config provided by global plugin config", t, func() { + config := NewConfig() + c := New(OptSetConfig(config)) + c.Start() + lpe := newListenToPluginEvent() + c.eventManager.RegisterHandler("Control.PluginLoaded", lpe) + c.Load(JSONRPC_PluginPath) + <-lpe.done + cd := cdata.NewNode() + m1 := MockMetricType{ + namespace: []string{"intel", "dummy", "foo"}, + } + config.Plugins.All.AddItem("password", ctypes.ConfigValueStr{Value: "testval"}) + metric, errs := c.validateMetricTypeSubscription(m1, cd) + Convey("So metric should be valid with config", func() { + So(errs, ShouldBeNil) + So(metric, ShouldNotBeNil) + }) }) } @@ -793,7 +814,8 @@ func TestPublishMetrics(t *testing.T) { plugin.PingTimeoutDurationDefault = time.Second * 1 // Create controller - c := New() + config := NewConfig() + c := New(OptSetConfig(config)) lpe := newListenToPluginEvent() c.eventManager.RegisterHandler("TestPublishMetrics", lpe) c.pluginRunner.(*runner).monitor.duration = time.Millisecond * 100 @@ -812,7 +834,7 @@ func TestPublishMetrics(t *testing.T) { Convey("Subscribe to file publisher with good config", func() { n := cdata.NewNode() - n.AddItem("file", ctypes.ConfigValueStr{Value: "/tmp/pulse-TestPublishMetrics.out"}) + config.Plugins.Publisher.Plugins[lp.Name()] = newPluginConfigItem(optAddPluginConfigItem("file", ctypes.ConfigValueStr{Value: "/tmp/pulse-TestPublishMetrics.out"})) p := mockPlugin{ name: "file", pluginType: core.PublisherPluginType, diff --git a/control/plugin_manager_test.go b/control/plugin_manager_test.go index c3daf8c6c..62cbeae1b 100644 --- a/control/plugin_manager_test.go +++ b/control/plugin_manager_test.go @@ -134,7 +134,7 @@ func TestLoadPlugin(t *testing.T) { Convey("loads plugin with cache TTL set", func() { p := newPluginManager() p.SetMetricCatalog(newMetricCatalog()) - lp, err := p.LoadPlugin(PluginPath, nil) + lp, err := p.LoadPlugin(JSONRPC_PluginPath, nil) So(err, ShouldBeNil) So(lp.Meta.CacheTTL, ShouldNotBeNil) diff --git a/docs/PULSED.md b/docs/PULSED.md index 0592f6712..0216a67fa 100644 --- a/docs/PULSED.md +++ b/docs/PULSED.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/examples/README.md b/examples/README.md index b956a3ee1..eeffe2f8a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/examples/influxdb-grafana/README.md b/examples/influxdb-grafana/README.md index ed524e9ea..8cab90c96 100644 --- a/examples/influxdb-grafana/README.md +++ b/examples/influxdb-grafana/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/examples/influxdb-grafana/influxdb/0.9/run.sh b/examples/influxdb-grafana/influxdb/0.9/run.sh index e2e8313eb..21ff8d8dd 100755 --- a/examples/influxdb-grafana/influxdb/0.9/run.sh +++ b/examples/influxdb-grafana/influxdb/0.9/run.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/influxdb-grafana/run-pcm.sh b/examples/influxdb-grafana/run-pcm.sh index 3e0d1185e..94468e4f5 100755 --- a/examples/influxdb-grafana/run-pcm.sh +++ b/examples/influxdb-grafana/run-pcm.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/influxdb-grafana/run-psutil.sh b/examples/influxdb-grafana/run-psutil.sh index 2a8093cad..dd9a4b72f 100755 --- a/examples/influxdb-grafana/run-psutil.sh +++ b/examples/influxdb-grafana/run-psutil.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/influxdb-grafana/run.sh b/examples/influxdb-grafana/run.sh index 91dcb6ae8..08452d596 100755 --- a/examples/influxdb-grafana/run.sh +++ b/examples/influxdb-grafana/run.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/linux_prep.sh b/examples/linux_prep.sh index fe90a29ee..174548a22 100755 --- a/examples/linux_prep.sh +++ b/examples/linux_prep.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/riemann/Vagrantfile b/examples/riemann/Vagrantfile index 2ee7173eb..7a11cc9db 100644 --- a/examples/riemann/Vagrantfile +++ b/examples/riemann/Vagrantfile @@ -1,7 +1,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/riemann/script/init.sh b/examples/riemann/script/init.sh index 4d4f424f1..1469ece8e 100755 --- a/examples/riemann/script/init.sh +++ b/examples/riemann/script/init.sh @@ -1,7 +1,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/examples/tasks/README.md b/examples/tasks/README.md index b9d539b58..92bcbf0ac 100644 --- a/examples/tasks/README.md +++ b/examples/tasks/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/examples/videos.md b/examples/videos.md index 8d0e15b5a..f19de1e7a 100644 --- a/examples/videos.md +++ b/examples/videos.md @@ -1,7 +1,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/mgmt/rest/client/README.md b/mgmt/rest/client/README.md index b5eeab4be..5c7b0790c 100644 --- a/mgmt/rest/client/README.md +++ b/mgmt/rest/client/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/mgmt/rest/config.go b/mgmt/rest/config.go index 8fa42c98f..96bc03ed5 100644 --- a/mgmt/rest/config.go +++ b/mgmt/rest/config.go @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/mgmt/rest/rbody/config.go b/mgmt/rest/rbody/config.go index cf1b77c06..c3d6ff96f 100644 --- a/mgmt/rest/rbody/config.go +++ b/mgmt/rest/rbody/config.go @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/mgmt/rest/readme.md b/mgmt/rest/readme.md index d48f966a3..f5ea28d86 100644 --- a/mgmt/rest/readme.md +++ b/mgmt/rest/readme.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/plugin/collector/pulse-collector-dummy1/README.md b/plugin/collector/pulse-collector-dummy1/README.md index 3ec6116d6..2f3fad991 100644 --- a/plugin/collector/pulse-collector-dummy1/README.md +++ b/plugin/collector/pulse-collector-dummy1/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/plugin/collector/pulse-collector-dummy2/README.md b/plugin/collector/pulse-collector-dummy2/README.md index 2c42efea7..5ea1fa411 100644 --- a/plugin/collector/pulse-collector-dummy2/README.md +++ b/plugin/collector/pulse-collector-dummy2/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/plugin/publisher/pulse-publisher-file/README.md b/plugin/publisher/pulse-publisher-file/README.md index 23a0b3ca3..26bd49a92 100644 --- a/plugin/publisher/pulse-publisher-file/README.md +++ b/plugin/publisher/pulse-publisher-file/README.md @@ -2,7 +2,7 @@ http://www.apache.org/licenses/LICENSE-2.0.txt -Copyright 2015 Intel Coporation +Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/scripts/build-plugin.sh b/scripts/build-plugin.sh index 257a94050..2069d3ae2 100755 --- a/scripts/build-plugin.sh +++ b/scripts/build-plugin.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/scripts/build.sh b/scripts/build.sh index c705174a0..9c1e3cb06 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/scripts/deps.sh b/scripts/deps.sh index 86addfd41..f2bf61b7b 100755 --- a/scripts/deps.sh +++ b/scripts/deps.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/scripts/release.sh b/scripts/release.sh index 63540d590..f25db3615 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/scripts/run_tests_with_docker.sh b/scripts/run_tests_with_docker.sh index adbd22aa8..436dc3634 100755 --- a/scripts/run_tests_with_docker.sh +++ b/scripts/run_tests_with_docker.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. diff --git a/scripts/test.sh b/scripts/test.sh index 2f620b324..8aa84b8d5 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,7 +3,7 @@ #http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Coporation +#Copyright 2015 Intel Corporation # #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License.