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

Commit

Permalink
Merge pull request #1496 from jcooklin/ib/1495
Browse files Browse the repository at this point in the history
apply plugins defaults after config
  • Loading branch information
candysmurf authored Jan 27, 2017
2 parents 8080135 + 70266cd commit f2f7c09
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
5 changes: 5 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type managesPlugins interface {
SetMetricCatalog(catalogsMetrics)
GenerateArgs(logLevel int) plugin.Arg
SetPluginConfig(*pluginConfig)
GetPluginConfig() *pluginConfig
SetPluginTags(map[string]map[string]string)
AddStandardAndWorkflowTags(core.Metric, map[string]map[string]string) core.Metric
SetPluginLoadTimeout(int)
Expand Down Expand Up @@ -758,6 +759,10 @@ func (p *pluginControl) getMetricsAndCollectors(requested []core.RequestedMetric
// set config to metric
mt.config = cfg

// apply the defaults from the global (plugin) config
cfgNode := p.pluginManager.GetPluginConfig().getPluginConfigDataNode(core.CollectorPluginType, mt.Plugin.Name(), mt.Plugin.Version())
cfg.ApplyDefaults(cfgNode.Table())

// apply defaults to the metric that may be present in the plugins
// configpolicy
if pluginCfg := mt.Plugin.Policy().Get(mt.Namespace().Strings()); pluginCfg != nil {
Expand Down
1 change: 1 addition & 0 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (m *MockPluginManagerBadSwap) UnloadPlugin(c core.Plugin) (*loadedPlugin, s
}
func (m *MockPluginManagerBadSwap) get(string) (*loadedPlugin, error) { return nil, nil }
func (m *MockPluginManagerBadSwap) teardown() {}
func (m *MockPluginManagerBadSwap) GetPluginConfig() *pluginConfig { return nil }
func (m *MockPluginManagerBadSwap) SetPluginConfig(*pluginConfig) {}
func (m *MockPluginManagerBadSwap) SetPluginTags(map[string]map[string]string) {}
func (m *MockPluginManagerBadSwap) AddStandardAndWorkflowTags(met core.Metric, allTags map[string]map[string]string) core.Metric {
Expand Down
5 changes: 5 additions & 0 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ func (p *pluginManager) SetPluginConfig(cf *pluginConfig) {
p.pluginConfig = cf
}

// GetPluginConfig gets the plugin config
func (p *pluginManager) GetPluginConfig() *pluginConfig {
return p.pluginConfig
}

// SetPluginTags sets plugin tags
func (p *pluginManager) SetPluginTags(tags map[string]map[string]string) {
p.pluginTags = tags
Expand Down
59 changes: 47 additions & 12 deletions control/subscription_group_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
package control

import (
"fmt"
"net"
"path"
"testing"
Expand Down Expand Up @@ -120,8 +121,53 @@ func TestComparePlugins(t *testing.T) {
})
}

func TestSubscriptionGroups_Process_GlobalPluginConfig(t *testing.T) {
c := New(getTestSGConfig())
Convey("Adds global plugin config for collectors", t, func() {
c.Config.Plugins.Collector.All.AddItem("name", ctypes.ConfigValueStr{Value: "jane"})

lpe := newLstnToPluginEvents()
c.eventManager.RegisterHandler("TestSubscriptionGroups_Process", lpe)
c.Start()

Convey("Loading a mock collector plugin", func() {
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Convey("Subscription group created", func() {
requested := mockRequestedMetric{namespace: core.NewNamespace("intel", "mock", "foo")}
subsPlugin := mockSubscribedPlugin{
typeName: core.CollectorPluginType,
name: "mock",
version: 1,
config: cdata.NewNode(),
}

sg := newSubscriptionGroups(c)
So(sg, ShouldNotBeNil)
sg.Add("task-id", []core.RequestedMetric{requested}, cdata.NewTree(), []core.SubscribedPlugin{subsPlugin})
<-lpe.sub
So(len(sg.subscriptionMap), ShouldEqual, 1)
group, ok := sg.subscriptionMap["task-id"]
So(ok, ShouldBeTrue)
So(group, ShouldNotBeNil)
So(len(group.plugins), ShouldEqual, 1)
So(subscribedPluginsContain(group.plugins, subsPlugin), ShouldBeTrue)
key := fmt.Sprintf("%s"+core.Separator+"%s"+core.Separator+"%d",
subsPlugin.TypeName(),
subsPlugin.Name(),
subsPlugin.Version())
So(group.metrics, ShouldContainKey, key)
So(len(group.metrics[key].Metrics()), ShouldEqual, 1)
So(group.metrics[key].Metrics()[0].Config().Table(), ShouldContainKey, "name")
So(group.metrics[key].Metrics()[0].Config().Table()["name"], ShouldResemble, ctypes.ConfigValueStr{Value: "jane"})
})
})
})
}

func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -192,7 +238,6 @@ func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) {
}

func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -262,7 +307,6 @@ func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) {
}

func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -345,7 +389,6 @@ func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) {
}

func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -416,7 +459,6 @@ func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) {
}

func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) {
log.SetLevel(log.WarnLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -501,7 +543,6 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) {
}

func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -578,7 +619,6 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) {
}

func TestSubscriptionGroups_AddRemoveStatic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -617,7 +657,6 @@ func TestSubscriptionGroups_AddRemoveStatic(t *testing.T) {
}

func TestSubscriptionGroups_AddRemoveDynamic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -659,7 +698,6 @@ func TestSubscriptionGroups_AddRemoveDynamic(t *testing.T) {
}

func TestSubscriptionGroups_AddRemoveSpecifiedDynamic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -704,7 +742,6 @@ func TestSubscriptionGroups_AddRemoveSpecifiedDynamic(t *testing.T) {
}

func TestSubscriptionGroups_GetStatic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -753,7 +790,6 @@ func TestSubscriptionGroups_GetStatic(t *testing.T) {
}

func TestSubscriptionGroups_GetDynamic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down Expand Up @@ -802,7 +838,6 @@ func TestSubscriptionGroups_GetDynamic(t *testing.T) {
}

func TestSubscriptionGroups_GetSpecifiedDynamic(t *testing.T) {
log.SetLevel(log.DebugLevel)
c := New(getTestSGConfig())

lpe := newLstnToPluginEvents()
Expand Down

0 comments on commit f2f7c09

Please sign in to comment.