Skip to content

Commit 796b3b8

Browse files
authored
fix issue with loading processor config from execd (influxdata#8274)
1 parent 4872d7b commit 796b3b8

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

plugins/common/shim/config.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ func createPluginsWithTomlConfig(md toml.MetaData, conf config) (loadedConfig, e
116116
plugin := creator()
117117
if len(primitives) > 0 {
118118
primitive := primitives[0]
119-
if err := md.PrimitiveDecode(primitive, plugin); err != nil {
119+
var p telegraf.PluginDescriber = plugin
120+
if processor, ok := plugin.(unwrappable); ok {
121+
p = processor.Unwrap()
122+
}
123+
if err := md.PrimitiveDecode(primitive, p); err != nil {
120124
return loadedConf, err
121125
}
122126
}
@@ -169,3 +173,7 @@ func DefaultImportedPlugins() (config, error) {
169173
}
170174
return conf, nil
171175
}
176+
177+
type unwrappable interface {
178+
Unwrap() telegraf.Processor
179+
}

plugins/common/shim/config_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/influxdata/telegraf"
99
tgConfig "github.com/influxdata/telegraf/config"
1010
"github.com/influxdata/telegraf/plugins/inputs"
11+
"github.com/influxdata/telegraf/plugins/processors"
1112
"github.com/stretchr/testify/require"
1213
)
1314

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

59+
func TestLoadingProcessorWithConfig(t *testing.T) {
60+
proc := &testConfigProcessor{}
61+
processors.Add("test_config_load", func() telegraf.Processor {
62+
return proc
63+
})
64+
65+
c := "./testdata/processor.conf"
66+
_, err := LoadConfig(&c)
67+
require.NoError(t, err)
68+
69+
require.EqualValues(t, "yep", proc.Loaded)
70+
}
71+
5872
type testDurationInput struct {
5973
Duration tgConfig.Duration `toml:"duration"`
6074
Size tgConfig.Size `toml:"size"`
@@ -70,3 +84,18 @@ func (i *testDurationInput) Description() string {
7084
func (i *testDurationInput) Gather(acc telegraf.Accumulator) error {
7185
return nil
7286
}
87+
88+
type testConfigProcessor struct {
89+
Loaded string `toml:"loaded"`
90+
}
91+
92+
func (p *testConfigProcessor) SampleConfig() string {
93+
return ""
94+
}
95+
96+
func (p *testConfigProcessor) Description() string {
97+
return ""
98+
}
99+
func (p *testConfigProcessor) Apply(metrics ...telegraf.Metric) []telegraf.Metric {
100+
return metrics
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[processors.test_config_load]]
2+
loaded = "yep"

0 commit comments

Comments
 (0)