Skip to content

Commit f9f9f74

Browse files
leehinmanmergify-bot
authored andcommitted
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 2af8ab9)
1 parent 1b145c6 commit f9f9f74

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
220220
- Fix default config template values for paths on oracle module: {pull}26276[26276]
221221
- Do not close filestream harvester if an unexpected error is returned when close.on_state_change.* is enabled. {pull}26411[26411]
222222
- Fix Elasticsearch compatibility for modules that use `copy_from` in `set` processors. {issue}26629[26629]
223+
- Change type of max_bytes in all configs to be cfgtype.ByteSize {pull}26699[26699]
223224

224225
*Filebeat*
225226

libbeat/reader/parser/parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/dustin/go-humanize"
2626

2727
"github.com/elastic/beats/v7/libbeat/common"
28+
"github.com/elastic/beats/v7/libbeat/common/cfgtype"
2829
"github.com/elastic/beats/v7/libbeat/reader"
2930
"github.com/elastic/beats/v7/libbeat/reader/multiline"
3031
"github.com/elastic/beats/v7/libbeat/reader/readfile"
@@ -43,7 +44,7 @@ type Parser interface {
4344
}
4445

4546
type CommonConfig struct {
46-
MaxBytes int `config:"max_bytes"`
47+
MaxBytes cfgtype.ByteSize `config:"max_bytes"`
4748
LineTerminator readfile.LineTerminator `config:"line_terminator"`
4849
}
4950

@@ -126,7 +127,7 @@ func (c *Config) Create(in reader.Reader) Parser {
126127
if err != nil {
127128
return p
128129
}
129-
p, err = multiline.New(p, "\n", c.pCfg.MaxBytes, &config)
130+
p, err = multiline.New(p, "\n", int(c.pCfg.MaxBytes), &config)
130131
if err != nil {
131132
return p
132133
}

libbeat/reader/parser/parser_example_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import (
2323
"github.com/stretchr/testify/require"
2424

2525
"github.com/elastic/beats/v7/libbeat/common"
26+
"github.com/elastic/beats/v7/libbeat/common/cfgtype"
2627
"github.com/elastic/beats/v7/libbeat/reader/readfile"
2728
)
2829

2930
type inputParsersConfig struct {
30-
MaxBytes int `config:"max_bytes"`
31+
MaxBytes cfgtype.ByteSize `config:"max_bytes"`
3132
LineTerminator readfile.LineTerminator `config:"line_terminator"`
3233
Parsers Config `config:",inline"`
3334
}
@@ -70,6 +71,34 @@ func TestParsersExampleInline(t *testing.T) {
7071
"[log] In total there should be 3 events\n",
7172
},
7273
},
74+
"humanize max_bytes, multiline XML": {
75+
lines: `<Event><Data>
76+
A
77+
B
78+
C</Data></Event>
79+
<Event><Data>
80+
D
81+
E
82+
F</Data></Event>
83+
`,
84+
parsers: map[string]interface{}{
85+
"max_bytes": "4 KiB",
86+
"line_terminator": "auto",
87+
"parsers": []map[string]interface{}{
88+
map[string]interface{}{
89+
"multiline": map[string]interface{}{
90+
"match": "after",
91+
"negate": true,
92+
"pattern": "^<Event",
93+
},
94+
},
95+
},
96+
},
97+
expectedMessages: []string{
98+
"<Event><Data>\n\n\tA\n\n\tB\n\n\tC</Data></Event>\n",
99+
"<Event><Data>\n\n\tD\n\n\tE\n\n\tF</Data></Event>\n",
100+
},
101+
},
73102
}
74103

75104
for name, test := range tests {

0 commit comments

Comments
 (0)