Skip to content

Commit 45de608

Browse files
committed
Admin: configure: multiline parse: Style updates
Signed-off-by: Lynette Miles <[email protected]>
1 parent ddfbbcc commit 45de608

File tree

1 file changed

+75
-66
lines changed

1 file changed

+75
-66
lines changed

administration/configuring-fluent-bit/multiline-parsing.md

Lines changed: 75 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,106 @@
1-
# Multiline Parsing
1+
# Multiline parsing
22

3-
In an ideal world, applications might log their messages within a single line, but in reality applications generate multiple log messages that sometimes belong to the same context. But when is time to process such information it gets really complex. Consider application stack traces which always have multiple log lines.
3+
In an ideal world, applications might log their messages within a single line, but in
4+
reality applications generate multiple log messages that sometimes belong to the same
5+
context. Processing this information can be complex, like in application stack traces which always have multiple log lines.
46

57
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=e19a4c14-a9e4-4163-8f3a-52196eb9a585" />
68

7-
Starting from Fluent Bit v1.8, we have implemented a unified Multiline core functionality to solve all the user corner cases. In this section, you will learn about the features and configuration options available.
9+
Fluent Bit v1.8 implemented a unified Multiline core capability to solve corner cases.
810

911
## Concepts
1012

11-
The Multiline parser engine exposes two ways to configure and use the functionality:
13+
The Multiline parser engine exposes two ways to configure and use the feature:
1214

13-
* Built-in multiline parser
14-
* Configurable multiline parser
15+
- Built-in multiline parser
16+
- Configurable multiline parser
1517

16-
### Built-in Multiline Parsers
18+
### Built-in multiline parsers
1719

18-
Without any extra configuration, Fluent Bit exposes certain pre-configured parsers (built-in) to solve specific multiline parser cases, e.g:
20+
Fluent Bit exposes certain pre-configured parsers (built-in) to solve specific
21+
multiline parser cases. For example:
1922

20-
| Parser | Description |
21-
| ------ | --------------------------------------------------------------------------------------------------------------------------------------- |
22-
| docker | Process a log entry generated by a Docker container engine. This parser supports the concatenation of log entries split by Docker. |
23-
| cri | Process a log entry generated by CRI-O container engine. Same as the _docker_ parser, it supports concatenation of log entries |
24-
| go | Process log entries generated by a Go based language application and perform concatenation if multiline messages are detected. |
25-
| python | Process log entries generated by a Python based language application and perform concatenation if multiline messages are detected. |
26-
| java | Process log entries generated by a Google Cloud Java language application and perform concatenation if multiline messages are detected. |
23+
| Parser | Description |
24+
| ------ | ----------- |
25+
| `docker` | Process a log entry generated by a Docker container engine. This parser supports the concatenation of log entries split by Docker. |
26+
| `cri` | Process a log entry generated by CRI-O container engine. Like the `docker` parser, it supports concatenation of log entries |
27+
| `go` | Process log entries generated by a Go based language application and perform concatenation if multiline messages are detected. |
28+
| `python` | Process log entries generated by a Python based language application and perform concatenation if multiline messages are detected. |
29+
| `java` | Process log entries generated by a Google Cloud Java language application and perform concatenation if multiline messages are detected. |
2730

28-
### Configurable Multiline Parsers
31+
### Configurable multiline parsers
2932

30-
Besides the built-in parsers listed above, through the configuration files is possible to define your own Multiline parsers with their own rules.
33+
You can define your own Multiline parsers with their own rules, using a configuration
34+
file.
3135

32-
A multiline parser is defined in a _parsers configuration file_ by using a `[MULTILINE_PARSER]` section definition. The Multiline parser must have a unique name and a type plus other configured properties associated with each type.
36+
A multiline parser is defined in a `parsers configuration file` by using a `[MULTILINE_PARSER]` section definition. The multiline parser must have a unique name and a type plus other configured properties associated with each type.
3337

