Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.14](backport #26699) change type of max_bytes to ByteType #26761

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
5 changes: 3 additions & 2 deletions libbeat/reader/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 30 additions & 1 deletion libbeat/reader/parser/parser_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -70,6 +71,34 @@ func TestParsersExampleInline(t *testing.T) {
"[log] In total there should be 3 events\n",
},
},
"humanize max_bytes, multiline XML": {
lines: `<Event><Data>
A
B
C</Data></Event>
<Event><Data>
D
E
F</Data></Event>
`,
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": "^<Event",
},
},
},
},
expectedMessages: []string{
"<Event><Data>\n\n\tA\n\n\tB\n\n\tC</Data></Event>\n",
"<Event><Data>\n\n\tD\n\n\tE\n\n\tF</Data></Event>\n",
},
},
}

for name, test := range tests {
Expand Down