diff --git a/control/control.go b/control/control.go index da07ad9cf..906f253fe 100644 --- a/control/control.go +++ b/control/control.go @@ -422,12 +422,17 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric, 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())) + + // merge global plugin config + if m.config != nil { + m.config.Merge(p.Config.Plugins.getPluginConfigDataNode(typ, m.Plugin.Name(), m.Plugin.Version())) + } else { + m.config = 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. @@ -709,7 +714,9 @@ func (p *pluginControl) CollectMetrics(metricTypes []core.Metric, deadline time. // merge global plugin config into the config for the metric for _, mt := range pmt.metricTypes { - mt.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(core.CollectorPluginType, ap.Name(), ap.Version())) + if mt.Config() != nil { + mt.Config().Merge(p.Config.Plugins.getPluginConfigDataNode(core.CollectorPluginType, ap.Name(), ap.Version())) + } } // get a metrics @@ -823,7 +830,6 @@ func (p *pluginControl) ProcessMetrics(contentType string, content []byte, plugi // merge global plugin config into the config for this request cfg := p.Config.Plugins.getPluginConfigDataNode(core.ProcessorPluginType, ap.Name(), ap.Version()).Table() - for k, v := range config { cfg[k] = v } diff --git a/control/control_test.go b/control/control_test.go index 5e41b8a82..b00b4b1cb 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -713,6 +713,25 @@ func TestMetricConfig(t *testing.T) { So(metric, ShouldNotBeNil) }) }) + Convey("nil config provided by task", t, func() { + config := NewConfig() + c := New(OptSetConfig(config)) + c.Start() + lpe := newListenToPluginEvent() + c.eventManager.RegisterHandler("Control.PluginLoaded", lpe) + c.Load(JSONRPC_PluginPath) + <-lpe.done + var cd *cdata.ConfigDataNode + 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) + }) + }) Convey("required config provided by global plugin config", t, func() { config := NewConfig() c := New(OptSetConfig(config)) diff --git a/examples/influxdb-grafana/run-psutil.sh b/examples/influxdb-grafana/run-psutil.sh index dd9a4b72f..227dc29d7 100755 --- a/examples/influxdb-grafana/run-psutil.sh +++ b/examples/influxdb-grafana/run-psutil.sh @@ -28,11 +28,13 @@ command -v docker-machine >/dev/null 2>&1 || die "Error: docker-machine is requi command -v docker-compose >/dev/null 2>&1 || die "Error: docker-compose is required." command -v docker >/dev/null 2>&1 || die "Error: docker is required." command -v netcat >/dev/null 2>&1 || die "Error: netcat is required." +file $PULSE_PATH/plugin/pulse-plugin-collector-psutil >/dev/null 2>&1 || die "Error: missing $PULSE_PATH/build/plugin/pulse-plugin-collector-psutil" +file $PULSE_PATH/plugin/pulse-plugin-publisher-influxdb >/dev/null 2>&1 || die "Error: missing $PULSE_PATH/build/plugin/pulse-plugin-publisher-influxdb" #docker machine ip -dm_ip=$(docker-machine ip $1) || die +dm_ip=$(docker-machine ip $1) || die echo "docker machine ip: ${dm_ip}" #start containers @@ -41,13 +43,13 @@ docker-compose up -d echo -n "waiting for influxdb and grafana to start" # wait for influxdb to start up -while ! curl --silent -G "http://${dm_ip}:8086/query?u=admin&p=admin" --data-urlencode "q=SHOW DATABASES" 2>&1 > /dev/null ; do - sleep 1 +while ! curl --silent -G "http://${dm_ip}:8086/query?u=admin&p=admin" --data-urlencode "q=SHOW DATABASES" 2>&1 > /dev/null ; do + sleep 1 echo -n "." done echo "" -#influxdb IP +#influxdb IP influx_ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' influxdbgrafana_influxdb_1) echo "influxdb ip: ${influx_ip}" @@ -86,7 +88,7 @@ curl --cookie "$COOKIEJAR" \ echo "" echo -n "starting pulsed" -$PULSE_PATH/bin/pulsed --log-level 1 --auto-discover $PULSE_PATH/plugin > /tmp/pulse.out 2>&1 & +$PULSE_PATH/bin/pulsed --log-level 1 -t 0 --auto-discover $PULSE_PATH/plugin > /tmp/pulse.out 2>&1 & echo "" sleep 3 @@ -94,17 +96,13 @@ sleep 3 echo -n "adding task " TASK="${TMPDIR}/pulse-task-$$.json" echo "$TASK" -cat $PULSE_PATH/../examples/tasks/psutil-influx.json | sed s/INFLUXDB_IP/${dm_ip}/ > $TASK +cat $PULSE_PATH/../examples/tasks/psutil-influx.json | sed s/INFLUXDB_IP/${dm_ip}/ > $TASK $PULSE_PATH/bin/pulsectl task create -t $TASK -echo "start task" -$PULSE_PATH/bin/pulsectl task start 1 - echo "" echo "Grafana Dashboard => http://${dm_ip}:3000/dashboard/db/pulse-dashboard" echo "Influxdb UI => http://${dm_ip}:8083" echo "" -echo "Press enter to start viewing the pulse.log" -read +echo "Press enter to start viewing the pulse.log" +read tail -f /tmp/pulse.out - diff --git a/examples/tasks/psutil-influx.json b/examples/tasks/psutil-influx.json index b94e654ad..c8ca177ae 100644 --- a/examples/tasks/psutil-influx.json +++ b/examples/tasks/psutil-influx.json @@ -6,13 +6,13 @@ }, "workflow": { "collect": { - "metrics": { - "/psutil/load/load1": {}, - "/psutil/load/load5": {}, - "/psutil/load/load15": {}, - "/psutil/vm/available": {}, - "/psutil/vm/free": {}, - "/psutil/vm/used": {} + "metrics": { + "/intel/psutil/load/load1": {}, + "/intel/psutil/load/load5": {}, + "/intel/psutil/load/load15": {}, + "/intel/psutil/vm/available": {}, + "/intel/psutil/vm/free": {}, + "/intel/psutil/vm/used": {} }, "config": { "/intel/dummy": { @@ -28,13 +28,13 @@ "publish": [ { "plugin_name": "influx", - "plugin_version": 1, + "plugin_version": 4, "config": { "host": "INFLUXDB_IP", "port": 8086, "database": "pulse", "user": "admin", - "password": "admin" + "password": "admin" } } ],