From 1932433be552f099de1917d75486c7fc3f1d806b Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Fri, 13 Mar 2020 11:58:39 -0400 Subject: [PATCH] Fix issue where autodiscover hints default configuration was not being copied. (#16987) * Fix issue where autodiscover hints default configuration was not being copied. * Add changelog. * Add test and update comment. (cherry picked from commit 661ff1412598d2da296fa6385b5751ac3d1792b9) --- CHANGELOG.next.asciidoc | 1 + filebeat/autodiscover/builder/hints/config.go | 5 ++- .../autodiscover/builder/hints/config_test.go | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 filebeat/autodiscover/builder/hints/config_test.go diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a04cb66f595..aa9d1d440c1 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -119,6 +119,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) +}