summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/tests/runtime/wasm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:07:37 +0000
commitb485aab7e71c1625cfc27e0f92c9509f42378458 (patch)
treeae9abe108601079d1679194de237c9a435ae5b55 /src/fluent-bit/tests/runtime/wasm
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz
netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/tests/runtime/wasm')
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/Makefile24
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/append_tag.go39
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/drop_record.go8
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/go.mod9
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/go.sum10
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/modify_record.go39
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/numeric_records.go44
-rw-r--r--src/fluent-bit/tests/runtime/wasm/go/say_hello.go14
8 files changed, 187 insertions, 0 deletions
diff --git a/src/fluent-bit/tests/runtime/wasm/go/Makefile b/src/fluent-bit/tests/runtime/wasm/go/Makefile
new file mode 100644
index 000000000..ddd32f884
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/append_tag.go b/src/fluent-bit/tests/runtime/wasm/go/append_tag.go
new file mode 100644
index 000000000..813afc51b
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/drop_record.go b/src/fluent-bit/tests/runtime/wasm/go/drop_record.go
new file mode 100644
index 000000000..30be9711b
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/go.mod b/src/fluent-bit/tests/runtime/wasm/go/go.mod
new file mode 100644
index 000000000..8250a72d2
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/go.sum b/src/fluent-bit/tests/runtime/wasm/go/go.sum
new file mode 100644
index 000000000..8e55f9a78
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/modify_record.go b/src/fluent-bit/tests/runtime/wasm/go/modify_record.go
new file mode 100644
index 000000000..8a53a87fd
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/numeric_records.go b/src/fluent-bit/tests/runtime/wasm/go/numeric_records.go
new file mode 100644
index 000000000..4604f454e
--- /dev/null
+++ b/src/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/src/fluent-bit/tests/runtime/wasm/go/say_hello.go b/src/fluent-bit/tests/runtime/wasm/go/say_hello.go
new file mode 100644
index 000000000..e5efa3f97
--- /dev/null
+++ b/src/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() {}