Skip to content

Commit d3e597a

Browse files
authored
filter_lua: add examples for yaml configuration (#1343)
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
1 parent e1f0eaa commit d3e597a

File tree

1 file changed

+113
-25
lines changed

1 file changed

+113
-25
lines changed

pipeline/filters/lua.md

Lines changed: 113 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ $ fluent-bit -i dummy -F lua -p script=test.lua -p call=cb_print -m '*' -o null
3838

3939
In your main configuration file append the following _Input_, _Filter_ & _Output_ sections:
4040

41+
{% tabs %}
42+
{% tab title="fluent-bit.conf" %}
4143
```python
4244
[INPUT]
4345
Name dummy
@@ -52,6 +54,25 @@ In your main configuration file append the following _Input_, _Filter_ & _Output
5254
Name null
5355
Match *
5456
```
57+
{% endtab %}
58+
59+
{% tab title="fluent-bit.yaml" %}
60+
```yaml
61+
pipeline:
62+
inputs:
63+
- name: dummy
64+
filters:
65+
- name: lua
66+
match: '*'
67+
script: test.lua
68+
call: cb_print
69+
outputs:
70+
- name: null
71+
match: '*'
72+
```
73+
{% endtab %}
74+
{% endtabs %}
75+
5576
5677
## Lua Script Filter API <a id="lua_script"></a>
5778
@@ -101,6 +122,32 @@ For functional examples of this interface, please refer to the code samples prov
101122

102123
The [Fluent Bit smoke tests](https://github.com/fluent/fluent-bit/tree/master/packaging/testing/smoke/container) include examples to verify during CI.
103124

125+
{% tabs %}
126+
{% tab title="fluent-bit.conf" %}
127+
```
128+
[SERVICE]
129+
flush 1
130+
daemon off
131+
log_level debug
132+
133+
[INPUT]
134+
Name random
135+
Tag test
136+
Samples 10
137+
138+
[FILTER]
139+
Name Lua
140+
Match *
141+
call append_tag
142+
code function append_tag(tag, timestamp, record) new_record = record new_record["tag"] = tag return 1, timestamp, new_record end
143+
144+
[OUTPUT]
145+
Name stdout
146+
Match *
147+
```
148+
{% endtab %}
149+
150+
{% tab title="fluent-bit.yaml" %}
104151
```yaml
105152
service:
106153
flush: 1
@@ -128,30 +175,8 @@ pipeline:
128175
- name: stdout
129176
match: "*"
130177
```
131-
132-
In classic mode:
133-
134-
```
135-
[SERVICE]
136-
flush 1
137-
daemon off
138-
log_level debug
139-
140-
[INPUT]
141-
Name random
142-
Tag test
143-
Samples 10
144-
145-
[FILTER]
146-
Name Lua
147-
Match *
148-
call append_tag
149-
code function append_tag(tag, timestamp, record) new_record = record new_record["tag"] = tag return 1, timestamp, new_record end
150-
151-
[OUTPUT]
152-
Name stdout
153-
Match *
154-
```
178+
{% endtab %}
179+
{% endtabs %}
155180

156181
#### Environment variable processing
157182

@@ -166,15 +191,33 @@ The environment variable is set like so:
166191

167192
We want to extract the `sandboxbsh` name and add it to our record as a special key.
168193

194+
{% tabs %}
195+
{% tab title="fluent-bit.conf" %}
169196
```
170197
[FILTER]
171198
Name lua
172199
Alias filter-iots-lua
173200
Match iots_thread.*
174201
Script filters.lua
175202
Call set_landscape_deployment
203+
```
204+
{% endtab %}
205+
206+
{% tab title="fluent-bit.yaml" %}
207+
```yaml
208+
filters:
209+
- name: lua
210+
alias: filter-iots-lua
211+
match: iots_thread.*
212+
script: filters.lua
213+
call: set_landscape_deployment
214+
```
215+
{% endtab %}
216+
{% endtabs %}
176217
177-
filters.lua: |
218+
219+
filters.lua:
220+
```lua
178221
-- Use a Lua function to create some additional entries based
179222
-- on substrings from the kubernetes properties.
180223
function set_landscape_deployment(tag, timestamp, record)
@@ -227,6 +270,8 @@ end
227270

228271
#### Configuration
229272

273+
{% tabs %}
274+
{% tab title="fluent-bit.conf" %}
230275
```python
231276
[Input]
232277
Name stdin
@@ -241,6 +286,24 @@ end
241286
Name stdout
242287
Match *
243288
```
289+
{% endtab %}
290+
291+
{% tab title="fluent-bit.yaml" %}
292+
```yaml
293+
pipeline:
294+
inputs:
295+
- name: stdin
296+
filters:
297+
- name: lua
298+
match: '*'
299+
script: test.lua
300+
call: cb_split
301+
outputs:
302+
- name: stdout
303+
match: '*'
304+
```
305+
{% endtab %}
306+
{% endtabs %}
244307
245308
#### Input
246309
@@ -290,6 +353,8 @@ end
290353

291354
Configuration to get istio logs and apply response code filter to them.
292355

356+
{% tabs %}
357+
{% tab title="fluent-bit.conf" %}
293358
```ini
294359
[INPUT]
295360
Name tail
@@ -309,6 +374,29 @@ Configuration to get istio logs and apply response code filter to them.
309374
Name stdout
310375
Match *
311376
```
377+
{% endtab %}
378+
379+
{% tab title="fluent-bit.yaml" %}
380+
```yaml
381+
pipeline:
382+
inputs:
383+
- name: tail
384+
path: /var/log/containers/*_istio-proxy-*.log
385+
multiline.parser: 'docker, cri'
386+
tag: istio.*
387+
mem_buf_limit: 64MB
388+
skip_long_lines: off
389+
filters:
390+
- name: lua
391+
match: istio.*
392+
script: response_code_filter.lua
393+
call: cb_response_code_filter
394+
outputs:
395+
- name: stdout
396+
match: '*'
397+
```
398+
{% endtab %}
399+
{% endtabs %}
312400
313401
#### Input
314402

0 commit comments

Comments
 (0)