Skip to content

Commit cc6af37

Browse files
authored
Merge pull request #1476 from fluent/lynettemiles/sc-113441/update-pipeline-filters-nest
2 parents 5e90309 + 9a0d31b commit cc6af37

File tree

1 file changed

+74
-50
lines changed

1 file changed

+74
-50
lines changed

pipeline/filters/nest.md

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Nest
22

3-
The _Nest Filter_ plugin allows you to operate on or with nested data. Its modes of operation are
3+
The _Nest Filter_ plugin lets you operate on or with nested data. Its modes of operation are:
44

5-
* `nest` - Take a set of records and place them in a map
6-
* `lift` - Take a map by key and lift its records up
5+
- `nest` - Take a set of records and place them in a map.
6+
- `lift` - Take a map by key and lift its records up.
77

8-
## Example usage \(nest\)
8+
## Example usage for `nest`
99

10-
As an example using JSON notation, to nest keys matching the `Wildcard` value `Key*` under a new key `NestKey` the transformation becomes,
10+
As an example using JSON notation, to nest keys matching the `Wildcard` value `Key*`
11+
under a new key `NestKey` the transformation becomes:
1112

12-
_Example \(input\)_
13+
Input:
1314

1415
```text
1516
{
@@ -19,7 +20,7 @@ _Example \(input\)_
1920
}
2021
```
2122

22-
_Example \(output\)_
23+
Output:
2324

2425
```text
2526
{
@@ -31,11 +32,12 @@ _Example \(output\)_
3132
}
3233
```
3334

34-
## Example usage \(lift\)
35+
## Example usage for `lift`
3536

36-
As an example using JSON notation, to lift keys nested under the `Nested_under` value `NestKey*` the transformation becomes,
37+
As an example using JSON notation, to lift keys nested under the `Nested_under` value
38+
`NestKey*` the transformation becomes:
3739

38-
_Example \(input\)_
40+
Input:
3941

4042
```text
4143
{
@@ -47,7 +49,7 @@ _Example \(input\)_
4749
}
4850
```
4951

50-
_Example \(output\)_
52+
Output:
5153

5254
```text
5355
{
@@ -61,40 +63,47 @@ _Example \(output\)_
6163

6264
The plugin supports the following configuration parameters:
6365

64-
| Key | Value Format | Operation | Description |
66+
| Key | Value format | Operation | Description |
6567
| :--- | :--- | :--- | :--- |
66-
| Operation | ENUM \[`nest` or `lift`\] | | Select the operation `nest` or `lift` |
67-
| Wildcard | FIELD WILDCARD | `nest` | Nest records which field matches the wildcard |
68-
| Nest\_under | FIELD STRING | `nest` | Nest records matching the `Wildcard` under this key |
69-
| Nested\_under | FIELD STRING | `lift` | Lift records nested under the `Nested_under` key |
70-
| Add\_prefix | FIELD STRING | ANY | Prefix affected keys with this string |
71-
| Remove\_prefix | FIELD STRING | ANY | Remove prefix from affected keys if it matches this string |
68+
| `Operation` | ENUM [`nest` or `lift`] | | Select the operation `nest` or `lift` |
69+
| `Wildcard` | FIELD WILDCARD | `nest` | Nest records which field matches the wildcard |
70+
| `Nest_under` | FIELD STRING | `nest` | Nest records matching the `Wildcard` under this key |
71+
| `Nested_under` | FIELD STRING | `lift` | Lift records nested under the `Nested_under` key |
72+
| `Add_prefix` | FIELD STRING | ANY | Prefix affected keys with this string |
73+
| `Remove_prefix` | FIELD STRING | ANY | Remove prefix from affected keys if it matches this string |
7274

7375
## Getting Started
7476

75-
In order to start filtering records, you can run the filter from the command line or through the configuration file. The following invokes the [Memory Usage Input Plugin](../inputs/memory-metrics.md), which outputs the following \(example\),
77+
To start filtering records, run the filter from the command line or through the
78+
configuration file. The following example invokes the
79+
[Memory Usage Input Plugin](../inputs/memory-metrics.md), which outputs the
80+
following:
7681

7782
```text
7883
[0] memory: [1488543156, {"Mem.total"=>1016044, "Mem.used"=>841388, "Mem.free"=>174656, "Swap.total"=>2064380, "Swap.used"=>139888, "Swap.free"=>1924492}]
7984
```
8085

81-
## Example \#1 - nest
86+
## Example 1 - nest
8287

8388
### Command Line
8489

85-
> Note: Using the command line mode requires quotes parse the wildcard properly. The use of a configuration file is recommended.
90+
Using command line mode requires quotes to parse the wildcard properly. The use
91+
of a configuration file is recommended.
8692

87-
The following command will load the _mem_ plugin. Then the _nest_ filter will match the wildcard rule to the keys and nest the keys matching `Mem.*` under the new key `NEST`.
93+
The following command loads the _mem_ plugin. Then the _nest_ filter matches the
94+
wildcard rule to the keys and nests the keys matching `Mem.*` under the new key
95+
`NEST`.
8896

89-
```text
90-
$ bin/fluent-bit -i mem -p 'tag=mem.local' -F nest -p 'Operation=nest' -p 'Wildcard=Mem.*' -p 'Nest_under=Memstats' -p 'Remove_prefix=Mem.' -m '*' -o stdout
97+
```shell copy
98+
bin/fluent-bit -i mem -p 'tag=mem.local' -F nest -p 'Operation=nest' -p 'Wildcard=Mem.*' -p 'Nest_under=Memstats' -p 'Remove_prefix=Mem.' -m '*' -o stdout
9199
```
92100

