diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index fb93e5562874..ca376e0df49e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -220,6 +220,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - 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] - Fix Elasticsearch compatibility for modules that use `copy_from` in `set` processors. {issue}26629[26629] +- 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 fa01181c2aa1..151e912416a9 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 ed8c12e2146c..f9776e37e9ff 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 {