Skip to content

Commit

Permalink
Fixes intelsdi-x#799: Adds plugin level defaults to the config data n…
Browse files Browse the repository at this point in the history
…ode for GetMetricTypes
  • Loading branch information
tiffanyfay committed May 23, 2016
1 parent 550d613 commit 4573cb3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/intelsdi-x/snap/control/plugin/client"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/cdata"
"github.com/intelsdi-x/snap/core/serror"
)

Expand Down Expand Up @@ -354,11 +355,50 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter
}
lPlugin.ConfigPolicy = cp

var defaultConfigNode *cdata.ConfigDataNode
cfgNode := p.pluginConfig.getPluginConfigDataNode(core.PluginType(resp.Type), resp.Meta.Name, resp.Meta.Version)
if resp.Type == plugin.CollectorPluginType {
if lPlugin.ConfigPolicy != nil {
ncd := lPlugin.ConfigPolicy.Get([]string{""})
rulesTable := ncd.RulesAsTable()
tbl, errs := ncd.Process(cfgNode.Table())
for _, t := range rulesTable {
fmt.Println("Name:", t.Name, "\nType:", t.Type, "\nDefault:", t.Default)
if t.Default != nil {
if errs != nil && errs.HasErrors() {
fields := make(map[string]interface{})
se := serror.New(fmt.Errorf("ConfigPolicy processing failed. Not loading collector:%v:%v", resp.Meta.Name, resp.Meta.Version))
for i, e := range errs.Errors() {
idx := fmt.Sprintf("%d", i)
fields[idx] = e.Error()
}
fields["name"] = resp.Meta.Name
fields["version"] = resp.Meta.Version
se.SetFields(fields)
return nil, se
}
if tbl != nil {
defaultConfigNode = cdata.FromTable(*tbl)
for k, v := range defaultConfigNode.Table() {
fmt.Printf("default: %v, %v", k, v)
}
}
}
}
}
for k, v := range cfgNode.Table() {
fmt.Printf("Pre Merge: %v, %v", k, v)
}
// cfgNode := p.pluginConfig.getPluginConfigDataNode(core.PluginType(resp.Type), resp.Meta.Name, resp.Meta.Version)
cfgNode.ReverseMerge(defaultConfigNode)
for k, v := range cfgNode.Table() {
fmt.Printf("Merge: %v, %v", k, v)
}

colClient := ap.client.(client.PluginCollectorClient)

cfg := plugin.ConfigType{
ConfigDataNode: p.pluginConfig.getPluginConfigDataNode(core.PluginType(resp.Type), resp.Meta.Name, resp.Meta.Version),
ConfigDataNode: cfgNode,
}

metricTypes, err := colClient.GetMetricTypes(cfg)
Expand Down

0 comments on commit 4573cb3

Please sign in to comment.