fix issue with loading processor config from execd (#8274)
This commit is contained in:
parent
4872d7b4a9
commit
796b3b8d41
|
|
@ -116,7 +116,11 @@ func createPluginsWithTomlConfig(md toml.MetaData, conf config) (loadedConfig, e
|
||||||
plugin := creator()
|
plugin := creator()
|
||||||
if len(primitives) > 0 {
|
if len(primitives) > 0 {
|
||||||
primitive := 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
|
return loadedConf, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,3 +173,7 @@ func DefaultImportedPlugins() (config, error) {
|
||||||
}
|
}
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type unwrappable interface {
|
||||||
|
Unwrap() telegraf.Processor
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
tgConfig "github.com/influxdata/telegraf/config"
|
tgConfig "github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/processors"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -55,6 +56,19 @@ func TestLoadingSpecialTypes(t *testing.T) {
|
||||||
require.EqualValues(t, 3*1000*1000, inp.Size)
|
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 {
|
type testDurationInput struct {
|
||||||
Duration tgConfig.Duration `toml:"duration"`
|
Duration tgConfig.Duration `toml:"duration"`
|
||||||
Size tgConfig.Size `toml:"size"`
|
Size tgConfig.Size `toml:"size"`
|
||||||
|
|
@ -70,3 +84,18 @@ func (i *testDurationInput) Description() string {
|
||||||
func (i *testDurationInput) Gather(acc telegraf.Accumulator) error {
|
func (i *testDurationInput) Gather(acc telegraf.Accumulator) error {
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
[[processors.test_config_load]]
|
||||||
|
loaded = "yep"
|
||||||
Loading…
Reference in New Issue