Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Merge with AppendValues option when merging default config with hints generated config #36857

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion filebeat/autodiscover/builder/hints/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (l *logHints) CreateConfig(event bus.Event, options ...ucfg.Option) []*conf
kubernetes.ShouldPut(tempCfg, json, jsonOpts, l.log)
}
// Merge config template with the configs from the annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this now. Is not needed probably

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is still a valid comment as it describes what is merged. And then we describe why AppendValues option is used.

if err := config.Merge(tempCfg); err != nil {
// AppendValues option is used to append arrays from annotations to existing arrays while merging
if err := config.MergeWithOpts(tempCfg, ucfg.AppendValues); err != nil {
logp.Debug("hints.builder", "config merge failed with error: %v", err)
continue
}
Expand Down
73 changes: 73 additions & 0 deletions filebeat/autodiscover/builder/hints/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ func TestGenerateHints(t *testing.T) {
},
})

customProcessorCfg := conf.MustNewConfigFrom(map[string]interface{}{
"default_config": map[string]interface{}{
"type": "container",
"paths": []string{
"/var/lib/docker/containers/${data.container.id}/*-json.log",
},
"close_timeout": "true",
"processors": []interface{}{
map[string]interface{}{
"add_tags": map[string]interface{}{
"tags": []string{"web"},
"target": "environment",
},
},
},
},
})

defaultCfg := conf.NewConfig()

defaultDisabled := conf.MustNewConfigFrom(map[string]interface{}{
Expand Down Expand Up @@ -389,6 +407,61 @@ func TestGenerateHints(t *testing.T) {
},
},
},
{
msg: "Processors in hints must be appended in the processors of the default config",
config: customProcessorCfg,
event: bus.Event{
"host": "1.2.3.4",
"kubernetes": mapstr.M{
"container": mapstr.M{
"name": "foobar",
"id": "abc",
},
},
"container": mapstr.M{
"name": "foobar",
"id": "abc",
},
"hints": mapstr.M{
"logs": mapstr.M{
"processors": mapstr.M{
"1": mapstr.M{
"dissect": mapstr.M{
"tokenizer": "%{key1} %{key2}",
},
},
"drop_event": mapstr.M{},
},
},
},
},
len: 1,
result: []mapstr.M{
{
"type": "container",
"paths": []interface{}{
"/var/lib/docker/containers/abc/*-json.log",
},
"close_timeout": "true",
"processors": []interface{}{
map[string]interface{}{
"add_tags": map[string]interface{}{
"tags": []interface{}{"web"},
"target": "environment",
},
},
map[string]interface{}{
"dissect": map[string]interface{}{
"tokenizer": "%{key1} %{key2}",
},
},
map[string]interface{}{
"drop_event": nil,
},
},
},
},
},
{
msg: "Hint with module should attach input to its filesets",
config: customCfg,
Expand Down
Loading