From 8406afadb70a5106b7837e76a5f7d597a51f99eb Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Thu, 9 Jul 2020 11:36:15 -0400 Subject: [PATCH] Warn when preserve is true and the original would be overwritten --- plugin/helper/parser.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/helper/parser.go b/plugin/helper/parser.go index 2f164ea69..1abd84740 100644 --- a/plugin/helper/parser.go +++ b/plugin/helper/parser.go @@ -2,6 +2,7 @@ package helper import ( "context" + "reflect" "github.com/observiq/carbon/entry" "github.com/observiq/carbon/errors" @@ -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,