diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6f280cc4920..a2cf0514d0e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/filebeat/autodiscover/builder/hints/config.go b/filebeat/autodiscover/builder/hints/config.go index 55b1ffb1811..9c8922f772c 100644 --- a/filebeat/autodiscover/builder/hints/config.go +++ b/filebeat/autodiscover/builder/hints/config.go @@ -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) } } diff --git a/filebeat/autodiscover/builder/hints/config_test.go b/filebeat/autodiscover/builder/hints/config_test.go new file mode 100644 index 00000000000..ce871a6f6cb --- /dev/null +++ b/filebeat/autodiscover/builder/hints/config_test.go @@ -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) +}