Skip to content

Commit 9a4326b

Browse files
authored
Fix issue where autodiscover hints default configuration was not being copied. (#16987) (#17002)
* Fix issue where autodiscover hints default configuration was not being copied. * Add changelog. * Add test and update comment. (cherry picked from commit 661ff14)
1 parent 1871b17 commit 9a4326b

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
119119
- Adding the var definitions in azure manifest files, fix for errors when executing command setup. {issue}16270[16270] {pull}16468[16468]
120120
- Fix merging of fileset inputs to replace paths and append processors. {pull}16450{16450}
121121
- Add queue_url definition in manifest file for aws module. {pull}16640{16640}
122+
- Fix issue where autodiscover hints default configuration was not being copied. {pull}16987[16987]
122123

123124
*Heartbeat*
124125

filebeat/autodiscover/builder/hints/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ func (c *config) Unpack(from *common.Config) error {
5858
return nil
5959
}
6060
} else {
61-
// full config provided, discard default
62-
c.DefaultConfig = config
61+
// full config provided, discard default. It must be a clone of the
62+
// given config otherwise it could be updated across multiple inputs.
63+
c.DefaultConfig = common.MustNewConfigFrom(config)
6364
}
6465
}
6566

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package hints
19+
20+
import (
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
25+
"github.com/elastic/beats/v7/libbeat/common"
26+
)
27+
28+
func TestUnpackCopiesDefault(t *testing.T) {
29+
userCfg := common.MustNewConfigFrom(common.MapStr{
30+
"default_config": common.MapStr{
31+
"type": "container",
32+
"paths": []string{
33+
"/var/log/containers/*${data.kubernetes.container.id}.log",
34+
},
35+
},
36+
})
37+
38+
cfg1 := defaultConfig()
39+
assert.NoError(t, userCfg.Unpack(&cfg1))
40+
41+
cfg2 := defaultConfig()
42+
assert.NoError(t, userCfg.Unpack(&cfg2))
43+
44+
assert.NotEqual(t, cfg1.DefaultConfig, cfg2.DefaultConfig)
45+
}

0 commit comments

Comments
 (0)