93101
### Configuration File
94102

95103
{% tabs %}
96104
{% tab title="fluent-bit.conf" %}
97-
```python
105+
106+
```python copy
98107
[INPUT]
99108
Name mem
100109
Tag mem.local
@@ -111,10 +120,12 @@ $ bin/fluent-bit -i mem -p 'tag=mem.local' -F nest -p 'Operation=nest' -p 'Wildc
111120
Nest_under Memstats
112121
Remove_prefix Mem.
113122
```
123+
114124
{% endtab %}
115125

116126
{% tab title="fluent-bit.yaml" %}
117-
```yaml
127+
128+
```yaml copy
118129
pipeline:
119130
inputs:
120131
- name: mem
@@ -130,6 +141,7 @@ pipeline:
130141
- name: stdout
131142
match: '*'
132143
```
144+
133145
{% endtab %}
134146
{% endtabs %}
135147
@@ -142,15 +154,17 @@ The output of both the command line and configuration invocations should be iden
142154
[0] mem.local: [1522978514.007359767, {"Swap.total"=>1046524, "Swap.used"=>0, "Swap.free"=>1046524, "Memstats"=>{"total"=>4050908, "used"=>714984, "free"=>3335924}}]
143155
```
144156
145-
## Example \#2 - nest and lift undo
157+
## Example 2 - nest and lift undo
146158
147-
This example nests all `Mem.*` and `Swap,*` items under the `Stats` key and then reverses these actions with a `lift` operation. The output appears unchanged.
159+
This example nests all `Mem.*` and `Swap.*` items under the `Stats` key and then
160+
reverses these actions with a `lift` operation. The output appears unchanged.
148161

149-
### Configuration File
162+
### Example 2 Configuration File
150163

151164
{% tabs %}
152165
{% tab title="fluent-bit.conf" %}
153-
```python
166+
167+
```python copy
154168
[INPUT]
155169
Name mem
156170
Tag mem.local
@@ -175,10 +189,11 @@ This example nests all `Mem.*` and `Swap,*` items under the `Stats` key and then
175189
Nested_under Stats
176190
Remove_prefix NESTED
177191
```
178-
{% endtab %}
179192

193+
{% endtab %}
180194
{% tab title="fluent-bit.yaml" %}
181-
```yaml
195+
196+
```yaml copy
182197
pipeline:
183198
inputs:
184199
- name: mem
@@ -201,6 +216,7 @@ pipeline:
201216
- name: stdout
202217
match: '*'
203218
```
219+
204220
{% endtab %}
205221
{% endtabs %}
206222

@@ -211,15 +227,17 @@ pipeline:
211227
[0] mem.local: [1529566958.000940636, {"Mem.total"=>8053656, "Mem.used"=>6940380, "Mem.free"=>1113276, "Swap.total"=>16532988, "Swap.used"=>1286772, "Swap.free"=>15246216}]
212228
```
213229

