Skip to content

Commit 43c68d4

Browse files
[Filebeat] change multiline configuration in awss3 input to parsers (#25873) (#26586)
* change multiline configuration in awss3 input to parsers - switches multiline configuration to parsers - JSON parsing is independent Closes #25249 (cherry picked from commit beaa972) Co-authored-by: Lee Hinman <[email protected]>
1 parent fce1e51 commit 43c68d4

File tree

6 files changed

+58
-26
lines changed

6 files changed

+58
-26
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
576576
- Update PanOS module to parse Global Protect & User ID logs. {issue}24722[24722] {issue}24724[24724] {pull}24927[24927]
577577
- Add HMAC signature validation support for http_endpoint input. {pull}24918[24918]
578578
- Add new grok pattern for iptables module for Ubiquiti UDM {issue}25615[25615] {pull}25616[25616]
579-
- Add multiline support to aws-s3 input. {issue}25249[25249] {pull}25710[25710]
579+
- Add multiline support to aws-s3 input. {issue}25249[25249] {pull}25710[25710] {pull}25873[25873]
580580
- Add monitoring metrics to the `aws-s3` input. {pull}25711[25711]
581581
- Added `network.direction` fields to Zeek and Suricata modules using the `add_network_direction` processor {pull}24620[24620]
582582
- Add Content-Type override to aws-s3 input. {issue}25697[25697] {pull}25772[25772]

x-pack/filebeat/docs/inputs/input-aws-s3.asciidoc

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ setting. If `file_selectors` is given, then any global
112112
`expand_event_list_from_field` value is ignored in favor of the ones
113113
specified in the `file_selectors`. Regex syntax is the same as the Go
114114
language. Files that don't match one of the regexes won't be
115-
processed. <<input-aws-s3-content_type>>, <<input-aws-s3-include_s3_metadata>>,
116-
<<input-aws-s3-multiline>>, <<input-aws-s3-max_bytes>>,
117-
<<input-aws-s3-buffer_size>>, and <<input-aws-s3-encoding>> may also be set for
118-
each file selector.
115+
processed. <<input-aws-s3-content_type>>, <<input-aws-s3-parsers>>,
116+
<<input-aws-s3-include_s3_metadata>>,<<input-aws-s3-max_bytes>>,
117+
<<input-aws-s3-buffer_size>>, and <<input-aws-s3-encoding>> may also
118+
be set for each file selector.
119119

120120
["source", "yml"]
121121
----
@@ -166,15 +166,43 @@ The maximum number of messages to return. Amazon SQS never returns more messages
166166
than this value (however, fewer messages might be returned). Valid values: 1 to
167167
10. Default: 5.
168168

169-
[id="input-{type}-multiline"]
169+
[id="input-{type}-parsers"]
170170
[float]
171-
==== `multiline`
171+
==== `parsers`
172+
173+
beta[]
174+
175+
This option expects a list of parsers that non-JSON logs go through.
176+
177+
Available parsers:
178+
179+
* `multiline`
180+
181+
In this example, {beatname_uc} is reading multiline messages that
182+
consist of XML that start with the `<Event>` tag.
183+
184+
["source","yaml",subs="attributes"]
185+
----
186+
{beatname_lc}.inputs:
187+
- type: {type}
188+
...
189+
parsers:
190+
- multiline:
191+
pattern: "^<Event"
192+
negate: true
193+
match: after
194+
----
195+
196+
See the available parser settings in detail below.
197+
198+
[float]
199+
===== `multiline`
172200

173201
beta[]
174202

175203
Options that control how {beatname_uc} deals with log messages that span
176-
multiple lines. This only applies to non-JSON logs. See <<multiline-examples>>
177-
for more information about configuring multiline options.
204+
multiple lines. See <<multiline-examples>> for more information about
205+
configuring multiline options.
178206

179207
[float]
180208
==== `queue_url`

x-pack/filebeat/input/awss3/collector.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/elastic/beats/v7/libbeat/common"
3333
"github.com/elastic/beats/v7/libbeat/logp"
3434
"github.com/elastic/beats/v7/libbeat/reader"
35-
"github.com/elastic/beats/v7/libbeat/reader/multiline"
3635
"github.com/elastic/beats/v7/libbeat/reader/readfile"
3736
"github.com/elastic/beats/v7/libbeat/reader/readfile/encoding"
3837
"github.com/elastic/go-concert/unison"
@@ -438,12 +437,7 @@ func (c *s3Collector) createEventsFromS3Info(svc s3iface.ClientAPI, info s3Info,
438437
}
439438
r = readfile.NewStripNewline(r, info.LineTerminator)
440439

441-
if info.Multiline != nil {
442-
r, err = multiline.New(r, "\n", int(info.MaxBytes), info.Multiline)
443-
if err != nil {
444-
return fmt.Errorf("error setting up multiline: %v", err)
445-
}
446-
}
440+
r = info.Parsers.Create(r)
447441

448442
r = readfile.NewLimitReader(r, int(info.MaxBytes))
449443

x-pack/filebeat/input/awss3/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/elastic/beats/v7/libbeat/common/cfgtype"
1414
"github.com/elastic/beats/v7/libbeat/common/match"
15-
"github.com/elastic/beats/v7/libbeat/reader/multiline"
15+
"github.com/elastic/beats/v7/libbeat/reader/parser"
1616
"github.com/elastic/beats/v7/libbeat/reader/readfile"
1717
awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws"
1818
)
@@ -66,14 +66,14 @@ type fileSelectorConfig struct {
6666

6767
// readerConfig defines the options for reading the content of an S3 object.
6868
type readerConfig struct {
69-
ExpandEventListFromField string `config:"expand_event_list_from_field"`
7069
BufferSize cfgtype.ByteSize `config:"buffer_size"`
71-
MaxBytes cfgtype.ByteSize `config:"max_bytes"`
72-
Multiline *multiline.Config `config:"multiline"`
73-
LineTerminator readfile.LineTerminator `config:"line_terminator"`
74-
Encoding string `config:"encoding"`
7570
ContentType string `config:"content_type"`
71+
Encoding string `config:"encoding"`
72+
ExpandEventListFromField string `config:"expand_event_list_from_field"`
7673
IncludeS3Metadata []string `config:"include_s3_metadata"`
74+
LineTerminator readfile.LineTerminator `config:"line_terminator"`
75+
MaxBytes cfgtype.ByteSize `config:"max_bytes"`
76+
Parsers parser.Config `config:",inline"`
7777
}
7878

7979
func (f *readerConfig) Validate() error {

x-pack/filebeat/input/awss3/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/elastic/beats/v7/libbeat/common"
1515
"github.com/elastic/beats/v7/libbeat/common/match"
16+
"github.com/elastic/beats/v7/libbeat/reader/parser"
1617
"github.com/elastic/beats/v7/libbeat/reader/readfile"
1718
)
1819

@@ -21,6 +22,10 @@ func TestConfig(t *testing.T) {
2122
makeConfig := func() config {
2223
// Have a separate copy of defaults in the test to make it clear when
2324
// anyone changes the defaults.
25+
cfg := common.MustNewConfigFrom("")
26+
c := parser.Config{}
27+
err := c.Unpack(cfg)
28+
assert.Nil(t, err)
2429
return config{
2530
QueueURL: queueURL,
2631
APITimeout: 120 * time.Second,
@@ -31,6 +36,7 @@ func TestConfig(t *testing.T) {
3136
BufferSize: 16 * humanize.KiByte,
3237
MaxBytes: 10 * humanize.MiByte,
3338
LineTerminator: readfile.AutoLineTerminator,
39+
Parsers: c,
3440
},
3541
}
3642
}

x-pack/filebeat/input/awss3/s3_integration_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ func defaultTestConfig() *common.Config {
8686
{
8787
"regex": strings.Replace(fileName2, ".", "\\.", -1),
8888
"max_bytes": 4096,
89-
"multiline": common.MapStr{
90-
"pattern": "^<Event",
91-
"negate": true,
92-
"match": "after",
89+
"parsers": []common.MapStr{
90+
{
91+
"multiline": common.MapStr{
92+
"pattern": "^<Event",
93+
"negate": true,
94+
"match": "after",
95+
},
96+
},
9397
},
9498
},
9599
},

0 commit comments

Comments
 (0)