From 8e85973893624e403d9908de5fcc2e24b9c6ddb8 Mon Sep 17 00:00:00 2001 From: jeremydenoun Date: Tue, 7 Mar 2017 17:04:39 +0100 Subject: [PATCH 1/3] Remove warning if parse empty content Related to my issue #2448, I propose to hide warning if empty content should be passed --- metric/parse.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metric/parse.go b/metric/parse.go index fe2cffdc1397e..15b88e5528e1a 100644 --- a/metric/parse.go +++ b/metric/parse.go @@ -44,6 +44,9 @@ func Parse(buf []byte) ([]telegraf.Metric, error) { } func ParseWithDefaultTime(buf []byte, t time.Time) ([]telegraf.Metric, error) { + if len(buf) == 0 { + return []telegraf.Metric{}, nil + } if len(buf) <= 6 { return []telegraf.Metric{}, makeError("buffer too short", buf, 0) } From f1e145635c5d48a572e47d7e83b751458d506b4b Mon Sep 17 00:00:00 2001 From: Jeremy Denoun Date: Wed, 8 Mar 2017 13:03:47 +0000 Subject: [PATCH 2/3] test unit --- plugins/inputs/exec/exec_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/inputs/exec/exec_test.go b/plugins/inputs/exec/exec_test.go index 71d33fb71bf8a..975eb9642668d 100644 --- a/plugins/inputs/exec/exec_test.go +++ b/plugins/inputs/exec/exec_test.go @@ -37,6 +37,8 @@ const malformedJson = ` ` const lineProtocol = "cpu,host=foo,datacenter=us-east usage_idle=99,usage_busy=1\n" +const lineProtocolEmpty = "" +const lineProtocolShort = "ab" const lineProtocolMulti = ` cpu,cpu=cpu0,host=foo,datacenter=us-east usage_idle=99,usage_busy=1 @@ -167,6 +169,33 @@ func TestLineProtocolParse(t *testing.T) { acc.AssertContainsTaggedFields(t, "cpu", fields, tags) } +func TestLineProtocolEmptyParse(t *testing.T) { + parser, _ := parsers.NewInfluxParser() + e := &Exec{ + runner: newRunnerMock([]byte(lineProtocolEmpty), nil), + Commands: []string{"line-protocol"}, + parser: parser, + } + + var acc testutil.Accumulator + err := e.Gather(&acc) + require.NoError(t, err) +} + +func TestLineProtocolShortParse(t *testing.T) { + parser, _ := parsers.NewInfluxParser() + e := &Exec{ + runner: newRunnerMock([]byte(lineProtocolShort), nil), + Commands: []string{"line-protocol"}, + parser: parser, + } + + var acc testutil.Accumulator + err := e.Gather(&acc) + require.Error(t, err) + assert.Contains(t, err.Error(), "buffer too short", "A buffer too short error was expected") +} + func TestLineProtocolParseMultiple(t *testing.T) { parser, _ := parsers.NewInfluxParser() e := &Exec{ From 2717e927b0505ddb57d5933ea224aaa986e36c0e Mon Sep 17 00:00:00 2001 From: Jeremy Denoun Date: Wed, 8 Mar 2017 21:45:55 +0000 Subject: [PATCH 3/3] Changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5773179b6c29d..cbbdd1651d541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ be deprecated eventually. - [#2178](https://github.com/influxdata/telegraf/issues/2178): logparser: regexp with lookahead. - [#2466](https://github.com/influxdata/telegraf/issues/2466): Telegraf can crash in LoadDirectory on 0600 files. - [#2215](https://github.com/influxdata/telegraf/issues/2215): Iptables input: document better that rules without a comment are ignored. +- [#2500](https://github.com/influxdata/telegraf/pull/2500): Remove warning if parse empty content ## v1.2.1 [2017-02-01]