You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[WebAssembly](https://webassembly.org/) is binary instruction format for stackbased virtual machine.
3
+
[WebAssembly](https://webassembly.org/)(Wasm) is a binary instruction format for stack-based virtual machines.
4
4
5
-
Fluent Bit currently supports integration of wasm plugins built as wasm/wasi objects for input and filter plugins only.
6
-
The interface for the WASM filter plugins is currently under development but is functional.
5
+
Fluent Bit supports integration of Wasm plugins built as Wasm/WASI objects for input and filter plugins only. The interface for Wasm filter plugins is currently under development but is functional.
7
6
8
7
## Prerequisites
9
8
10
-
### Building Fluent Bit
9
+
### Build Fluent Bit
11
10
12
-
There are no additional requirements to execute WASM plugins.
11
+
There are no additional requirements to execute Wasm plugins.
13
12
14
-
#### Building flb-wamrc (optional)
13
+
#### Build `flb-wamrc` (optional)
15
14
16
-
`flb-wamrc` is just`flb-`prefixed AOT (Ahead Of Time) compiler that is provided from [wasm-micro-runtime](https://github.com/bytecodealliance/wasm-micro-runtime).
15
+
`flb-wamrc` is a`flb`-prefixed AOT (ahead of time) compiler that's provided from [`wasm-micro-runtime`](https://github.com/bytecodealliance/wasm-micro-runtime).
17
16
18
-
For `flb-wamrc` support, users have to install llvm infrastructure and some additional libraries (`libmlir`, `libPolly`, `libedit`, and `libpfm`), e.g:
17
+
For `flb-wamrc` support, you must install the LLVM infrastructure and some additional libraries (`libmlir`, `libPolly`, `libedit`, and `libpfm`). For example:
Currently, Fluent Bit supports the following WASM toolchains:
25
+
Currently, Fluent Bit supports the following Wasm tool chains:
27
26
28
-
* Rust on `wasm32-unknown-unknown`.
27
+
* Rust on `wasm32-unknown-unknown`
29
28
* rustc 1.62.1 (e092d0b6b 2022-07-16) or later
30
-
*[TinyGo](https://github.com/tinygo-org/tinygo) on wasm32-wasi
29
+
*[TinyGo](https://github.com/tinygo-org/tinygo) on `wasm32-wasi`
31
30
* v0.24.0 or later
32
31
*[WASI SDK](https://github.com/WebAssembly/wasi-sdk) 13 or later.
33
32
34
-
## Getting Started
33
+
## Get started
35
34
36
-
As described in general options in [source installation](../installation/sources/build-and-install.md),
37
-
WASM support is enabled by default.
38
-
Compile Fluent Bit with WASM support, e.g:
35
+
As described in the general options in the [source installation](../installation/sources/build-and-install.md) guide, Wasm support is enabled by default. Compile Fluent Bit with Wasm support, for example:
39
36
40
37
```text
41
38
$ cd build/
42
39
$ cmake .. [-DFLB_WAMRC=On]
43
40
$ make
44
41
```
45
42
46
-
To support AOTcompiled WASM execution as filter plugins, users have to built Fluent Bit with `-DFLB_WAMRC=On`.
43
+
To support AOT-compiled Wasm execution as filter plugins, build Fluent Bit with `-DFLB_WAMRC=On`.
47
44
48
-
Once compiled, we can see new plugins in which handles _wasm_, e.g:
45
+
Once compiled, you can see new plugins that handle `wasm`, for example:
49
46
50
47
```text
51
48
$ bin/fluent-bit -h
@@ -59,31 +56,30 @@ Filters
59
56
wasm WASM program filter
60
57
```
61
58
62
-
## Build a WASM Filter for Filter Plugin
59
+
## Build a Wasm filter for filter plugin
63
60
64
-
Currently, Fluent Bit's WASM filter assumes C ABI that is also known as `wasm32-unknown-unknown` on Rust target and `wasm32-wasi` on TinyGo target.
61
+
The Fluent Bit Wasm filter assumes C ABI, also known as `wasm32-unknown-unknown` on Rust target and `wasm32-wasi` on TinyGo target.
65
62
66
63
### To Install Additional Components
67
64
68
-
TinyGo and WASI SDK support wasm target by default.
69
-
When using Rust's `wasm32-unknown-unknown` target, users must install `wasm32-unknown-unknown` via [rustup](https://rustup.rs/). Then, installing that target components as:
65
+
TinyGo and WASI SDK support Wasm target by default. When using Rust's `wasm32-unknown-unknown` target, you must install `wasm32-unknown-unknown` by using [rustup](https://rustup.rs/). Then, install the target components as follows:
70
66
71
67
```text
72
68
$ rustup target add wasm32-unknown-unknown
73
69
```
74
70
75
-
### Requirements of WASM programs
71
+
### Requirements of Wasm programs
76
72
77
-
WASM filter plugins execute the function that has the following signagure.
73
+
Wasm filter plugins execute the function that has the following signature.
78
74
79
75
For C:
80
76
81
77
```text
82
-
// We can use an arbitrary function name for filter operations w/ WASM.
78
+
// We can use an arbitrary function name for filter operations w/ Wasm.
Note that `//export XXX` on TinyGo and `#[no_mangle]`attributes on Rust are required. This is because TinyGo and Rust will mangle their function names if they are not specified.
99
+
The `//export XXX`attribute on TinyGo and `#[no_mangle]`attribute on Rust are required. This is because TinyGo and Rust will mangle their function names if they aren't specified.
104
100
105
-
Once built, a WASM program will be available. Then, that built program can be executed with the following Fluent Bit configuration:
101
+
Once built, a Wasm program will be available. Then you can execute that built program with the following Fluent Bit configuration:
106
102
107
103
```text
108
104
[INPUT]
@@ -121,14 +117,14 @@ Once built, a WASM program will be available. Then, that built program can be ex
121
117
Match *
122
118
```
123
119
124
-
For example, one of the examples of [Rust WASM filter](https://github.com/fluent/fluent-bit/tree/master/examples/filter_rust) should generate its filtered logs as follows:
120
+
For example, one of the sample [Rust Wasm filters](https://github.com/fluent/fluent-bit/tree/master/examples/filter_rust) should generate its filtered logs as follows:
Another example of a Rust WASM filter is the [flb_filter_iis](https://github.com/kenriortega/flb_filter_iis) filter.
127
+
Another example of a Rust Wasm filter is the [flb_filter_iis](https://github.com/kenriortega/flb_filter_iis) filter.
132
128
This filter takes the [Internet Information Services (IIS)](https://learn.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/configure-logging-in-iis)[w3c logs](https://learn.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/configure-logging-in-iis#select-w3c-fields-to-log) (with some custom modifications) and transforms the raw string into a standard Fluent Bit JSON structured record.
133
129
134
130
```text
@@ -158,32 +154,33 @@ The output after the filter logic will be:
This filter approach provides us with several powerful advantages inherent to programming languages.
162
-
For instance, it:
163
-
- Can be extended by adding type conversion to fields such as `sc_bytes, cs_bytes, time_taken`. This is particularly useful when we need to validate our data results.
164
-
- Allows for the use of conditions to apply more descriptive filters, for example, "get only all logs that contain status codes above 4xx or 5xx".
165
-
- Can be used to define a `allow/deny` list using a data structure array or a file to store predefined IP addresses.
166
-
- Makes it possible to call an external resource such as an API or database to enhance our data.
167
-
- Allows all methods to be thoroughly tested and shared as a binary bundle or library.
168
-
These examples can be applied in our demo and can serve as an ideal starting point to create more complex logic, depending on our requirements.
169
157
170
-
### Optimize execution of WASM programs
158
+
This filter approach offers several advantages inherent to programming languages. For example:
159
+
- It can be extended by adding type conversion to fields, such as `sc_bytes`, `cs_bytes`, and `time_taken`. You can use this to validate data results.
160
+
- It allows for the use of conditions to apply more descriptive filters. For example, you can get only all logs that contain status codes higher than `4xx` or `5xx`.
161
+
- It can be used to define allow lists and deny lists using a data structure array or a file to store predefined IP addresses.
162
+
- It makes it possible to call an external resource such as an API or database to enhance your data.
163
+
- It allows all methods to be thoroughly tested and shared as a binary bundle or library.
171
164
172
-
To optimize WASM program execution, there is the option of using `flb-wamrc`.
173
-
`flb-wamrc` will reduce runtime footprint and to be best performance for filtering operations.
174
-
This tool will be built when `-DFLB_WAMRC=On` cmake option is specified and llvm infrastructure is installed on the building box.
165
+
These examples can be applied in a demo and can serve as an ideal starting point to create more complex logic, depending on your requirements.
166
+
167
+
### Optimize execution of Wasm programs
168
+
169
+
To optimize Wasm program execution, there is the option of using `flb-wamrc`. This option reduces your runtime footprint and to be best performance for filtering operations.
170
+
171
+
This tool will be built when the `-DFLB_WAMRC=On` CMake option is specified and LLVM infrastructure is installed on the building box.
Then, when AOT (Ahead Of Time) compiling is succeeded:
183
+
Then, when AOT (Ahead Of Time) compiling has succeeded:
187
184
188
185
```text
189
186
Create AoT compiler with:
@@ -196,13 +193,10 @@ Create AoT compiler with:
196
193
Compile success, file /path/to/built_wasm.aot was generated.
197
194
```
198
195
199
-
Note that AOT compiling should generate CPU architecture-dependent objects. If users want to use AOT compiled object on the different archtecture, it must align the **target** and **target cpu** for actual environments.
196
+
AOT compiling should generate CPU architecture-dependent objects. If you want to use an AOT compiled object on different architecture, it must align the `target` and `target cpu` for actual environments.
0 commit comments