From 20263b5db90911ca038c78e4e212d6562e861f4b Mon Sep 17 00:00:00 2001 From: JinXinWang Date: Thu, 18 Jul 2024 14:07:45 +0800 Subject: [PATCH] examples: filter_wasm_go: Upgrade to support Go 1.22.5 and TinyGo 0.32 Signed-off-by: JinXinWang --- examples/filter_wasm_go/README.md | 11 +++++------ examples/filter_wasm_go/filter.go | 6 +++--- examples/filter_wasm_go/go.mod | 8 ++------ examples/filter_wasm_go/go.sum | 16 ---------------- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/examples/filter_wasm_go/README.md b/examples/filter_wasm_go/README.md index 863cf836007..7c0e9c7979a 100644 --- a/examples/filter_wasm_go/README.md +++ b/examples/filter_wasm_go/README.md @@ -7,14 +7,13 @@ This source source tree provides an example of WASM filter program with WASI mod Tested on * TinyGo - * [tinygo](https://tinygo.org/) tinygo version 0.23.0 linux/amd64 (using go version go1.18.2 and LLVM version 14.0.0) - * [tinygo](https://tinygo.org/) tinygo version 0.24.0 linux/amd64 (using go version go1.18.2 and LLVM version 14.0.0) + * [tinygo](https://tinygo.org/) tinygo version 0.32.0 linux/amd64 (using go version go1.22.5 and LLVM version 18.1.2) For Ubuntu, it's easy to install with: ```console -$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.24.0/tinygo_0.24.0_amd64.deb -$ sudo dpkg -i tinygo_0.24.0_amd64.deb +$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.32.0/tinygo_0.32.0_amd64.deb +$ sudo dpkg -i tinygo_0.32.0_amd64.deb ``` ## How to build @@ -22,7 +21,7 @@ $ sudo dpkg -i tinygo_0.24.0_amd64.deb Execute _tinygo build_ as follows: ```console -$ tinygo build -wasm-abi=generic -target=wasi -o filter.wasm filter.go +$ tinygo build -target=wasi -o filter.wasm filter.go ``` Finally, under the same directory, `*.wasm` file will be created: @@ -52,6 +51,7 @@ Create fluent-bit configuration file as follows: [FILTER] Name wasm match dummy.* + Event_Format json WASM_Path /path/to/filter.wasm Function_Name go_filter accessible_paths .,/path/to/fluent-bit @@ -59,5 +59,4 @@ Create fluent-bit configuration file as follows: [OUTPUT] Name stdout Match * - ``` diff --git a/examples/filter_wasm_go/filter.go b/examples/filter_wasm_go/filter.go index fe7303c681c..25a9075505c 100644 --- a/examples/filter_wasm_go/filter.go +++ b/examples/filter_wasm_go/filter.go @@ -31,11 +31,11 @@ func go_filter(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record * obj.Set("time", arena.NewString(now.String())) obj.Set("tag", arena.NewString(string(btag))) obj.Set("original", arena.NewString(br)) - s := obj.String() - s += string(rune(0)) // Note: explicit null terminator. + + s := obj.String() + string(rune(0)) rv := []byte(s) return &rv[0] } -func main() {} +func main() {} \ No newline at end of file diff --git a/examples/filter_wasm_go/go.mod b/examples/filter_wasm_go/go.mod index 8250a72d20f..ec8e1cc8ec9 100644 --- a/examples/filter_wasm_go/go.mod +++ b/examples/filter_wasm_go/go.mod @@ -1,9 +1,5 @@ module filter_wasm_go -go 1.18 +go 1.22.5 -require ( - github.com/valyala/fastjson v1.6.3 // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect - github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect -) +require github.com/valyala/fastjson v1.6.3 diff --git a/examples/filter_wasm_go/go.sum b/examples/filter_wasm_go/go.sum index 2489b8d5436..37063017cde 100644 --- a/examples/filter_wasm_go/go.sum +++ b/examples/filter_wasm_go/go.sum @@ -1,18 +1,2 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc= -github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= -github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= -github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= -github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= -github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=