Skip to content

Commit

Permalink
fix issue with loading processor config from execd (#8274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored Oct 15, 2020
1 parent 4872d7b commit 796b3b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/common/shim/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func createPluginsWithTomlConfig(md toml.MetaData, conf config) (loadedConfig, e
plugin := creator()
if len(primitives) > 0 {
primitive := primitives[0]
if err := md.PrimitiveDecode(primitive, plugin); err != nil {
var p telegraf.PluginDescriber = plugin
if processor, ok := plugin.(unwrappable); ok {
p = processor.Unwrap()
}
if err := md.PrimitiveDecode(primitive, p); err != nil {
return loadedConf, err
}
}
Expand Down Expand Up @@ -169,3 +173,7 @@ func DefaultImportedPlugins() (config, error) {
}
return conf, nil
}

type unwrappable interface {
Unwrap() telegraf.Processor
}
29 changes: 29 additions & 0 deletions plugins/common/shim/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/influxdata/telegraf"
tgConfig "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/processors"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -55,6 +56,19 @@ func TestLoadingSpecialTypes(t *testing.T) {
require.EqualValues(t, 3*1000*1000, inp.Size)
}

func TestLoadingProcessorWithConfig(t *testing.T) {
proc := &testConfigProcessor{}
processors.Add("test_config_load", func() telegraf.Processor {
return proc
})

c := "./testdata/processor.conf"
_, err := LoadConfig(&c)
require.NoError(t, err)

require.EqualValues(t, "yep", proc.Loaded)
}

type testDurationInput struct {
Duration tgConfig.Duration `toml:"duration"`
Size tgConfig.Size `toml:"size"`
Expand All @@ -70,3 +84,18 @@ func (i *testDurationInput) Description() string {
func (i *testDurationInput) Gather(acc telegraf.Accumulator) error {
return nil
}

type testConfigProcessor struct {
Loaded string `toml:"loaded"`
}

func (p *testConfigProcessor) SampleConfig() string {
return ""
}

func (p *testConfigProcessor) Description() string {
return ""
}
func (p *testConfigProcessor) Apply(metrics ...telegraf.Metric) []telegraf.Metric {
return metrics
}
2 changes: 2 additions & 0 deletions plugins/common/shim/testdata/processor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[processors.test_config_load]]
loaded = "yep"

0 comments on commit 796b3b8

Please sign in to comment.