From 7e908ae0575f927ab579803685247b8722d0da5c Mon Sep 17 00:00:00 2001 From: "Eric D. Schabell" Date: Fri, 20 Jun 2025 15:51:12 +0200 Subject: [PATCH] Adding YAML examples to developers wasm filter plugin docs. Fixes ##1768. Signed-off-by: Eric D. Schabell --- development/wasm-filter-plugins.md | 62 ++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/development/wasm-filter-plugins.md b/development/wasm-filter-plugins.md index 9664b439b..0b61c232d 100644 --- a/development/wasm-filter-plugins.md +++ b/development/wasm-filter-plugins.md @@ -98,7 +98,31 @@ pub extern "C" fn rust_filter(tag: *const c_char, tag_len: u32, time_sec: u32, t 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. -Once built, a Wasm program will be available. Then you can execute that built program with the following Fluent Bit configuration: +Once built, a Wasm program will be available. Then you can execute that built program with one of the following Fluent Bit configurations: + +{% tabs %} +{% tab title="fluent-bit.yaml" %} + +```yaml +pipeline: + inputs: + - name: dummy + tag: dummy.local + + filters: + - name: wasm + match: 'dummy.*' + wasm_path: /path/to/built_filter.wasm + function_name: super_awesome_filter + accessible_paths: /path/to/fluent-bit + + outputs: + - name: stdout + match: '*' +``` + +{% endtab %} +{% tab title="fluent-bit.conf" %} ```text [INPUT] @@ -110,13 +134,16 @@ Once built, a Wasm program will be available. Then you can execute that built pr Match dummy.* WASM_Path /path/to/built_filter.wasm Function_Name super_awesome_filter - accessible_paths .,/path/to/fluent-bit + accessible_paths /path/to/fluent-bit [OUTPUT] Name stdout Match * ``` +{% endtab %} +{% endtabs %} + 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: ```text @@ -125,8 +152,34 @@ For example, one of the sample [Rust Wasm filters](https://github.com/fluent/flu [0] dummy.local: [1666270590.271107000, {"lang"=>"Rust", "message"=>"dummy", "original"=>"{"message":"dummy"}", "tag"=>"dummy.local", "time"=>"2022-10-20T12:56:30.271107000 +0000"}] ``` Another example of a Rust Wasm filter is the [flb_filter_iis](https://github.com/kenriortega/flb_filter_iis) filter. + 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. +{% tabs %} +{% tab title="fluent-bit.yaml" %} + +```yaml +pipeline: + inputs: + - name: dummy + dummy: '{"log": "2023-08-11 19:56:44 W3SVC1 WIN-PC1 ::1 GET / - 80 ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/115.0.0.0+Safari/537.36+Edg/115.0.1901.200 - - localhost 304 142 756 1078 -"}' + tag: 'iis.*' + + filters: + - name: wasm + match: 'iis.*' + wasm_path: /plugins/flb_filter_iis_wasm.wasm + function_name: flb_filter_log_iis_w3c_custom + accessible_paths: . + + outputs: + - name: stdout + match: 'iis.*' +``` + +{% endtab %} +{% tab title="fluent-bit.conf" %} + ```text [INPUT] Name dummy @@ -145,6 +198,9 @@ This filter takes the [Internet Information Services (IIS)](https://learn.micros match iis.* ``` +{% endtab %} +{% endtabs %} + The incoming raw strings from an IIS log are composed of the following fields: `date time s-sitename s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port c-ip cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-bytes cs-bytes time-taken c-authorization-header` @@ -199,4 +255,4 @@ AOT compiling should generate CPU architecture-dependent objects. If you want to * [C filter](https://github.com/fluent/fluent-bit/tree/master/examples/filter_wasm_c) * [Rust Filter](https://github.com/fluent/fluent-bit/tree/master/examples/filter_rust) -* [TinyGo filter](https://github.com/fluent/fluent-bit/tree/master/examples/filter_wasm_go) +* [TinyGo filter](https://github.com/fluent/fluent-bit/tree/master/examples/filter_wasm_go) \ No newline at end of file