From c283e5992a3c4a83a6e4b07b6938f2a5254acf3f Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 2 Apr 2019 11:14:56 -0700 Subject: [PATCH] Fix tags applied to wrong metric on parse error (#5650) --- plugins/parsers/influx/handler.go | 4 ++++ plugins/parsers/influx/parser.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/plugins/parsers/influx/handler.go b/plugins/parsers/influx/handler.go index c488a9c98..928671cc9 100644 --- a/plugins/parsers/influx/handler.go +++ b/plugins/parsers/influx/handler.go @@ -118,3 +118,7 @@ func (h *MetricHandler) SetTimestamp(tm []byte) error { h.builder.SetTime(time.Unix(0, ns)) return nil } + +func (h *MetricHandler) Reset() { + h.builder.Reset() +} diff --git a/plugins/parsers/influx/parser.go b/plugins/parsers/influx/parser.go index 8b9272b69..f1cd9a032 100644 --- a/plugins/parsers/influx/parser.go +++ b/plugins/parsers/influx/parser.go @@ -75,6 +75,7 @@ func (p *Parser) Parse(input []byte) ([]telegraf.Metric, error) { } if err != nil { + p.handler.Reset() return nil, &ParseError{ Offset: p.machine.Position(), LineOffset: p.machine.LineOffset(), @@ -87,6 +88,7 @@ func (p *Parser) Parse(input []byte) ([]telegraf.Metric, error) { metric, err := p.handler.Metric() if err != nil { + p.handler.Reset() return nil, err }