Skip to content

Commit

Permalink
Fix processor actions that incorrectly always return an error (elasti…
Browse files Browse the repository at this point in the history
…c#3049)

Even when no error occurs during the action, a new empty error was being returned causing an error to be logged.
  • Loading branch information
andrewkroh authored and ruflin committed Nov 22, 2016
1 parent 4c2389f commit 104563d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ https://github.com/elastic/beats/compare/v5.0.1...master[Check the HEAD diff]
==== Bugfixes

*Affecting all Beats*
- Fix empty benign errors logged by processor actions. {pull}3046[3046]

*Metricbeat*

Expand Down
5 changes: 4 additions & 1 deletion libbeat/processors/actions/decode_json_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (f decodeJSONFields) Run(event common.MapStr) (common.MapStr, error) {
}
}

return event, fmt.Errorf(strings.Join(errs, ", "))
if len(errs) > 0 {
return event, fmt.Errorf(strings.Join(errs, ", "))
}
return event, nil
}

func unmarshal(maxDepth int, text []byte, fields *interface{}, processArray bool) error {
Expand Down
8 changes: 6 additions & 2 deletions libbeat/processors/actions/drop_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newDropFields(c common.Config) (processors.Processor, error) {
}

func (f dropFields) Run(event common.MapStr) (common.MapStr, error) {
errors := []string{}
var errors []string

for _, field := range f.Fields {
err := event.Delete(field)
Expand All @@ -51,7 +51,11 @@ func (f dropFields) Run(event common.MapStr) (common.MapStr, error) {
}

}
return event, fmt.Errorf(strings.Join(errors, ", "))

if len(errors) > 0 {
return event, fmt.Errorf(strings.Join(errors, ", "))
}
return event, nil
}

func (f dropFields) String() string {
Expand Down
7 changes: 5 additions & 2 deletions libbeat/processors/actions/include_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newIncludeFields(c common.Config) (processors.Processor, error) {

func (f includeFields) Run(event common.MapStr) (common.MapStr, error) {
filtered := common.MapStr{}
errs := []string{}
var errs []string

for _, field := range f.Fields {
err := event.CopyFieldsTo(filtered, field)
Expand All @@ -58,7 +58,10 @@ func (f includeFields) Run(event common.MapStr) (common.MapStr, error) {
}
}

return filtered, fmt.Errorf(strings.Join(errs, ", "))
if len(errs) > 0 {
return filtered, fmt.Errorf(strings.Join(errs, ", "))
}
return filtered, nil
}

func (f includeFields) String() string {
Expand Down
4 changes: 1 addition & 3 deletions libbeat/processors/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ func (procs *Processors) Run(event common.MapStr) common.MapStr {
}

func (procs Processors) String() string {
s := []string{}

var s []string
for _, p := range procs.list {

s = append(s, p.String())
}
return strings.Join(s, ", ")
Expand Down

0 comments on commit 104563d

Please sign in to comment.