214-
## Example \#3 - nest 3 levels deep
230+
## Example 3 - nest 3 levels deep
215231

216-
This example takes the keys starting with `Mem.*` and nests them under `LAYER1`, which itself is then nested under `LAYER2`, which is nested under `LAYER3`.
232+
This example takes the keys starting with `Mem.*` and nests them under `LAYER1`,
233+
which is then nested under `LAYER2`, which is nested under `LAYER3`.
217234

218-
### Configuration File
235+
### Example 3 Configuration File
219236

220237
{% tabs %}
221238
{% tab title="fluent-bit.conf" %}
222-
```python
239+
240+
```python copy
223241
[INPUT]
224242
Name mem
225243
Tag mem.local
@@ -249,10 +267,11 @@ This example takes the keys starting with `Mem.*` and nests them under `LAYER1`,
249267
Wildcard LAYER2*
250268
Nest_under LAYER3
251269
```
252-
{% endtab %}
253270

271+
{% endtab %}
254272
{% tab title="fluent-bit.yaml" %}
255-
```yaml
273+
274+
```yaml copy
256275
pipeline:
257276
inputs:
258277
- name: mem
@@ -277,6 +296,7 @@ pipeline:
277296
- name: stdout
278297
match: '*'
279298
```
299+
280300
{% endtab %}
281301
{% endtabs %}
282302

@@ -302,15 +322,19 @@ pipeline:
302322
}
303323
```
304324

305-
## Example \#4 - multiple nest and lift filters with prefix
325+
## Example 4 - multiple nest and lift filters with prefix
306326

307-
This example starts with the 3-level deep nesting of _Example 2_ and applies the `lift` filter three times to reverse the operations. The end result is that all records are at the top level, without nesting, again. One prefix is added for each level that is lifted.
327+
This example uses the 3-level deep nesting of _Example 2_ and applies the
328+
`lift` filter three times to reverse the operations. The end result is that all
329+
records are at the top level, without nesting, again. One prefix is added for each
330+
level that's lifted.
308331

309332
### Configuration file
310333

311334
{% tabs %}
312335
{% tab title="fluent-bit.conf" %}
313-
```python
336+
337+
```python copy
314338
[INPUT]
315339
Name mem
316340
Tag mem.local
@@ -361,10 +385,12 @@ This example starts with the 3-level deep nesting of _Example 2_ and applies the
361385
Nested_under Lifted3_Lifted2_LAYER1
362386
Add_prefix Lifted3_Lifted2_Lifted1_
363387
```
388+
364389
{% endtab %}
365390

366391
{% tab title="fluent-bit.yaml" %}
367-
```yaml
392+
393+
```yaml copy
368394
pipeline:
369395
inputs:
370396
- name: mem
@@ -404,23 +430,21 @@ pipeline:
404430
- name: stdout
405431
match: '*'
406432
```
433+
407434
{% endtab %}
408435
{% endtabs %}
409436

410-
411437
### Result
412438

413439
```text
414440
[0] mem.local: [1524862951.013414798, {"Swap.total"=>1046524, "Swap.used"=>0, "Swap.free"=>1046524, "Lifted3_Lifted2_Lifted1_Mem.total"=>4050908, "Lifted3_Lifted2_Lifted1_Mem.used"=>1253912, "Lifted3_Lifted2_Lifted1_Mem.free"=>2796996}]
415441
416-
417442
{
418-
"Swap.total"=>1046524,
419-
"Swap.used"=>0,
420-
"Swap.free"=>1046524,
421-
"Lifted3_Lifted2_Lifted1_Mem.total"=>4050908,
422-
"Lifted3_Lifted2_Lifted1_Mem.used"=>1253912,
443+
"Swap.total"=>1046524,
444+
"Swap.used"=>0,
445+
"Swap.free"=>1046524,
446+
"Lifted3_Lifted2_Lifted1_Mem.total"=>4050908,
447+
"Lifted3_Lifted2_Lifted1_Mem.used"=>1253912,
423448
"Lifted3_Lifted2_Lifted1_Mem.free"=>2796996
424449
}
425450
```
426-

0 commit comments

Comments
 (0)