Skip to content

Commit f5e797a

Browse files
author
Pat
authored
filter_lua: add inline code details (fluent#789)
Signed-off-by: Patrick Stephens <[email protected]>
1 parent 72f6a8d commit f5e797a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

pipeline/filters/lua.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The plugin supports the following configuration parameters:
1919
| type\_array\_key| If these keys are matched, the fields are handled as array. If more than one key, delimit by space. It is useful the array can be empty. |
2020
| protected\_mode | If enabled, Lua script will be executed in protected mode. It prevents Fluent Bit from crashing when invalid Lua script is executed or the triggered Lua function throws exceptions. Default is true. |
2121
| time\_as\_table | By default when the Lua script is invoked, the record timestamp is passed as a *floating number* which might lead to precision loss when it is converted back. If you desire timestamp precision, enabling this option will pass the timestamp as a Lua table with keys `sec` for seconds since epoch and `nsec` for nanoseconds. |
22+
| code | Inline LUA code instead of loading from a path via `script`. |
2223

2324
## Getting Started <a id="getting_started"></a>
2425

@@ -95,6 +96,62 @@ For functional examples of this interface, please refer to the code samples prov
9596

9697
[https://github.com/fluent/fluent-bit/tree/master/scripts](https://github.com/fluent/fluent-bit/tree/master/scripts)
9798

99+
#### Inline configuration
100+
101+
The [Fluent Bit smoke tests](https://github.com/fluent/fluent-bit/tree/master/packaging/testing/smoke/container) include examples to verify during CI.
102+
103+
```yaml
104+
service:
105+
flush: 1
106+
daemon: off
107+
log_level: info
108+
109+
pipeline:
110+
inputs:
111+
- random:
112+
tag: test
113+
samples: 10
114+
115+
filters:
116+
- lua:
117+
match: "*"
118+
call: append_tag
119+
code: |
120+
function append_tag(tag, timestamp, record)
121+
new_record = record
122+
new_record["tag"] = tag
123+
return 1, timestamp, new_record
124+
end
125+
126+
outputs:
127+
- stdout:
128+
match: "*"
129+
```
130+
131+
In classic mode:
132+
133+
```
134+
[SERVICE]
135+
flush 1
136+
daemon off
137+
log_level debug
138+
139+
[INPUT]
140+
Name random
141+
Tag test
142+
Samples 10
143+
144+
[FILTER]
145+
Name Lua
146+
Match *
147+
call append_tag
148+
code function append_tag(tag, timestamp, record) new_record = record new_record["tag"] = tag return 1, timestamp, new_record end
149+
150+
[OUTPUT]
151+
Name stdout
152+
Match *
153+
```
154+
98155
#### Environment variable processing
99156

100157
As an example that combines a bit of LUA processing with the [Kubernetes filter](./kubernetes.md) that demonstrates using environment variables with LUA regex and substitutions.

0 commit comments

Comments
 (0)