From d379a94627965cc035240532f0c679064f894b23 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 8 Jul 2021 10:21:41 -0500 Subject: [PATCH] [7.x](backport #26699) change type of max_bytes to ByteType (#26773) * change type of max_bytes to ByteType (#26699) * change type of max_bytes to ByteType allows for both number and humanize values in the config. Without this max_bytes in awss3 input could only be numbers. (cherry picked from commit 2af8ab91731e43d37d3f22014e7594dbf346057e) * Update CHANGELOG.next.asciidoc Co-authored-by: Lee Hinman <57081003+leehinman@users.noreply.github.com> --- CHANGELOG.next.asciidoc | 1 + libbeat/reader/parser/parser.go | 5 ++-- libbeat/reader/parser/parser_example_test.go | 31 +++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index b0d5f4c707a..42e44111981 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -224,6 +224,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Improve inode reuse handling by removing state for removed files more eagerly from the internal state table in the logs inputs. {pull}25756[25756] - Fix default config template values for paths on oracle module: {pull}26276[26276] - Do not close filestream harvester if an unexpected error is returned when close.on_state_change.* is enabled. {pull}26411[26411] +- Change type of max_bytes in all configs to be cfgtype.ByteSize {pull}26699[26699] *Filebeat* diff --git a/libbeat/reader/parser/parser.go b/libbeat/reader/parser/parser.go index fa01181c2aa..151e912416a 100644 --- a/libbeat/reader/parser/parser.go +++ b/libbeat/reader/parser/parser.go @@ -25,6 +25,7 @@ import ( "github.com/dustin/go-humanize" "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/common/cfgtype" "github.com/elastic/beats/v7/libbeat/reader" "github.com/elastic/beats/v7/libbeat/reader/multiline" "github.com/elastic/beats/v7/libbeat/reader/readfile" @@ -43,7 +44,7 @@ type Parser interface { } type CommonConfig struct { - MaxBytes int `config:"max_bytes"` + MaxBytes cfgtype.ByteSize `config:"max_bytes"` LineTerminator readfile.LineTerminator `config:"line_terminator"` } @@ -126,7 +127,7 @@ func (c *Config) Create(in reader.Reader) Parser { if err != nil { return p } - p, err = multiline.New(p, "\n", c.pCfg.MaxBytes, &config) + p, err = multiline.New(p, "\n", int(c.pCfg.MaxBytes), &config) if err != nil { return p } diff --git a/libbeat/reader/parser/parser_example_test.go b/libbeat/reader/parser/parser_example_test.go index ed8c12e2146..f9776e37e9f 100644 --- a/libbeat/reader/parser/parser_example_test.go +++ b/libbeat/reader/parser/parser_example_test.go @@ -23,11 +23,12 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/libbeat/common" + "github.com/elastic/beats/v7/libbeat/common/cfgtype" "github.com/elastic/beats/v7/libbeat/reader/readfile" ) type inputParsersConfig struct { - MaxBytes int `config:"max_bytes"` + MaxBytes cfgtype.ByteSize `config:"max_bytes"` LineTerminator readfile.LineTerminator `config:"line_terminator"` Parsers Config `config:",inline"` } @@ -70,6 +71,34 @@ func TestParsersExampleInline(t *testing.T) { "[log] In total there should be 3 events\n", }, }, + "humanize max_bytes, multiline XML": { + lines: ` + A + B + C + + D + E + F +`, + parsers: map[string]interface{}{ + "max_bytes": "4 KiB", + "line_terminator": "auto", + "parsers": []map[string]interface{}{ + map[string]interface{}{ + "multiline": map[string]interface{}{ + "match": "after", + "negate": true, + "pattern": "^\n\n\tA\n\n\tB\n\n\tC\n", + "\n\n\tD\n\n\tE\n\n\tF\n", + }, + }, } for name, test := range tests {