From 4f5967953035672527fa2132e36697e95882461b Mon Sep 17 00:00:00 2001 From: Andy Hunt Date: Fri, 7 Jun 2019 12:36:09 +0100 Subject: [PATCH] Decouple debug logging behaviour from fail_on_error value --- CHANGELOG.next.asciidoc | 1 + libbeat/processors/actions/copy_fields.go | 10 ++++------ libbeat/processors/actions/rename.go | 10 ++++------ libbeat/processors/actions/truncate_fields.go | 8 +++----- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 819a85e9668..e973887c99f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -161,6 +161,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Affecting all Beats* +- Decouple Debug logging from fail_on_error logic for rename, copy, truncate processors {pull}12451[12451] - Add an option to append to existing logs rather than always rotate on start. {pull}11953[11953] - Add `network` condition to processors for matching IP addresses against CIDRs. {pull}10743[10743] - Add if/then/else support to processors. {pull}10744[10744] diff --git a/libbeat/processors/actions/copy_fields.go b/libbeat/processors/actions/copy_fields.go index af5709d54e1..ec82cfa3e02 100644 --- a/libbeat/processors/actions/copy_fields.go +++ b/libbeat/processors/actions/copy_fields.go @@ -72,14 +72,12 @@ func (f *copyFields) Run(event *beat.Event) (*beat.Event, error) { for _, field := range f.config.Fields { err := f.copyField(field.From, field.To, event.Fields) - if err != nil { + if err != nil && f.config.FailOnError { errMsg := fmt.Errorf("Failed to copy fields in copy_fields processor: %s", err) logp.Debug("copy_fields", errMsg.Error()) - if f.config.FailOnError { - event.Fields = backup - event.PutValue("error.message", errMsg.Error()) - return event, err - } + event.Fields = backup + event.PutValue("error.message", errMsg.Error()) + return event, err } } diff --git a/libbeat/processors/actions/rename.go b/libbeat/processors/actions/rename.go index c0c8f778745..2a94b9f834e 100644 --- a/libbeat/processors/actions/rename.go +++ b/libbeat/processors/actions/rename.go @@ -76,14 +76,12 @@ func (f *renameFields) Run(event *beat.Event) (*beat.Event, error) { for _, field := range f.config.Fields { err := f.renameField(field.From, field.To, event.Fields) - if err != nil { + if err != nil && f.config.FailOnError { errMsg := fmt.Errorf("Failed to rename fields in processor: %s", err) logp.Debug("rename", errMsg.Error()) - if f.config.FailOnError { - event.Fields = backup - event.PutValue("error.message", errMsg.Error()) - return event, err - } + event.Fields = backup + event.PutValue("error.message", errMsg.Error()) + return event, err } } diff --git a/libbeat/processors/actions/truncate_fields.go b/libbeat/processors/actions/truncate_fields.go index ca87eb35c5e..d924da381a5 100644 --- a/libbeat/processors/actions/truncate_fields.go +++ b/libbeat/processors/actions/truncate_fields.go @@ -85,12 +85,10 @@ func (f *truncateFields) Run(event *beat.Event) (*beat.Event, error) { for _, field := range f.config.Fields { event, err := f.truncateSingleField(field, event) - if err != nil { + if err != nil && f.config.FailOnError { logp.Debug("truncate_fields", "Failed to truncate fields: %s", err) - if f.config.FailOnError { - event.Fields = backup - return event, err - } + event.Fields = backup + return event, err } }