Skip to content

Commit 03b5f96

Browse files
fix(enrich)!: enrich processor not working (#390)
* fix(enrich): enrich processor not working * test(plugin): add test for nil config)
1 parent d5ba47c commit 03b5f96

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

plugins/base_plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func (p *BasePlugin) Info() Info {
2525

2626
// Validate checks if the given options is valid for the plugin.
2727
func (p *BasePlugin) Validate(config Config) error {
28+
if p.configRef == nil {
29+
return nil
30+
}
31+
2832
return buildConfig(config.RawConfig, p.configRef)
2933
}
3034

plugins/base_plugin_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func TestBasePluginInfo(t *testing.T) {
3737
}
3838

3939
func TestBasePluginValidate(t *testing.T) {
40+
t.Run("should not return error if config is nil", func(t *testing.T) {
41+
basePlugin := plugins.NewBasePlugin(plugins.Info{}, nil)
42+
err := basePlugin.Validate(plugins.Config{
43+
URNScope: "test-scope",
44+
RawConfig: map[string]interface{}{},
45+
})
46+
47+
assert.NoError(t, err)
48+
})
49+
4050
t.Run("should return InvalidConfigError if config is invalid", func(t *testing.T) {
4151
invalidConfig := struct {
4252
FieldA string `validate:"required"`

plugins/processors/enrich/processor.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ import (
1414
//go:embed README.md
1515
var summary string
1616

17+
type Config struct {
18+
Attributes map[string]interface{} `mapstructure:"attributes" validate:"required"`
19+
}
20+
1721
// Processor work in a list of data
1822
type Processor struct {
1923
plugins.BasePlugin
20-
config map[string]interface{}
24+
config Config
2125
logger log.Logger
2226
}
2327

2428
var sampleConfig = `
2529
# Enrichment configuration
26-
# fieldA: valueA
27-
# fieldB: valueB`
30+
# attributes:
31+
# fieldA: valueA
32+
# fieldB: valueB`
2833

2934
var info = plugins.Info{
3035
Description: "Append custom fields to records",
@@ -68,7 +73,7 @@ func (p *Processor) process(record models.Record) (models.Metadata, error) {
6873
customProps := utils.GetCustomProperties(data)
6974

7075
// update custom properties using value from config
71-
for key, value := range p.config {
76+
for key, value := range p.config.Attributes {
7277
stringVal, ok := value.(string)
7378
if ok {
7479
customProps[key] = stringVal

0 commit comments

Comments
 (0)