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

Fix issue where autodiscover hints default configuration was not being copied. #16987

Merged
merged 3 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Adding the var definitions in azure manifest files, fix for errors when executing command setup. {issue}16270[16270] {pull}16468[16468]
- Fix merging of fileset inputs to replace paths and append processors. {pull}16450{16450}
- Add queue_url definition in manifest file for aws module. {pull}16640{16640}
- Fix issue where autodiscover hints default configuration was not being copied. {pull}16987[16987]

*Heartbeat*

Expand Down
5 changes: 3 additions & 2 deletions filebeat/autodiscover/builder/hints/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func (c *config) Unpack(from *common.Config) error {
return nil
}
} else {
// full config provided, discard default
c.DefaultConfig = config
// full config provided, discard default. It must be a clone of the
// given config otherwise it could be updated across multiple inputs.
c.DefaultConfig = common.MustNewConfigFrom(config)
}
}

Expand Down
45 changes: 45 additions & 0 deletions filebeat/autodiscover/builder/hints/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package hints

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/libbeat/common"
)

func TestUnpackCopiesDefault(t *testing.T) {
userCfg := common.MustNewConfigFrom(common.MapStr{
"default_config": common.MapStr{
"type": "container",
"paths": []string{
"/var/log/containers/*${data.kubernetes.container.id}.log",
},
},
})

cfg1 := defaultConfig()
assert.NoError(t, userCfg.Unpack(&cfg1))

cfg2 := defaultConfig()
assert.NoError(t, userCfg.Unpack(&cfg2))

assert.NotEqual(t, cfg1.DefaultConfig, cfg2.DefaultConfig)
}