34-
To understand which Multiline parser type is required for your use case you have to know beforehand what are the conditions in the content that determines the beginning of a multiline message and the continuation of subsequent lines. We provide a regex based configuration that supports states to handle from the most simple to difficult cases.
38+
To understand which multiline parser type is required for your use case you have to
39+
know the conditions in the content that determine the beginning of a multiline
40+
message, and the continuation of subsequent lines. Fluent Bit provides a regular expression-based
41+
configuration that supports states to handle from the most cases.
3542

36-
| Property | Description | Default |
37-
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
38-
| name | Specify a unique name for the Multiline Parser definition. A good practice is to prefix the name with the word `multiline_` to avoid confusion with normal parser's definitions. | |
39-
| type | Set the multiline mode, for now, we support the type `regex`. | |
40-
| parser | <p>Name of a pre-defined parser that must be applied to the incoming content before applying the regex rule. If no parser is defined, it's assumed that's a raw text and not a structured message. </p><p></p><p>Note: when a parser is applied to a raw text, then the regex is applied against a specific key of the structured message by using the <code>key_content</code> configuration property (see below).</p> | |
41-
| key_content | For an incoming structured message, specify the key that contains the data that should be processed by the regular expression and possibly concatenated. | |
42-
| flush_timeout | Timeout in milliseconds to flush a non-terminated multiline buffer. Default is set to 5 seconds. | 5s |
43-
| rule | Configure a rule to match a multiline pattern. The rule has a specific format described below. Multiple rules can be defined. | |
43+
| Property | Description | Default |
44+
| -------- | ----------- | ------- |
45+
| `name` | Specify a unique name for the multiline parser definition. A good practice is to prefix the name with the word `multiline_` to avoid confusion with normal parser definitions. | _none_ |
46+
| `type` | Set the multiline mode. Fluent Bit supports the type `regex`.| _none_ |
47+
| `parser` | Name of a pre-defined parser that must be applied to the incoming content before applying the regular expression rule. If no parser is defined, it's assumed that's a raw text and not a structured message. <br /> When a parser is applied to a raw text, the regular expression is applied against a specific key of the structured message by using the `key_content` configuration property. | _none_ |
48+
| `key_content` | For an incoming structured message, specify the key that contains the data that should be processed by the regular expression and possibly concatenated. | _none_ |
49+
| `flush_timeout` | Timeout in milliseconds to flush a non-terminated multiline buffer. | `5s` |
50+
| `rule` | Configure a rule to match a multiline pattern. The rule has a [specific format](#rules-definition). Multiple rules can be defined. | _none_|
4451

45-
#### Lines and States
52+
#### Lines and states
4653

47-
Before start configuring your parser you need to know the answer to the following questions:
54+
Before configuring your parser you need to know the answer to the following questions:
4855

49-
1. What is the regular expression (regex) that matches the first line of a multiline message ?
50-
2. What are the regular expressions (regex) that match the continuation lines of a multiline message ?
56+
1. What's the regular expression (`regex`) that matches the first line of a multiline message?
57+
1. What are the regular expressions (`regex`) that match the continuation lines of a multiline message?
5158

52-
When matching regex, we have to define **states**, some states define the start of a multiline message while others are states for the continuation of multiline messages. You can have multiple **continuation states** definitions to solve complex cases.
59+
When matching a regular expression, you must to define `states`. Some states define the start of a multiline message while others are states for the continuation of multiline messages. You can have multiple `continuation states` definitions to solve complex cases.
5360

54-
The first regex that matches the start of a multiline message is called **start_state**, then other regexes continuation lines can have different state names.
61+
The first regular expression that matches the start of a multiline message is called
62+
`start_state`. Other regular expression continuation lines can have different state names.
5563

56-
#### Rules Definition
64+
#### Rules definition
5765

5866
A rule specifies how to match a multiline pattern and perform the concatenation. A rule is defined by 3 specific components:
5967

60-
1. state name
61-
2. regular expression pattern
62-
3. next state
68+
- state name
69+
- regular expression pattern
70+
- next state
6371

64-
A rule might be defined as follows (comments added to simplify the definition) :
72+
A rule might be defined as follows (comments added to simplify the definition):
6573

66-
```
74+
```text
6775
# rules | state name | regex pattern | next state
6876
# --------|----------------|---------------------------------------------
6977
rule "start_state" "/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/" "cont"
7078
rule "cont" "/^\s+at.*/" "cont"
7179
```
7280

73-
In the example above, we have defined two rules, each one has its own state name, regex patterns, and the next state name. Every field that composes a rule **must be** inside double quotes.
81+
This example defines two rules. Each rule has its own state name, regex patterns, and the next state name. Every field that composes a rule must be inside double quotes.
7482

75-
The first rule of state name **must always** be **start_state**, and the regex pattern **must** match the first line of a multiline message, also a next state must be set to specify how the possible continuation lines would look like.
83+
The first rule of a state name must be `start_state`. The regex pattern must match the first line of a multiline message, and a next state must be set to specify what the possible continuation lines look like.
7684

7785
{% hint style="info" %}
78-
To simplify the configuration of regular expressions, you can use the Rubular web site. We have posted an example by using the regex described above plus a log line that matches the pattern:\
79-
\
80-
[https://rubular.com/r/NDuyKwlTGOvq2g](https://rubular.com/r/NDuyKwlTGOvq2g)
86+
To simplify the configuration of regular expressions, you can use the [Rubular]((https://rubular.com/r/NDuyKwlTGOvq2g)) web site. This link uses the regex described in the previous example, plus a log line that matches the pattern:
8187
{% endhint %}
8288

83-
#### Configuration Example
89+
#### Configuration example
8490

85-
The following example provides a full Fluent Bit configuration file for multiline parsing by using the definition explained above.
91+
The following example provides a full Fluent Bit configuration file for multiline parsing by using the definition explained previously.
8692

8793
{% hint style="info" %}
88-
The following example files can be located at:\
89-
\
90-
[https://github.com/fluent/fluent-bit/tree/master/documentation/examples/multiline/regex-001](https://github.com/fluent/fluent-bit/tree/master/documentation/examples/multiline/regex-001)
94+
The following example files can be located [at this link](https://github.com/fluent/fluent-bit/tree/master/documentation/examples/multiline/regex-001).
9195
{% endhint %}
9296

9397
Example files content:
9498

9599
{% tabs %}
96100
{% tab title="fluent-bit.conf" %}
97-
This is the primary Fluent Bit configuration file. It includes the `parsers_multiline.conf` and tails the file `test.log` by applying the multiline parser `multiline-regex-test`. Then it sends the processing to the standard output.
101+
This is the primary Fluent Bit configuration file. It includes the `parsers_multiline.conf` and tails the file `test.log` by applying the multiline parser `multiline-regex-test`. Then it sends the processing to the standard output.
98102

99-
```
103+
```python
100104
[SERVICE]
101105
flush 1
102106
log_level info
@@ -112,12 +116,13 @@ This is the primary Fluent Bit configuration file. It includes the `parsers_mult
112116
name stdout
113117
match *
114118
```
119+
115120
{% endtab %}
116121

117122
{% tab title="parsers_multiline.conf" %}
118123
This second file defines a multiline parser for the example.
119124

120-
```
125+
```python
121126
[MULTILINE_PARSER]
122127
name multiline-regex-test
123128
type regex
@@ -136,12 +141,13 @@ This second file defines a multiline parser for the example.
136141
rule "start_state" "/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/" "cont"
137142
rule "cont" "/^\s+at.*/" "cont"
138143
```
144+
139145
{% endtab %}
140146

141147
{% tab title="test.log" %}
142148
An example file with multiline content:
143149

144-
```
150+
```text
145151
single line...
146152
Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
147153
at com.myproject.module.MyProject.badMethod(MyProject.java:22)
@@ -152,13 +158,14 @@ Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something
152158
another line...
153159
154160
```
161+
155162
{% endtab %}
156163
{% endtabs %}
157164

158165
By running Fluent Bit with the given configuration file you will obtain:
159166

160-
```
161-
$ fluent-bit -c fluent-bit.conf
167+
```text
168+
$ fluent-bit -c fluent-bit.conf
162169
163170
[0] tail.0: [0.000000000, {"log"=>"single line...
164171
"}]
@@ -174,29 +181,28 @@ $ fluent-bit -c fluent-bit.conf
174181
175182
```
176183

177-
The lines that did not match a pattern are not considered as part of the multiline message, while the ones that matched the rules were concatenated properly.
184+
The lines that didn't match a pattern aren't considered as part of the multiline message, while the ones that matched the rules were concatenated properly.
178185

179186
## Limitations
180187

181188
The multiline parser is a very powerful feature, but it has some limitations that you should be aware of:
182189

183-
* The multiline parser is not affected by the `buffer_max_size` configuration option, allowing the composed log record to grow beyond this size.
184-
Hence, the `skip_long_lines` option will not be applied to multiline messages.
185-
* It is not possible to get the time key from the body of the multiline message. However, it can be extracted and set as a new key by using a filter.
190+
- The multiline parser isn't affected by the `buffer_max_size` configuration option, allowing the composed log record to grow beyond this size. The `skip_long_lines` option won't be applied to multiline messages.
191+
- It's not possible to get the time key from the body of the multiline message. However, it can be extracted and set as a new key by using a filter.
186192

187193
## Get structured data from multiline message
188194

189-
Fluent-bit supports `/pat/m` option. It allows `.` matches a new line. It is useful to parse multiline log.
195+
Fluent-bit supports the `/pat/m` option. It allows `.` matches a new line, which can be used to parse multiline logs.
190196

191-
The following example is to get `date` and `message` from concatenated log.
197+
The following example retrieves `date` and `message` from concatenated logs.
192198

193199
Example files content:
194200

195201
{% tabs %}
196202
{% tab title="fluent-bit.conf" %}
197203
This is the primary Fluent Bit configuration file. It includes the `parsers_multiline.conf` and tails the file `test.log` by applying the multiline parser `multiline-regex-test`. It also parses concatenated log by applying parser `named-capture-test`. Then it sends the processing to the standard output.
198204

199-
```
205+
```python
200206
[SERVICE]
201207
flush 1
202208
log_level info
@@ -218,12 +224,13 @@ This is the primary Fluent Bit configuration file. It includes the `parsers_mult
218224
name stdout
219225
match *
220226
```
227+
221228
{% endtab %}
222229

223230
{% tab title="parsers_multiline.conf" %}
224231
This second file defines a multiline parser for the example.
225232

226-
```
233+
```python
227234
[MULTILINE_PARSER]
228235
name multiline-regex-test
229236
type regex
@@ -247,12 +254,13 @@ This second file defines a multiline parser for the example.
247254
Format regex
248255
Regex /^(?<date>[a-zA-Z]+ \d+ \d+\:\d+\:\d+) (?<message>.*)/m
249256
```
257+
250258
{% endtab %}
251259

252260
{% tab title="test.log" %}
253261
An example file with multiline content:
254262

255-
```
263+
```text
256264
single line...
257265
Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
258266
at com.myproject.module.MyProject.badMethod(MyProject.java:22)
@@ -263,12 +271,13 @@ Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something
263271
another line...
264272

265273
```
274+
266275
{% endtab %}
267276
{% endtabs %}
268277

269278
By running Fluent Bit with the given configuration file you will obtain:
270279

271-
```
280+
```text
272281
$ fluent-bit -c fluent-bit.conf
273282

274283
[0] tail.0: [1669160706.737650473, {"log"=>"single line...
@@ -282,4 +291,4 @@ $ fluent-bit -c fluent-bit.conf
282291
"}]
283292
[2] tail.0: [1669160706.737657687, {"log"=>"another line...
284293
"}]
285-
```
294+
```

0 commit comments

Comments
 (0)