From 764a008c2d7d88af99d1b16c031dc77622240204 Mon Sep 17 00:00:00 2001 From: Andy Hunt Date: Thu, 6 Jun 2019 10:37:46 +0100 Subject: [PATCH] Separate logging behaviour from fail_on_error --- libbeat/processors/actions/copy_fields.go | 10 ++++++---- libbeat/processors/actions/rename.go | 10 ++++++---- libbeat/processors/actions/truncate_fields.go | 8 +++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libbeat/processors/actions/copy_fields.go b/libbeat/processors/actions/copy_fields.go index ec82cfa3e028..af5709d54e16 100644 --- a/libbeat/processors/actions/copy_fields.go +++ b/libbeat/processors/actions/copy_fields.go @@ -72,12 +72,14 @@ 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 && f.config.FailOnError { + if err != nil { errMsg := fmt.Errorf("Failed to copy fields in copy_fields processor: %s", err) logp.Debug("copy_fields", errMsg.Error()) - event.Fields = backup - event.PutValue("error.message", errMsg.Error()) - return event, err + if f.config.FailOnError { + 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 2a94b9f834ea..c0c8f7787455 100644 --- a/libbeat/processors/actions/rename.go +++ b/libbeat/processors/actions/rename.go @@ -76,12 +76,14 @@ 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 && f.config.FailOnError { + if err != nil { errMsg := fmt.Errorf("Failed to rename fields in processor: %s", err) logp.Debug("rename", errMsg.Error()) - event.Fields = backup - event.PutValue("error.message", errMsg.Error()) - return event, err + if f.config.FailOnError { + 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 d924da381a56..ca87eb35c5e4 100644 --- a/libbeat/processors/actions/truncate_fields.go +++ b/libbeat/processors/actions/truncate_fields.go @@ -85,10 +85,12 @@ 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 && f.config.FailOnError { + if err != nil { logp.Debug("truncate_fields", "Failed to truncate fields: %s", err) - event.Fields = backup - return event, err + if f.config.FailOnError { + event.Fields = backup + return event, err + } } }