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

Commit

Permalink
Resolves #419 by checking for nil config before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin committed Oct 21, 2015
1 parent 8e3b7f6 commit 7dbe5cd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
14 changes: 10 additions & 4 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 19 additions & 0 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 10 additions & 12 deletions examples/influxdb-grafana/run-psutil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"

Expand Down Expand Up @@ -86,25 +88,21 @@ 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

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

18 changes: 9 additions & 9 deletions examples/tasks/psutil-influx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
],
Expand Down

0 comments on commit 7dbe5cd

Please sign in to comment.