summaryrefslogtreecommitdiffstats
path: root/fluent-bit/tests/runtime/wasm/go
diff options
context:
space:
mode:
Diffstat (limited to 'fluent-bit/tests/runtime/wasm/go')
-rw-r--r--fluent-bit/tests/runtime/wasm/go/Makefile24
-rw-r--r--fluent-bit/tests/runtime/wasm/go/append_tag.go39
-rw-r--r--fluent-bit/tests/runtime/wasm/go/drop_record.go8
-rw-r--r--fluent-bit/tests/runtime/wasm/go/go.mod9
-rw-r--r--fluent-bit/tests/runtime/wasm/go/go.sum10
-rw-r--r--fluent-bit/tests/runtime/wasm/go/modify_record.go39
-rw-r--r--fluent-bit/tests/runtime/wasm/go/numeric_records.go44
-rw-r--r--fluent-bit/tests/runtime/wasm/go/say_hello.go14
8 files changed, 187 insertions, 0 deletions
diff --git a/fluent-bit/tests/runtime/wasm/go/Makefile b/fluent-bit/tests/runtime/wasm/go/Makefile
new file mode 100644
index 00000000..ddd32f88
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/Makefile
@@ -0,0 +1,24 @@
+.PHONY: build
+
+build: append_tag numeric_records say_hello modify_record
+
+append_tag:
+ tinygo build -wasm-abi=generic -target=wasi -o $@.wasm $@.go
+
+modify_record:
+ tinygo build -wasm-abi=generic -target=wasi -o $@.wasm $@.go
+
+numeric_records:
+ tinygo build -wasm-abi=generic -target=wasi -o $@.wasm $@.go
+
+say_hello:
+ tinygo build -wasm-abi=generic -target=wasi -o $@.wasm $@.go
+
+drop_record:
+ tinygo build -wasm-abi=generic -target=wasi -o $@.wasm $@.go
+
+testdata:
+ cp *.wasm ../../data/wasm
+
+clean:
+ rm -f *.wasm
diff --git a/fluent-bit/tests/runtime/wasm/go/append_tag.go b/fluent-bit/tests/runtime/wasm/go/append_tag.go
new file mode 100644
index 00000000..813afc51
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/append_tag.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+ "time"
+ "unsafe"
+
+ "github.com/valyala/fastjson"
+)
+
+//export filter_append_tag
+func filter_append_tag(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 {
+ btag := unsafe.Slice(tag, tag_len) // Note, requires Go 1.17+ (tinygo 0.20+)
+ brecord := unsafe.Slice(record, record_len)
+ _ = time.Unix(int64(time_sec), int64(time_nsec))
+
+ br := string(brecord)
+ var p fastjson.Parser
+ value, err := p.Parse(br)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+ obj, err := value.Object()
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ var arena fastjson.Arena
+ obj.Set("tag", arena.NewString(string(btag)))
+ s := obj.String()
+ s += string(rune(0)) // Note: explicit null terminator.
+ rv := []byte(s)
+
+ return &rv[0]
+}
+
+func main() {}
diff --git a/fluent-bit/tests/runtime/wasm/go/drop_record.go b/fluent-bit/tests/runtime/wasm/go/drop_record.go
new file mode 100644
index 00000000..30be9711
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/drop_record.go
@@ -0,0 +1,8 @@
+package main
+
+//export filter_drop_record
+func filter_drop_record(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 {
+ return nil
+}
+
+func main() {}
diff --git a/fluent-bit/tests/runtime/wasm/go/go.mod b/fluent-bit/tests/runtime/wasm/go/go.mod
new file mode 100644
index 00000000..8250a72d
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/go.mod
@@ -0,0 +1,9 @@
+module filter_wasm_go
+
+go 1.18
+
+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
+)
diff --git a/fluent-bit/tests/runtime/wasm/go/go.sum b/fluent-bit/tests/runtime/wasm/go/go.sum
new file mode 100644
index 00000000..8e55f9a7
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/go.sum
@@ -0,0 +1,10 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+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/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
+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=
diff --git a/fluent-bit/tests/runtime/wasm/go/modify_record.go b/fluent-bit/tests/runtime/wasm/go/modify_record.go
new file mode 100644
index 00000000..8a53a87f
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/modify_record.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+ "time"
+ "unsafe"
+
+ "github.com/valyala/fastjson"
+)
+
+//export filter_modify_record
+func filter_modify_record(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 {
+ _ = unsafe.Slice(tag, tag_len) // Note, requires Go 1.17+ (tinygo 0.20+)
+ brecord := unsafe.Slice(record, record_len)
+ _ = time.Unix(int64(time_sec), int64(time_nsec))
+
+ br := string(brecord)
+ var p fastjson.Parser
+ value, err := p.Parse(br)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+ obj, err := value.Object()
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ var arena fastjson.Arena
+ obj.Set("modify", arena.NewString(string("yes")))
+ s := obj.String()
+ s += string(rune(0)) // Note: explicit null terminator.
+ rv := []byte(s)
+
+ return &rv[0]
+}
+
+func main() {}
diff --git a/fluent-bit/tests/runtime/wasm/go/numeric_records.go b/fluent-bit/tests/runtime/wasm/go/numeric_records.go
new file mode 100644
index 00000000..4604f454
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/numeric_records.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "fmt"
+ "time"
+ "unsafe"
+
+ "github.com/valyala/fastjson"
+)
+
+//export filter_numeric_records
+func filter_numeric_records(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 {
+ _ = unsafe.Slice(tag, tag_len) // Note, requires Go 1.17+ (tinygo 0.20+)
+ brecord := unsafe.Slice(record, record_len)
+ _ = time.Unix(int64(time_sec), int64(time_nsec))
+
+ br := string(brecord)
+ var p fastjson.Parser
+ value, err := p.Parse(br)
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+ obj, err := value.Object()
+ if err != nil {
+ fmt.Println(err)
+ return nil
+ }
+
+ var arena fastjson.Arena
+ obj.Set("wasm_int1", arena.NewNumberInt(10))
+ obj.Set("wasm_int2", arena.NewNumberInt(100))
+ obj.Set("wasm_float1", arena.NewNumberFloat64(10.5))
+ obj.Set("wasm_float2", arena.NewNumberFloat64(100.5))
+ obj.Set("wasm_truncate_float", arena.NewNumberFloat64(120.0))
+ obj.Set("wasm_exp_float", arena.NewNumberFloat64(3.54789e-3))
+ s := obj.String()
+ s += string(rune(0)) // Note: explicit null terminator.
+ rv := []byte(s)
+
+ return &rv[0]
+}
+
+func main() {}
diff --git a/fluent-bit/tests/runtime/wasm/go/say_hello.go b/fluent-bit/tests/runtime/wasm/go/say_hello.go
new file mode 100644
index 00000000..e5efa3f9
--- /dev/null
+++ b/fluent-bit/tests/runtime/wasm/go/say_hello.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "fmt"
+)
+
+//export filter_say_hello
+func filter_say_hello(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 {
+ fmt.Println("Hello from WASM!")
+
+ return record
+}
+
+func main() {}