Skip to content

Commit

Permalink
Fix issue where autodiscover hints default configuration was not bein…
Browse files Browse the repository at this point in the history
…g copied. (elastic#16987)

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

* Add changelog.

* Add test and update comment.

(cherry picked from commit 661ff14)
  • Loading branch information
blakerouse committed Mar 13, 2020
1 parent 87e6b3a commit 1932433
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

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)
}

0 comments on commit 1932433

Please sign in to comment.