Skip to content

Commit

Permalink
Warn when preserve is true and the original would be overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
camdencheek committed Jul 9, 2020
1 parent 8b756aa commit 8406afa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugin/helper/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helper

import (
"context"
"reflect"

"github.com/observiq/carbon/entry"
"github.com/observiq/carbon/errors"
Expand Down Expand Up @@ -34,6 +35,14 @@ func (c ParserConfig) Build(context plugin.BuildContext) (ParserPlugin, error) {
c.ParseTo.FieldInterface = entry.NewRecordField()
}

if reflect.DeepEqual(c.ParseFrom, c.ParseTo) && c.Preserve {
transformerPlugin.Warnw(
"preserve is true, but parse_to is set to the same field as parse_from, "+
"which will cause the original value to be overwritten",
"plugin_id", c.PluginID,
)
}

parserPlugin := ParserPlugin{
TransformerPlugin: transformerPlugin,
ParseFrom: c.ParseFrom,
Expand Down

0 comments on commit 8406afa

Please sign in to comment.