Skip to content

Commit

Permalink
Don't generate a config when disabling logs collection with hints (el…
Browse files Browse the repository at this point in the history
…astic#9305) (elastic#9356)

When `co.elastic.logs/disable="true"` is used in a container, an
incomplete event is generated, what provokes errors about configurations
with missing fields. Don't generate configs in these cases.

If after that a builder doesn't generate any configuration,
it still generates an event but with with an empty list of configs
instead of an event without a config field.

(cherry picked from commit a4b06ae)
  • Loading branch information
jsoriano authored Dec 4, 2018
1 parent d82c15f commit aa31126
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ https://github.com/elastic/beats/compare/v6.5.0...6.x[Check the HEAD diff]
- Make sure the Filebeat Elastic licensed packages uses the Elastic binary instead of the OSS. {pull}8836[8836]
- Fix installation of haproxy dashboard. {issue}9307[9307] {pull}9313[9313]

- Don't generate incomplete configurations when logs collection is disabled by hints. {pull}9305[9305]
- Stop runners disabled by hints after previously being started. {pull}9305[9305]

*Heartbeat*

- Heartbeat now always downloads the entire body of HTTP endpoints, even if no checks against the body content are declared. This fixes an issue where timing metrics would be incorrect in scenarios where the body wasn't used since the connection would be closed soon after the headers were sent, but before the entire body was. {pull}8894[8894]
Expand Down
5 changes: 3 additions & 2 deletions filebeat/autodiscover/builder/hints/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ func (l *logHints) CreateConfig(event bus.Event) []*common.Config {
hints, _ = hIface.(common.MapStr)
}

if builder.IsNoOp(hints, l.Key) == true {
return []*common.Config{config}
if builder.IsNoOp(hints, l.Key) {
logp.Debug("hints.builder", "disabled config in event: %+v", event)
return []*common.Config{}
}

inputConfig := l.getInputs(hints)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *registry) BuildBuilder(c *common.Config) (Builder, error) {

// GetConfig creates configs for all builders initialized.
func (b Builders) GetConfig(event bus.Event) []*common.Config {
var configs []*common.Config
configs := []*common.Config{}

for _, builder := range b {
if config := builder.CreateConfig(event); config != nil {
Expand Down
3 changes: 2 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func TestEmitEvent(t *testing.T) {
},
},
},
"config": []*common.Config{},
},
},
{
Expand Down Expand Up @@ -282,7 +283,7 @@ func TestEmitEvent(t *testing.T) {

select {
case event := <-listener.Events():
assert.Equal(t, test.Expected, event)
assert.Equal(t, test.Expected, event, test.Message)
case <-time.After(2 * time.Second):
if test.Expected != nil {
t.Fatal("Timeout while waiting for event")
Expand Down

0 comments on commit aa31126

Please sign in to comment.