From 73a23a2fbbc23a33215f5409d446e9cb850a8ec4 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:19:42 +0900 Subject: [PATCH 01/39] Add tinygo lang Signed-off-by: mathetake --- DEVELOPER.md | 53 --------------- Makefile | 4 +- .../default/go.mod | 8 +++ .../default/go.sum | 13 ++++ .../default/main.go | 29 ++++++++ .../default/main_test.go | 27 ++++++++ .../tinygo/envoy.filters.http/default/go.mod | 8 +++ .../tinygo/envoy.filters.http/default/go.sum | 13 ++++ .../tinygo/envoy.filters.http/default/main.go | 68 +++++++++++++++++++ .../envoy.filters.http/default/main_test.go | 37 ++++++++++ .../envoy.filters.network/default/go.mod | 8 +++ .../envoy.filters.network/default/go.sum | 13 ++++ .../envoy.filters.network/default/main.go | 51 ++++++++++++++ .../default/main_test.go | 43 ++++++++++++ go.mod | 7 +- go.sum | 61 +++++++++++++---- .../{rust => }/entrypoint.sh | 0 images/extension-builders/rust/Dockerfile | 2 +- images/extension-builders/tinygo/Dockerfile | 28 ++++++++ images/extension-builders/tinygo/commands.sh | 29 ++++++++ pkg/cmd/extension/init/cmd.go | 1 + .../workspace/config/extension/helpers.go | 2 +- .../workspace/config/extension/types.go | 4 +- .../toolchain/builtin/default_config.go | 7 +- .../toolchain/builtin/default_config_test.go | 3 +- .../toolchain/builtin/example_config_test.go | 4 +- .../default_config/tinygo.toolchain.yaml | 6 ++ .../example_config/tinygo.toolchain.yaml | 56 +++++++++++++++ test/e2e/e2e_suite_test.go | 7 ++ test/e2e/getenvoy_extension_build_test.go | 1 + test/e2e/getenvoy_extension_examples_test.go | 1 + test/e2e/getenvoy_extension_init_test.go | 1 + test/e2e/getenvoy_extension_run_test.go | 1 + test/e2e/getenvoy_extension_test_test.go | 1 + 34 files changed, 517 insertions(+), 80 deletions(-) create mode 100644 data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod create mode 100644 data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum create mode 100644 data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go create mode 100644 data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/main.go create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/main.go create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go rename images/extension-builders/{rust => }/entrypoint.sh (100%) create mode 100644 images/extension-builders/tinygo/Dockerfile create mode 100755 images/extension-builders/tinygo/commands.sh create mode 100644 pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml create mode 100644 pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml diff --git a/DEVELOPER.md b/DEVELOPER.md index ab65cbea..72509330 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -42,62 +42,9 @@ getenvoy extension init my-extension ``` and follow the wizard. -> NOTE: At the moment, `Rust` extensions have a dependency on a private `GitHub` repository [tetratelabs/envoy-wasm-rust-sdk](https://github.com/tetratelabs/envoy-wasm-rust-sdk). -> -> In practice, it means that `Rust` toolchain (`cargo`) will have to pass through [GitHub authenticatation]() to be able to fetch the source code of [tetratelabs/envoy-wasm-rust-sdk](https://github.com/tetratelabs/envoy-wasm-rust-sdk). -> -> For more details see a section on [SSH authentication](https://doc.rust-lang.org/cargo/appendix/git-authentication.html#ssh-authentication) in the [Cargo Book](https://doc.rust-lang.org/cargo/). - -To build a Wasm extension on `Mac OS`, do the following: -1. [Configure SSH agent](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent) -2. Run: - ```shell - cd my-new-extension - - getenvoy extension build --toolchain-container-options \ - '--mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock' - ``` - ### How to run e2e Tests Run: ```shell make e2e ``` - -> NOTE: At the moment, `Rust` extensions have a dependency on a private `GitHub` repository [tetratelabs/envoy-wasm-rust-sdk](https://github.com/tetratelabs/envoy-wasm-rust-sdk). -> -> In practice, it means that `Rust` toolchain (`cargo`) will have to pass through [GitHub authenticatation]() to be able to fetch the source code of [tetratelabs/envoy-wasm-rust-sdk](https://github.com/tetratelabs/envoy-wasm-rust-sdk). -> -> For more details see a section on [SSH authentication](https://doc.rust-lang.org/cargo/appendix/git-authentication.html#ssh-authentication) in the [Cargo Book](https://doc.rust-lang.org/cargo/). - -To run e2e tests on `Mac OS`, do the following: -1. [Configure SSH agent](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent) -2. Run: - ```shell - bash -c ' - set -e - - # - # restore original ownership over the SSH agent socket (mounted inside container) - # - trap "docker run --rm -t --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock busybox chown 0 /run/host-services/ssh-auth.sock" EXIT - - # - # pass ownership over the SSH agent socket (mounted inside container) to the current user - # - docker run --rm -t --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock busybox chown $(id -u) /run/host-services/ssh-auth.sock - - # - # Run e2e tests in the following context: - # 1. Pass SSH agent socket (so that build containers could download private dependencies) - # 2. Override location of Cargo cache (so that all extensions and their build containers could share the same cache) - # - E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS=" \ - --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock \ - -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \ - -v /tmp/cache/getenvoy:/tmp/cache/getenvoy \ - -e CARGO_HOME=/tmp/cache/getenvoy/extension/rust-builder/cargo" \ - make e2e - ' - ``` diff --git a/Makefile b/Makefile index c1e2c5f6..31eb767d 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ ENVOY = standard:1.11.1 HUB ?= docker.io/getenvoy GETENVOY_TAG ?= dev -BUILDERS_LANGS := rust +BUILDERS_LANGS := rust tinygo BUILDERS_TAG ?= latest EXTRA_TAG ?= @@ -133,7 +133,7 @@ builder/$(1): $(if $(USE_DOCKER_BUILDKIT_CACHE),--build-arg BUILDKIT_INLINE_CACHE=1,) \ $(if $(USE_DOCKER_BUILDKIT_CACHE),--cache-from $(call EXTENSION_BUILDER_IMAGE,$(1),$(EXTENSION_BUILDER_IMAGE_LATEST_VERSION)),) \ -t $(call EXTENSION_BUILDER_IMAGE,$(1),$(BUILDERS_TAG)) \ - images/extension-builders/$(1) + -f images/extension-builders/$(1)/Dockerfile images/extension-builders endef $(foreach lang,$(BUILDERS_LANGS),$(eval $(call GEN_BUILD_EXTENSION_BUILDER_IMAGE_TARGET,$(lang)))) diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod new file mode 100644 index 00000000..4d2560ee --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod @@ -0,0 +1,8 @@ +module my.filters.http + +go 1.15 + +require ( + github.com/stretchr/testify v1.6.1 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 +) diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum new file mode 100644 index 00000000..fdb00ca2 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go new file mode 100644 index 00000000..e3f2af62 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" +) + +func main() { + proxywasm.SetNewRootContext(newAccessLogger) +} + +type accessLogger struct { + // you must embed the default context + proxywasm.DefaultRootContext +} + +func newAccessLogger(contextID uint32) proxywasm.RootContext { + return &accessLogger{} +} + +// override +func (ctx *accessLogger) OnLog() { + hdr, err := proxywasm.GetHttpRequestHeader(":path") + if err != nil { + proxywasm.LogCritical(err.Error()) + return + } + + proxywasm.LogInfof("OnLog: :path = %s", hdr) +} diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go new file mode 100644 index 00000000..560360d6 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +func TestHelloWorld_OnTick(t *testing.T) { + opt := proxytest.NewEmulatorOption(). + WithNewRootContext(newAccessLogger) + host := proxytest.NewHostEmulator(opt) + defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + + host.CallOnLogForAccessLogger([][2]string{{":path", "/this/is/path"}}, nil) // call OnLog + + logs := host.GetLogs(types.LogLevelInfo) + require.Greater(t, len(logs), 0) + msg := logs[len(logs)-1] + + assert.True(t, strings.Contains(msg, "/this/is/path")) +} diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod new file mode 100644 index 00000000..4d2560ee --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -0,0 +1,8 @@ +module my.filters.http + +go 1.15 + +require ( + github.com/stretchr/testify v1.6.1 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 +) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum new file mode 100644 index 00000000..fdb00ca2 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go new file mode 100644 index 00000000..a1f22028 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +var ( + requestCounterName = "my_http_filter.request_counter" + counter proxywasm.MetricCounter +) + +func main() { + proxywasm.SetNewRootContext(newRootContext) + proxywasm.SetNewHttpContext(newHttpContext) +} + +type rootContext struct { + // we must embed the default context + proxywasm.DefaultRootContext + contextID uint32 +} + +func newRootContext(rootContextID uint32) proxywasm.RootContext { + return &rootContext{contextID: rootContextID} +} + +func (ctx *rootContext) OnVMStart(vmConfigurationSize int) bool { + counter = proxywasm.DefineCounterMetric(requestCounterName) + return true +} + +type httpContext struct { + // you must embed the default context + proxywasm.DefaultHttpContext + rootContextID, contextID uint32 +} + +func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext { + return &httpContext{contextID: contextID, rootContextID: rootContextID} +} + +func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { + hs, err := proxywasm.GetHttpRequestHeaders() + if err != nil { + proxywasm.LogCriticalf("failed to get request headers: %v", err) + return types.ActionPause + } + + proxywasm.LogInfo("observing request headers") + for _, h := range hs { + proxywasm.LogInfof("%s: %s", h[0], h[1]) + } + + return types.ActionContinue +} + +func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { + if err := proxywasm.SetHttpResponseHeader("additional", "header"); err != nil { + proxywasm.LogCriticalf("failed to add header: %v", err) + return types.ActionPause + } + return types.ActionContinue +} + +func (ctx *httpContext) OnHttpStreamDone() { + counter.Increment(1) +} diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go new file mode 100644 index 00000000..c4bf69d3 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { + opt := proxytest.NewEmulatorOption(). + WithNewRootContext(newRootContext). + WithNewHttpContext(newHttpContext) + host := proxytest.NewHostEmulator(opt) + defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + + host.StartVM() // call OnVMStart -> the metric is initialized + + contextID := host.HttpFilterInitContext() // create http stream + + hs := [][2]string{ + {"key1", "value1"}, + {"key2", "value2"}, + } + + host.HttpFilterPutRequestHeaders(contextID, hs) // call OnHttpRequestHeaders + + logs := host.GetLogs(types.LogLevelInfo) + require.Greater(t, len(logs), 2) + + assert.Equal(t, "key2: value2", logs[len(logs)-1]) + assert.Equal(t, "key1: value1", logs[len(logs)-2]) + assert.Equal(t, "observing request headers", logs[len(logs)-3]) +} diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod new file mode 100644 index 00000000..4d2560ee --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -0,0 +1,8 @@ +module my.filters.http + +go 1.15 + +require ( + github.com/stretchr/testify v1.6.1 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 +) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum new file mode 100644 index 00000000..fdb00ca2 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go new file mode 100644 index 00000000..d7a6831c --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +var ( + connectionCounterName = "my_network_filter.connection_counter" + counter proxywasm.MetricCounter +) + +func main() { + proxywasm.SetNewRootContext(newRootContext) + proxywasm.SetNewStreamContext(newStreamContext) +} + +type rootContext struct { + // we must embed the default context + proxywasm.DefaultRootContext + contextID uint32 +} + +func newRootContext(rootContextID uint32) proxywasm.RootContext { + return &rootContext{contextID: rootContextID} +} + +func (ctx *rootContext) OnVMStart(vmConfigurationSize int) bool { + counter = proxywasm.DefineCounterMetric(connectionCounterName) + return true +} + +type streamContext struct { + // we must embed the default context + proxywasm.DefaultStreamContext + rootContextID, contextID uint32 +} + +func newStreamContext(rootContextID, contextID uint32) proxywasm.StreamContext { + return &streamContext{contextID: contextID, rootContextID: rootContextID} +} + +func (ctx *streamContext) OnNewConnection() types.Action { + proxywasm.LogInfo("new connection!") + return types.ActionContinue +} + +func (ctx *streamContext) OnStreamDone() { + counter.Increment(1) + proxywasm.LogInfo("connection complete!") +} diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go new file mode 100644 index 00000000..2c0bf975 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -0,0 +1,43 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +func TestNetwork_OnNewConnection(t *testing.T) { + opt := proxytest.NewEmulatorOption(). + WithNewRootContext(newRootContext). + WithNewStreamContext(newStreamContext) + host := proxytest.NewHostEmulator(opt) + defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + + host.NetworkFilterInitConnection() // OnNewConnection is called + + logs := host.GetLogs(types.LogLevelInfo) // retrieve logs emitted to Envoy + assert.Equal(t, logs[0], "new connection!") +} + +func TestNetwork_counter(t *testing.T) { + opt := proxytest.NewEmulatorOption(). + WithNewRootContext(newRootContext). + WithNewStreamContext(newStreamContext) + host := proxytest.NewHostEmulator(opt) + defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + + host.StartVM() // init metric + + contextID := host.NetworkFilterInitConnection() + host.NetworkFilterCompleteConnection(contextID) // call OnDone on contextID -> increment the connection counter + + logs := host.GetLogs(types.LogLevelInfo) + require.Greater(t, len(logs), 0) + + assert.Equal(t, "connection complete!", logs[len(logs)-1]) + actual := counter.Get() + assert.Equal(t, uint64(1), actual) +} diff --git a/go.mod b/go.mod index e32f2b50..eceb4370 100644 --- a/go.mod +++ b/go.mod @@ -5,14 +5,12 @@ go 1.13 require ( bitbucket.org/creachadair/shell v0.0.6 github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect + github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a github.com/docker/distribution v2.7.1+incompatible github.com/envoyproxy/go-control-plane v0.9.5 github.com/ghodss/yaml v1.0.0 - github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a github.com/go-ole/go-ole v1.2.4 // indirect - github.com/gogo/protobuf v1.3.0 github.com/golang/protobuf v1.3.5 - github.com/hashicorp/go-multierror v1.0.0 github.com/manifoldco/promptui v0.0.0-00010101000000-000000000000 github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-shellwords v1.0.10 @@ -27,10 +25,11 @@ require ( github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984 github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 github.com/spf13/cobra v0.0.5 - github.com/stretchr/testify v1.4.0 + github.com/stretchr/testify v1.6.1 github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 github.com/tetratelabs/multierror v1.1.0 + github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0 // indirect gotest.tools v2.2.0+incompatible istio.io/api v0.0.0-20200227213531-891bf31f3c32 istio.io/istio v0.0.0-20200304114959-c3c353285578 diff --git a/go.sum b/go.sum index ce3603df..1aa31b3c 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,7 @@ contrib.go.opencensus.io/exporter/prometheus v0.1.0/go.mod h1:cGFniUXGZlKRjzOyuZ contrib.go.opencensus.io/exporter/stackdriver v0.12.9/go.mod h1:XyyafDnFOsqoxHJgTFycKZMrRUrPThLh2iYTJF6uoO0= contrib.go.opencensus.io/exporter/zipkin v0.1.1/go.mod h1:GMvdSl3eJ2gapOaLKzTKE3qDgUkJ86k9k3yY2eqwkzc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +fortio.org/fortio v1.3.1 h1:XScQoLYEdMmlmPyueDwEZxrMOaoX9V9juSIkxkZf5zM= fortio.org/fortio v1.3.1/go.mod h1:Go0fRqoPJ1xy5JOWcS23jyF58byVZxFyEePYsGmCR0k= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= @@ -33,16 +34,20 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E= +github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/sprig v2.14.1+incompatible h1:rTHERm50Xp1Cbb8x7xBCeDp//jMMqqR44EWw7KwSXUQ= github.com/Masterminds/sprig v2.14.1+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -55,6 +60,7 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -64,6 +70,7 @@ github.com/alicebob/miniredis v0.0.0-20180201100744-9d52b1fc8da9/go.mod h1:8HZjE github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antlr/antlr4 v0.0.0-20190223165740-dade65a895c2 h1:Q1TGw0wvj6lqZQ4/CMfZykGQDnkslNcvuDID+AfNiQE= github.com/antlr/antlr4 v0.0.0-20190223165740-dade65a895c2/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y= +github.com/aokoli/goutils v1.0.1 h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg= github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -72,9 +79,6 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= -github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-sdk-go v1.23.20 h1:2CBuL21P0yKdZN5urf2NxKa1ha8fhnY+A3pBCHFeZoA= @@ -87,14 +91,17 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/cactus/go-statsd-client v3.1.1+incompatible/go.mod h1:cMRcwZDklk7hXp+Law83urTHUiHMzCev/r4JMYr/zU0= +github.com/cenkalti/backoff v2.0.0+incompatible h1:5IIPUHhlnUZbcHQsQou5k1Tn58nJkeJL9U+ig5CHJbY= github.com/cenkalti/backoff v2.0.0+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= +github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.4/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= @@ -104,6 +111,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533 h1:8wZizuKuZVu5COB7EsBYxBQz8nRcXXn5d4Gt91eJLvU= github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/containerd/containerd v1.3.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/coreos/bbolt v1.3.1-coreos.6/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -123,7 +131,9 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= +github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -159,14 +169,12 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/envoyproxy/go-control-plane v0.8.6/go.mod h1:XB9+ce7x+IrsjgIVnRnql0O61gj/np0/bGDfhJI3sCU= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4 h1:rEvIZUSZ3fx39WIi3JkQqQBitGwpELBIYWeBVh6wn+E= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.5 h1:lRJIqDD8yjV1YyPRqecMdytjDLs2fTXq363aCib5xPU= github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s= -github.com/envoyproxy/protoc-gen-validate v0.0.0-20190405222122-d6164de49109/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -177,6 +185,7 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fluent/fluent-logger-golang v1.3.0/go.mod h1:2/HCT/jTy78yGyeNGQLGQsjF3zzzAuy6Xlk6FCMV5eU= +github.com/frankban/quicktest v1.4.1 h1:Wv2VwvNn73pAdFIVUQRXYDFp31lXKbqblIXo/Q5GPSg= github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -195,6 +204,7 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7 github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= github.com/go-logr/zapr v0.1.1/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= +github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= @@ -244,6 +254,7 @@ github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85n github.com/go-redis/redis v6.10.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -253,6 +264,7 @@ github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5 github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -281,6 +293,7 @@ github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAO github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8= github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/cel-go v0.2.0 h1:1xQjGc4NQ0Kk0308Om1gfSt7Tkk4hwgVMGEpEEYwf9g= github.com/google/cel-go v0.2.0/go.mod h1:fTCVOuSN/Vn6d49zvRpr3fDAKFyfpLViE0gU+9Vtm7g= @@ -331,6 +344,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.3.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20171214222146-0e7658f8ee99 h1:bTRV2bQrg85E7ZeeyQfHX3GyfidLrNzVoyq7epx0bTw= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20171214222146-0e7658f8ee99/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hashicorp/consul v1.3.1 h1:bY7/Uo29Uq7+mHce4wgSHtAJSbeRl+4F7M+OHTuEeXI= github.com/hashicorp/consul v1.3.1/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= @@ -344,6 +358,7 @@ github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -352,9 +367,11 @@ github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es github.com/hashicorp/go-rootcerts v1.0.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8= github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc= github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= @@ -367,6 +384,7 @@ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3 h1:EmmoJme1matNzb+hMpDuR/0sbJSUisxyqBGG676r31M= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.5 h1:ZynDUIQiA8usmRgPdGPHFdPnb1wgGI9tK3mO9hcAJjc= github.com/hashicorp/serf v0.8.5/go.mod h1:UpNcs7fFbpKIyZaUuSW6EPiH+eZC7OuyFD+wc1oal+k= @@ -377,11 +395,13 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKe github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY= github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huandu/xstrings v1.2.1 h1:v6IdmkCnDhJG/S0ivr58PeIfg+tyhqQYy4YsCsQ0Pdc= github.com/huandu/xstrings v1.2.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -439,6 +459,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU= github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU= +github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= @@ -448,6 +469,7 @@ github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFW github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -500,16 +522,20 @@ github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/openshift/api v3.9.1-0.20191008181517-e4fd21196097+incompatible h1:CIa+Zv6vIPhJl5OHmKxVpnekHC54YYe49L9GLr7IxGI= github.com/openshift/api v3.9.1-0.20191008181517-e4fd21196097+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY= +github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.1.7/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= +github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= +github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc= github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -574,20 +600,19 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/schollz/progressbar/v2 v2.13.2 h1:3L9bP5KQOGEnFP8P5V8dz+U0yo5I29iY5Oa9s9EAwn0= github.com/schollz/progressbar/v2 v2.13.2/go.mod h1:6YZjqdthH6SCZKv2rqGryrxPtfmRB/DWZxSMfCXPyD8= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984 h1:wsZAb4P8F7uQSwsnxE1gk9AHCcc5U0wvyDzcLwFY0Eo= github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= +github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= -github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= -github.com/signalfx/com_signalfx_metrics_protobuf v0.0.0-20170330202426-93e507b42f43/go.mod h1:muYA2clvwCdj7nzAJ5vJIXYpJsUumhAl4Uu1wUNpWzA= -github.com/signalfx/gohistogram v0.0.0-20160107210732-1ccfd2ff5083/go.mod h1:adPDS6s7WaajdFBV9mQ7i0dKfQ8xiDnF9ZNETVPpp7c= -github.com/signalfx/golib v1.1.6/go.mod h1:nWYefOwlUKWm/SpN/LgVSBnyH1T9NpT1ANlmgRIi1Cs= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -620,18 +645,24 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e h1:P03rR9jXeD2ilkYVsRlDz/EyS2rTg5Nko8T/LzPri5k= github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e/go.mod h1:IrGJ2YZz3+qia1dEU9GFg3QieuMUUwiJf5tjG8uhogg= github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 h1:a7FN/XPymdzttMaO+u4osDaV11WTJtgJGtmPMJfqeM8= github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8/go.mod h1:w+dEBsxcYEFg0I6whrgkMzjD8GBBQgmDq9hykB30pt8= github.com/tetratelabs/multierror v1.1.0 h1:cKmV/Pbf42K5wp8glxa2YIausbxIraPN8fzru9Pn1Cg= github.com/tetratelabs/multierror v1.1.0/go.mod h1:kH3SzI/z+FwEbV9bxQDx4GiIgE2djuyb8wiB2DaUBnY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0 h1:n2foXJoViPNPz5Jr3bHMc8a4WXBuXwQ3bKJYpfXZUPE= +github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= +github.com/uber/jaeger-client-go v0.0.0-20190228190846-ecf2d03a9e80 h1:nWzkj/LnVGFeaeXAAXq7AyH4BQP3678Lqj3y2fIaieg= github.com/uber/jaeger-client-go v0.0.0-20190228190846-ecf2d03a9e80/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.0.0+incompatible h1:iMSCV0rmXEogjNWPh2D0xk9YVKvrtGoHJNe9ebLu/pw= github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= @@ -752,6 +783,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180117170059-2c42eef0765b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -775,7 +807,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -847,6 +878,7 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.2/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -868,7 +900,6 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -883,14 +914,17 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/d4l3k/messagediff.v1 v1.2.1 h1:70AthpjunwzUiarMHyED52mj9UwtAnE89l1Gmrt3EU0= gopkg.in/d4l3k/messagediff.v1 v1.2.1/go.mod h1:EUzikiKadqXWcD1AzJLagx0j/BeeWGtn++04Xniyg44= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= @@ -905,6 +939,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -916,7 +952,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt istio.io/api v0.0.0-20190515205759-982e5c3888c6/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo= istio.io/api v0.0.0-20200227213531-891bf31f3c32 h1:Kbv2woZ1iw8s4JSz/WgcLEUVmBjQDneL/EB3k5jhU+A= istio.io/api v0.0.0-20200227213531-891bf31f3c32/go.mod h1:bcY3prusO/6vA6zGHz4PNG2v79clPyTw06Xx3fprJSQ= -istio.io/gogo-genproto v0.0.0-20190731221249-06e20ada0df2/go.mod h1:IjvrbUlRbbw4JCpsgvgihcz9USUwEoNTL/uwMtyV5yk= istio.io/gogo-genproto v0.0.0-20190930162913-45029607206a/go.mod h1:OzpAts7jljZceG4Vqi5/zXy/pOg1b209T3jb7Nv5wIs= istio.io/gogo-genproto v0.0.0-20200130224810-a0338448499a h1:WQLbIB0tZSOwAILzqBG9/A7rq+wwTA8a1nqfTmQQSU8= istio.io/gogo-genproto v0.0.0-20200130224810-a0338448499a/go.mod h1:OzpAts7jljZceG4Vqi5/zXy/pOg1b209T3jb7Nv5wIs= @@ -947,6 +982,7 @@ k8s.io/component-base v0.0.0-20190918160511-547f6c5d7090/go.mod h1:933PBGtQFJky3 k8s.io/component-base v0.17.2/go.mod h1:zMPW3g5aH7cHJpKYQ/ZsGMcgbsA/VyhEugF3QT1awLs= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20190822140433-26a664648505/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/helm v2.14.3+incompatible h1:uzotTcZXa/b2SWVoUzM1xiCXVjI38TuxMujS/1s+3Gw= k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= @@ -956,6 +992,7 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= +k8s.io/kubectl v0.17.2 h1:QZR8Q6lWiVRjwKslekdbN5WPMp53dS/17j5e+oi5XVU= k8s.io/kubectl v0.17.2/go.mod h1:y4rfLV0n6aPmvbRCqZQjvOp3ezxsFgpqL+zF5jH/lxk= k8s.io/metrics v0.17.2/go.mod h1:3TkNHET4ROd+NfzNxkjoVfQ0Ob4iZnaHmSEA4vYpwLw= k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= diff --git a/images/extension-builders/rust/entrypoint.sh b/images/extension-builders/entrypoint.sh similarity index 100% rename from images/extension-builders/rust/entrypoint.sh rename to images/extension-builders/entrypoint.sh diff --git a/images/extension-builders/rust/Dockerfile b/images/extension-builders/rust/Dockerfile index 52fddf0f..e71d0166 100644 --- a/images/extension-builders/rust/Dockerfile +++ b/images/extension-builders/rust/Dockerfile @@ -24,6 +24,6 @@ RUN rustup target add wasm32-unknown-unknown ENV CARGO_HOME= COPY ./entrypoint.sh /usr/local/getenvoy/extension/builder/entrypoint.sh -COPY ./commands.sh /usr/local/getenvoy/extension/builder/commands.sh +COPY ./rust/commands.sh /usr/local/getenvoy/extension/builder/commands.sh ENTRYPOINT ["/usr/local/getenvoy/extension/builder/entrypoint.sh"] CMD ["--help"] diff --git a/images/extension-builders/tinygo/Dockerfile b/images/extension-builders/tinygo/Dockerfile new file mode 100644 index 00000000..e3af4f9b --- /dev/null +++ b/images/extension-builders/tinygo/Dockerfile @@ -0,0 +1,28 @@ +# Copyright 2020 Tetrate +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Builder image for Envoy Wasm extensions written in Go. +# + +FROM tinygo/tinygo:0.16.0 + +ENV GOCACHE=/source/.gocache +ENV GOMODCACHE=/source/.gomodcache +ENV XDG_CACHE_HOME=/source/.cache + +COPY ./entrypoint.sh /usr/local/getenvoy/extension/builder/entrypoint.sh +COPY ./tinygo/commands.sh /usr/local/getenvoy/extension/builder/commands.sh +ENTRYPOINT ["/usr/local/getenvoy/extension/builder/entrypoint.sh"] +CMD ["--help"] diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh new file mode 100755 index 00000000..ac4eaad2 --- /dev/null +++ b/images/extension-builders/tinygo/commands.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Copyright 2020 Tetrate +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +extension_build() { + exec tinygo build -o "$1" -scheduler=none -target wasi main.go +} + +extension_test() { + exec go test -tags=proxytest -v ./... +} + +extension_clean() { + rm /source/extension.wasm || true + go clean -modcache + rm -rf "${GOCACHE}" "${XDG_CACHE_HOME}" || true +} diff --git a/pkg/cmd/extension/init/cmd.go b/pkg/cmd/extension/init/cmd.go index 2db0c203..e0946332 100644 --- a/pkg/cmd/extension/init/cmd.go +++ b/pkg/cmd/extension/init/cmd.go @@ -35,6 +35,7 @@ var ( // programming languages supported by the `init` command. supportedLanguages = options{ {Value: extension.LanguageRust.String(), DisplayText: "Rust"}, + {Value: extension.LanguageTinyGo.String(), DisplayText: "TinyGo"}, } // Envoy release the extension templates have been developed against. // diff --git a/pkg/extension/workspace/config/extension/helpers.go b/pkg/extension/workspace/config/extension/helpers.go index d31b3e49..64b75a0f 100644 --- a/pkg/extension/workspace/config/extension/helpers.go +++ b/pkg/extension/workspace/config/extension/helpers.go @@ -88,7 +88,7 @@ func (languages languages) Index() map[string]Language { var ( // Languages is a list of valid programming languages. - Languages = languages{LanguageRust} + Languages = languages{LanguageRust, LanguageTinyGo} languageIndex = Languages.Index() ) diff --git a/pkg/extension/workspace/config/extension/types.go b/pkg/extension/workspace/config/extension/types.go index b30c7a3d..88c71ff8 100644 --- a/pkg/extension/workspace/config/extension/types.go +++ b/pkg/extension/workspace/config/extension/types.go @@ -47,8 +47,10 @@ func (l Language) String() string { } const ( - // LanguageRust represens a Rust programming language. + // LanguageRust represents a Rust programming language. LanguageRust Language = "rust" + // LanguageTinyGo represents a TinyGo programming language. + LanguageTinyGo Language = "tinygo" ) // Descriptor represents an extension created by getenvoy toolkit. diff --git a/pkg/extension/workspace/toolchain/builtin/default_config.go b/pkg/extension/workspace/toolchain/builtin/default_config.go index be468385..3e949608 100644 --- a/pkg/extension/workspace/toolchain/builtin/default_config.go +++ b/pkg/extension/workspace/toolchain/builtin/default_config.go @@ -36,7 +36,8 @@ var ( return version.Build.Version }() // defaultRustBuildImage represents a full name of the default Rust builder image in a Docker registry. - defaultRustBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-rust-builder", Tag: defaultBuildImageTag}.String() + defaultRustBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-rust-builder", Tag: defaultBuildImageTag}.String() + defaultTinyGoBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-tinygo-builder", Tag: defaultBuildImageTag}.String() ) // defaultConfigFor returns a default toolchain config for a given extension. @@ -57,6 +58,8 @@ func defaultBuildImageFor(language extensionconfig.Language) string { switch language { case extensionconfig.LanguageRust: return defaultRustBuildImage + case extensionconfig.LanguageTinyGo: + return defaultTinyGoBuildImage default: // must be caught by unit tests panic(errors.Errorf("failed to determine default build image for unsupported programming language %q", language)) @@ -69,6 +72,8 @@ func defaultOutputPathFor(language extensionconfig.Language) string { case extensionconfig.LanguageRust: // keep *.wasm file inside Cargo build dir (to be cleaned up automatically) return "target/getenvoy/extension.wasm" + case extensionconfig.LanguageTinyGo: + return "extension.wasm" default: // must be caught by unit tests panic(errors.Errorf("failed to determine default output path for unsupported programming language %q", language)) diff --git a/pkg/extension/workspace/toolchain/builtin/default_config_test.go b/pkg/extension/workspace/toolchain/builtin/default_config_test.go index aab2f20b..3ce88c65 100644 --- a/pkg/extension/workspace/toolchain/builtin/default_config_test.go +++ b/pkg/extension/workspace/toolchain/builtin/default_config_test.go @@ -18,11 +18,10 @@ import ( "fmt" "io/ioutil" - "github.com/pkg/errors" - . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + "github.com/pkg/errors" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" diff --git a/pkg/extension/workspace/toolchain/builtin/example_config_test.go b/pkg/extension/workspace/toolchain/builtin/example_config_test.go index 93d61eed..c5c9d7d7 100644 --- a/pkg/extension/workspace/toolchain/builtin/example_config_test.go +++ b/pkg/extension/workspace/toolchain/builtin/example_config_test.go @@ -21,12 +21,10 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - - . "github.com/tetratelabs/getenvoy/pkg/extension/workspace/toolchain/builtin" - "github.com/pkg/errors" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" + . "github.com/tetratelabs/getenvoy/pkg/extension/workspace/toolchain/builtin" ) var _ = Describe("ExampleConfig()", func() { diff --git a/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml b/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml new file mode 100644 index 00000000..c5671813 --- /dev/null +++ b/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml @@ -0,0 +1,6 @@ +kind: BuiltinToolchain +container: + image: getenvoy/extension-tinygo-builder:latest +build: + output: + wasmFile: extension.wasm diff --git a/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml b/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml new file mode 100644 index 00000000..d6adf1d5 --- /dev/null +++ b/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml @@ -0,0 +1,56 @@ +# +# Configuration for the built-in toolchain. +# +kind: BuiltinToolchain + +# +# Configuration of the default build container. +# + +## container: +## # Builder image. +## image: getenvoy/extension-tinygo-builder:latest +## # Docker cli options. +## options: [] + +# +# Configuration of the 'build' command. +# +# If omitted, configuration of the default build container will be used instead. +# + +## build: +## container: +## # Builder image. +## image: getenvoy/extension-tinygo-builder:latest +## # Docker cli options. +## options: [] +## output: +## # Output *.wasm file. +## wasmFile: extension.wasm + +# +# Configuration of the 'test' command. +# +# If omitted, configuration of the default build container will be used instead. +# + +## test: +## container: +## # Builder image. +## image: getenvoy/extension-tinygo-builder:latest +## # Docker cli options. +## options: [] + +# +# Configuration of the 'clean' command. +# +# If omitted, configuration of the default build container will be used instead. +# + +## clean: +## container: +## # Builder image. +## image: getenvoy/extension-tinygo-builder:latest +## # Docker cli options. +## options: [] diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index aab68c92..74d629d2 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -58,3 +58,10 @@ var _ = AfterEach(func() { Expect(os.RemoveAll(tempDir)).To(Succeed()) } }) + +func CleanUpExtensionDir(dir string) { + Expect(os.Chdir(dir)).To(Succeed()) + clean := GetEnvoy("extension clean") + _, _, err := clean.Exec() + Expect(err).To(Succeed()) +} diff --git a/test/e2e/getenvoy_extension_build_test.go b/test/e2e/getenvoy_extension_build_test.go index 9719c9c1..ce37daf4 100644 --- a/test/e2e/getenvoy_extension_build_test.go +++ b/test/e2e/getenvoy_extension_build_test.go @@ -46,6 +46,7 @@ var _ = Describe("getenvoy extension build", func() { func(given testCase) { By("choosing the output directory") outputDir := filepath.Join(tempDir, "new") + defer CleanUpExtensionDir(outputDir) By("running `extension init` command") _, _, err := GetEnvoy("extension init"). diff --git a/test/e2e/getenvoy_extension_examples_test.go b/test/e2e/getenvoy_extension_examples_test.go index 41cb8cc2..56b14069 100644 --- a/test/e2e/getenvoy_extension_examples_test.go +++ b/test/e2e/getenvoy_extension_examples_test.go @@ -43,6 +43,7 @@ var _ = Describe("getenvoy extension examples", func() { func(given testCase) { By("choosing the output directory") outputDir := filepath.Join(tempDir, "new") + defer CleanUpExtensionDir(outputDir) By("running `extension init` command") _, _, err := GetEnvoy("extension init"). diff --git a/test/e2e/getenvoy_extension_init_test.go b/test/e2e/getenvoy_extension_init_test.go index c37bfc4d..5ec1f8fa 100644 --- a/test/e2e/getenvoy_extension_init_test.go +++ b/test/e2e/getenvoy_extension_init_test.go @@ -84,6 +84,7 @@ var _ = Describe("getenvoy extension init", func() { func(given testCase) { By("choosing the output directory") outputDir := tempDir + defer CleanUpExtensionDir(outputDir) By("changing to the output directory") err := os.Chdir(outputDir) diff --git a/test/e2e/getenvoy_extension_run_test.go b/test/e2e/getenvoy_extension_run_test.go index ef5c0d33..ba140b6d 100644 --- a/test/e2e/getenvoy_extension_run_test.go +++ b/test/e2e/getenvoy_extension_run_test.go @@ -99,6 +99,7 @@ var _ = Describe("getenvoy extension run", func() { func(given testCase) { By("choosing the output directory") outputDir := filepath.Join(tempDir, "extension") + defer CleanUpExtensionDir(outputDir) By("running `extension init` command") _, _, err := GetEnvoy("extension init"). diff --git a/test/e2e/getenvoy_extension_test_test.go b/test/e2e/getenvoy_extension_test_test.go index 5cc1f2c8..9bdc2ea5 100644 --- a/test/e2e/getenvoy_extension_test_test.go +++ b/test/e2e/getenvoy_extension_test_test.go @@ -43,6 +43,7 @@ var _ = Describe("getenvoy extension test", func() { func(given testCase) { By("choosing the output directory") outputDir := filepath.Join(tempDir, "new") + defer CleanUpExtensionDir(outputDir) By("running `extension init` command") _, _, err := GetEnvoy("extension init"). From 11ee7a8f72b41d991425b4f894ca8757fbb60723 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:40:34 +0900 Subject: [PATCH 02/39] allow abi 0.1.0 Signed-off-by: mathetake --- images/extension-builders/tinygo/commands.sh | 3 ++- pkg/cmd/extension/run/cmd_test.go | 15 ++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index ac4eaad2..550c184c 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,7 +15,8 @@ # limitations under the License. extension_build() { - exec tinygo build -o "$1" -scheduler=none -target wasi main.go + # TODO: remove abi_010 tag after upgrading wasm:nightly or Envoy 1.17 release + exec tinygo build -o "$1" -tags=abi_010 -scheduler=none -target wasi main.go } extension_test() { diff --git a/pkg/cmd/extension/run/cmd_test.go b/pkg/cmd/extension/run/cmd_test.go index 9de8c49d..c504af24 100644 --- a/pkg/cmd/extension/run/cmd_test.go +++ b/pkg/cmd/extension/run/cmd_test.go @@ -23,26 +23,19 @@ import ( "path/filepath" "strings" + "github.com/ghodss/yaml" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - + "github.com/otiai10/copy" "github.com/pkg/errors" - "github.com/spf13/cobra" - "github.com/ghodss/yaml" - - "github.com/otiai10/copy" - "github.com/tetratelabs/getenvoy/pkg/cmd" "github.com/tetratelabs/getenvoy/pkg/manifest" - "github.com/tetratelabs/getenvoy/pkg/types" - testcontext "github.com/tetratelabs/getenvoy/pkg/test/cmd/extension" - - cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd" - manifesttest "github.com/tetratelabs/getenvoy/pkg/test/manifest" + "github.com/tetratelabs/getenvoy/pkg/types" + cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd" ) //nolint:lll From d6f8eba4865a0bb533bb89a51aaca8c5489d5faa Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:51:27 +0900 Subject: [PATCH 03/39] Fix e2e Signed-off-by: mathetake --- .../default/go.mod | 0 .../default/go.sum | 0 .../default/main.go | 0 .../default/main_test.go | 3 ++- test/e2e/util/data.go | 4 ++++ 5 files changed, 6 insertions(+), 1 deletion(-) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/go.mod (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/go.sum (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/main.go (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/main_test.go (85%) diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go similarity index 85% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 560360d6..c1f2e5f7 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -17,7 +17,8 @@ func TestHelloWorld_OnTick(t *testing.T) { host := proxytest.NewHostEmulator(opt) defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation - host.CallOnLogForAccessLogger([][2]string{{":path", "/this/is/path"}}, nil) // call OnLog + path := [2]string{":path", "/this/is/path"} + host.CallOnLogForAccessLogger([][2]string{path}, nil) // call OnLog logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index f0cda09e..2c2689eb 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,6 +16,7 @@ package util import ( "fmt" + "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -37,6 +38,9 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { + if strings.Contains(language.String(), "rust") { + continue + } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From ebb1b11c29e68adf7819835acf5d1d6a718f5498 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:52:20 +0900 Subject: [PATCH 04/39] Fix e2e Signed-off-by: mathetake --- test/e2e/util/data.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index 2c2689eb..f0cda09e 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,7 +16,6 @@ package util import ( "fmt" - "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -38,9 +37,6 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { - if strings.Contains(language.String(), "rust") { - continue - } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From 9dce67963f497c3b73a3c0261172baca41d9c420 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:40:34 +0900 Subject: [PATCH 05/39] allow abi 0.1.0 Signed-off-by: mathetake --- images/extension-builders/tinygo/commands.sh | 3 ++- pkg/cmd/extension/run/cmd_test.go | 15 ++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index ac4eaad2..550c184c 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,7 +15,8 @@ # limitations under the License. extension_build() { - exec tinygo build -o "$1" -scheduler=none -target wasi main.go + # TODO: remove abi_010 tag after upgrading wasm:nightly or Envoy 1.17 release + exec tinygo build -o "$1" -tags=abi_010 -scheduler=none -target wasi main.go } extension_test() { diff --git a/pkg/cmd/extension/run/cmd_test.go b/pkg/cmd/extension/run/cmd_test.go index 9de8c49d..c504af24 100644 --- a/pkg/cmd/extension/run/cmd_test.go +++ b/pkg/cmd/extension/run/cmd_test.go @@ -23,26 +23,19 @@ import ( "path/filepath" "strings" + "github.com/ghodss/yaml" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - + "github.com/otiai10/copy" "github.com/pkg/errors" - "github.com/spf13/cobra" - "github.com/ghodss/yaml" - - "github.com/otiai10/copy" - "github.com/tetratelabs/getenvoy/pkg/cmd" "github.com/tetratelabs/getenvoy/pkg/manifest" - "github.com/tetratelabs/getenvoy/pkg/types" - testcontext "github.com/tetratelabs/getenvoy/pkg/test/cmd/extension" - - cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd" - manifesttest "github.com/tetratelabs/getenvoy/pkg/test/manifest" + "github.com/tetratelabs/getenvoy/pkg/types" + cmdutil "github.com/tetratelabs/getenvoy/pkg/util/cmd" ) //nolint:lll From fbc011bc808285900521c04010a2c35d88247dfe Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:51:27 +0900 Subject: [PATCH 06/39] Fix e2e Signed-off-by: mathetake --- .../default/go.mod | 0 .../default/go.sum | 0 .../default/main.go | 0 .../default/main_test.go | 3 ++- test/e2e/util/data.go | 4 ++++ 5 files changed, 6 insertions(+), 1 deletion(-) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/go.mod (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/go.sum (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/main.go (100%) rename data/extension/init/templates/tinygo/{envoy.filters.access_loggers => envoy.access_loggers}/default/main_test.go (85%) diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.mod rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/go.sum rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go similarity index 100% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main.go rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go diff --git a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go similarity index 85% rename from data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go rename to data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 560360d6..c1f2e5f7 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -17,7 +17,8 @@ func TestHelloWorld_OnTick(t *testing.T) { host := proxytest.NewHostEmulator(opt) defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation - host.CallOnLogForAccessLogger([][2]string{{":path", "/this/is/path"}}, nil) // call OnLog + path := [2]string{":path", "/this/is/path"} + host.CallOnLogForAccessLogger([][2]string{path}, nil) // call OnLog logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index f0cda09e..2c2689eb 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,6 +16,7 @@ package util import ( "fmt" + "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -37,6 +38,9 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { + if strings.Contains(language.String(), "rust") { + continue + } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From f53036f915856e4e7424a7e5b5ef1954327269af Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 13:52:20 +0900 Subject: [PATCH 07/39] Fix e2e Signed-off-by: mathetake --- test/e2e/util/data.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index 2c2689eb..f0cda09e 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,7 +16,6 @@ package util import ( "fmt" - "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -38,9 +37,6 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { - if strings.Contains(language.String(), "rust") { - continue - } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From f4f46d3082339f5a6c8b641dface24a9c799930d Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 18:37:06 +0900 Subject: [PATCH 08/39] fix e2e on mac Signed-off-by: mathetake --- test/e2e/getenvoy_extension_build_test.go | 3 +-- test/e2e/getenvoy_extension_init_test.go | 3 +-- test/e2e/getenvoy_extension_run_test.go | 3 ++- test/e2e/util/data.go | 7 +++++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/e2e/getenvoy_extension_build_test.go b/test/e2e/getenvoy_extension_build_test.go index ce37daf4..f5385789 100644 --- a/test/e2e/getenvoy_extension_build_test.go +++ b/test/e2e/getenvoy_extension_build_test.go @@ -22,10 +22,9 @@ import ( . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - e2e "github.com/tetratelabs/getenvoy/test/e2e/util" - workspaces "github.com/tetratelabs/getenvoy/pkg/extension/workspace" toolchains "github.com/tetratelabs/getenvoy/pkg/extension/workspace/toolchain" + e2e "github.com/tetratelabs/getenvoy/test/e2e/util" ) var _ = Describe("getenvoy extension build", func() { diff --git a/test/e2e/getenvoy_extension_init_test.go b/test/e2e/getenvoy_extension_init_test.go index 5ec1f8fa..0dd4e0f7 100644 --- a/test/e2e/getenvoy_extension_init_test.go +++ b/test/e2e/getenvoy_extension_init_test.go @@ -22,9 +22,8 @@ import ( . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - e2e "github.com/tetratelabs/getenvoy/test/e2e/util" - workspaces "github.com/tetratelabs/getenvoy/pkg/extension/workspace" + e2e "github.com/tetratelabs/getenvoy/test/e2e/util" ) var _ = Describe("getenvoy extension init", func() { diff --git a/test/e2e/getenvoy_extension_run_test.go b/test/e2e/getenvoy_extension_run_test.go index ba140b6d..dc93de46 100644 --- a/test/e2e/getenvoy_extension_run_test.go +++ b/test/e2e/getenvoy_extension_run_test.go @@ -115,7 +115,7 @@ var _ = Describe("getenvoy extension run", func() { Expect(err).NotTo(HaveOccurred()) By("running `extension run` command") - _, stderr, cancel, errs := GetEnvoy("extension run"). + _, stderr, cancel, errs := GetEnvoy("extension run --envoy-options '-l trace'"). Args(e2e.Env.GetBuiltinContainerOptions()...). Start() @@ -136,6 +136,7 @@ var _ = Describe("getenvoy extension run", func() { // fail the test if `getenvoy extension run` exits with an error or unexpectedly go func() { + defer GinkgoRecover() select { case e := <-errs: Expect(e).NotTo(HaveOccurred(), "getenvoy command exited unexpectedly") diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index f0cda09e..12c38ea5 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,6 +16,7 @@ package util import ( "fmt" + "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -36,7 +37,13 @@ func (t CategoryLanguageTuple) String() string { func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { + if !strings.Contains(category.String(), "http") { + continue + } for _, language := range extension.Languages { + if strings.Contains(language.String(), "rust") { + continue + } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From e3c77b010e6f1508a047f19fbe714c0a3e1c5968 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 19:38:06 +0900 Subject: [PATCH 09/39] fix e2e Signed-off-by: mathetake --- .github/workflows/commit.yaml | 21 ----------------- .github/workflows/release.yaml | 6 ----- ci/e2e/linux/run_tests.sh | 22 ------------------ ci/e2e/macos/install_docker.sh | 36 ----------------------------- ci/e2e/macos/run_tests.sh | 42 +--------------------------------- 5 files changed, 1 insertion(+), 126 deletions(-) delete mode 100755 ci/e2e/macos/install_docker.sh diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index a92dad36..296b6f49 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -54,15 +54,6 @@ jobs: run: make builders - name: "Run e2e tests using `getenvoy` and `e2e` binaries built by the upstream job" - env: - # Allow extension templates to have dependecies on private GitHub repositories. - E2E_ALLOW_PRIVATE_DEPENDENCIES: 'yes' - # Key of a GitHub "machine user" that has access to all private repositories needed by e2e tests: - # user: https://github.com/getenvoy-ci - # key fingeprint: MD5:ae:8d:18:6a:1b:44:17:dc:b8:c8:0f:a9:48:44:be:2b - # - # See https://developer.github.com/v3/guides/managing-deploy-keys/#machine-users - E2E_GITHUB_MACHINE_USER_KEY: ${{ secrets.E2E_GITHUB_MACHINE_USER_KEY }} run: ./ci/e2e/linux/run_tests.sh e2e_macos: @@ -80,9 +71,6 @@ jobs: name: bin path: build/bin - - name: "Install 'Docker for Mac' (an older version that can be installed in CI environment)" - run: ./ci/e2e/macos/install_docker.sh - - name: "Build language-specific Docker build images" env: # don't use `DOCKER_BUILDKIT=1`, `--build-arg BUILDKIT_INLINE_CACHE=1` and `--cache-from` @@ -91,13 +79,4 @@ jobs: run: make builders - name: "Run e2e tests using `getenvoy` and `e2e` binaries built by the upstream job" - env: - # Allow extension templates to have dependecies on private GitHub repositories. - E2E_ALLOW_PRIVATE_DEPENDENCIES: 'yes' - # Key of a GitHub "machine user" that has access to all private repositories needed by e2e tests: - # user: https://github.com/getenvoy-ci - # key fingeprint: MD5:ae:8d:18:6a:1b:44:17:dc:b8:c8:0f:a9:48:44:be:2b - # - # See https://developer.github.com/v3/guides/managing-deploy-keys/#machine-users - E2E_GITHUB_MACHINE_USER_KEY: ${{ secrets.E2E_GITHUB_MACHINE_USER_KEY }} run: ./ci/e2e/macos/run_tests.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a2ab953e..e5d4b751 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -123,9 +123,6 @@ jobs: # `getenvoy extension build | test | run` stable - name: "Run e2e tests using released `getenvoy` binary and published extension builder images" - env: - # Forbid extension templates to have dependecies on private GitHub repositories. - E2E_ALLOW_PRIVATE_DEPENDENCIES: 'no' run: ./ci/e2e/linux/run_tests.sh e2e_macos: @@ -169,7 +166,4 @@ jobs: # `getenvoy extension build | test | run` stable - name: "Run e2e tests using released `getenvoy` binary and published extension builder images" - env: - # Forbid extension templates to have dependecies on private GitHub repositories. - E2E_ALLOW_PRIVATE_DEPENDENCIES: 'no' run: ./ci/e2e/macos/run_tests.sh diff --git a/ci/e2e/linux/run_tests.sh b/ci/e2e/linux/run_tests.sh index 61b686cf..9bedc5b0 100755 --- a/ci/e2e/linux/run_tests.sh +++ b/ci/e2e/linux/run_tests.sh @@ -29,28 +29,6 @@ sudo chown -R $(id -u):$(id -g) "${E2E_CACHE_DIR}" # to speed up `getenvoy extension build|test`, re-use a single cache across all extensions created by e2e tests export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -v ${E2E_CACHE_DIR}:/tmp/cache/getenvoy -e CARGO_HOME=/tmp/cache/getenvoy/extension/rust-builder/cargo" -forward_ssh_agent=false -case "${E2E_ALLOW_PRIVATE_DEPENDENCIES}" in - yes | on | true | 1) forward_ssh_agent=true ;; -esac - -if [[ "${forward_ssh_agent}" == "true" ]]; then - # setup SSH key that will be used by build containers to fetch private dependencies - mkdir -p $HOME/.ssh/ - echo "${E2E_GITHUB_MACHINE_USER_KEY}" | base64 -d > $HOME/.ssh/id_rsa_e2e_github_machine_user - chmod 600 $HOME/.ssh/id_rsa_e2e_github_machine_user - - # use a dedicated SSH agent to manage the keys needed by extension build containers - eval $(ssh-agent -s) - # always kill that SSH agent in the end - trap "ssh-agent -k" EXIT - # load a single key of a GitHub "machine user" that has access to all private repositories needed by e2e tests - ssh-add $HOME/.ssh/id_rsa_e2e_github_machine_user - - # forward SSH agent into extension build containers so that to they could fetch source code from private GitHub repositories - export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -v ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK} -e SSH_AUTH_SOCK" -fi - # restore executable bit that get lost by Github Actions during artifact upload/download chmod a+x ${WORKSPACE_DIR}/build/bin/linux/amd64/* diff --git a/ci/e2e/macos/install_docker.sh b/ci/e2e/macos/install_docker.sh deleted file mode 100755 index 037f3c3f..00000000 --- a/ci/e2e/macos/install_docker.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2020 Tetrate -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -# Docker for Mac 2.0.0.3-ce-mac81,31259 (the last version of 'Docker for Mac' that can be installed in CI environment) -E2E_MACOS_DOCKER_CASK_VERSION="${E2E_MACOS_DOCKER_CASK_VERSION:-8ce4e89d10716666743b28c5a46cd54af59a9cc2}" - -# install Docker for Mac -brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/${E2E_MACOS_DOCKER_CASK_VERSION}/Casks/docker.rb - -# follow instructions from: -# https://github.com/microsoft/azure-pipelines-image-generation/issues/738#issuecomment-496211237 -# https://github.com/microsoft/azure-pipelines-image-generation/issues/738#issuecomment-522301481 -sudo /Applications/Docker.app/Contents/MacOS/Docker --quit-after-install --unattended -nohup /Applications/Docker.app/Contents/MacOS/Docker --unattended > /dev/stdout & -while ! docker info 2> /dev/null; do - sleep 5 - echo "Waiting for docker service to be in the running state" -done - -# sanity check -docker run --rm -t busybox date diff --git a/ci/e2e/macos/run_tests.sh b/ci/e2e/macos/run_tests.sh index b2a99f4f..9ef1058d 100755 --- a/ci/e2e/macos/run_tests.sh +++ b/ci/e2e/macos/run_tests.sh @@ -24,53 +24,13 @@ E2E_CACHE_DIR="${E2E_CACHE_DIR:-$HOME/cache/getenvoy}" # make sure the cache directory is first created on behalf of the current user mkdir -p "${E2E_CACHE_DIR}" +# TODO: support multiple language # to speed up `getenvoy extension build|test`, re-use a single cache across all extensions created by e2e tests export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -v ${E2E_CACHE_DIR}:/tmp/cache/getenvoy -e CARGO_HOME=/tmp/cache/getenvoy/extension/rust-builder/cargo" # set HOME directory export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -e HOME=/tmp/getenvoy" -forward_ssh_agent=false -case "${E2E_ALLOW_PRIVATE_DEPENDENCIES}" in - yes | on | true | 1) forward_ssh_agent=true ;; -esac - -if [[ "${forward_ssh_agent}" == "true" ]]; then - # unfortunately, older versions of 'Docker for Mac' (that can be installed in CI environment) - # do not support SSH agent forwarding. - # that is why we have to take care of it manually and work around the limitation that it's not - # possible to mount a Unix socket from a Mac host into a container - - # setup SSH key that will be used by build containers to fetch private dependencies - mkdir -p $HOME/.ssh/ - echo "${E2E_GITHUB_MACHINE_USER_KEY}" | base64 -D > $HOME/.ssh/id_rsa_e2e_github_machine_user - chmod 600 $HOME/.ssh/id_rsa_e2e_github_machine_user - - # create a wrapper script around the original container entrypoint to setup SSH agent inside the container - echo '#!/usr/bin/env bash -set -e -# use an SSH agent to manage the keys (works better than a plain SSH key in case of Cargo) -eval $(ssh-agent -s) -# always kill that SSH agent in the end -trap "ssh-agent -k" EXIT -# load a single key of a GitHub "machine user" that has access to all private repositories needed by e2e tests -ssh-add $HOME/.ssh/id_rsa -# sanity check -ssh-add -l - -# call the original entrypoint -/usr/local/getenvoy/extension/builder/entrypoint.sh "$@" -' > /tmp/entrypoint-wrapper.sh - chmod a+x /tmp/entrypoint-wrapper.sh - - # mount SSH key into extension build containers - export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -v $HOME/.ssh/id_rsa_e2e_github_machine_user:/tmp/getenvoy/.ssh/id_rsa" - # mount the entrypoint wrapper script - export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} -v /tmp/entrypoint-wrapper.sh:/tmp/getenvoy/entrypoint-wrapper.sh" - # substitute entrypoint with a wrapper script - export E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS="${E2E_BUILTIN_TOOLCHAIN_CONTAINER_OPTIONS} --entrypoint /tmp/getenvoy/entrypoint-wrapper.sh" -fi - # restore executable bit that get lost by Github Actions during artifact upload/download chmod a+x ${WORKSPACE_DIR}/build/bin/darwin/amd64/* From 29743bbc9da09260da092e1750175dfa71d9f6d5 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 19:48:17 +0900 Subject: [PATCH 10/39] fix e2e Signed-off-by: mathetake --- .github/workflows/commit.yaml | 3 +++ ci/e2e/macos/install_docker.sh | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 ci/e2e/macos/install_docker.sh diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index 296b6f49..e91109c5 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -71,6 +71,9 @@ jobs: name: bin path: build/bin + - name: "Install 'Docker for Mac' (an older version that can be installed in CI environment)" + run: ./ci/e2e/macos/install_docker.sh + - name: "Build language-specific Docker build images" env: # don't use `DOCKER_BUILDKIT=1`, `--build-arg BUILDKIT_INLINE_CACHE=1` and `--cache-from` diff --git a/ci/e2e/macos/install_docker.sh b/ci/e2e/macos/install_docker.sh new file mode 100644 index 00000000..037f3c3f --- /dev/null +++ b/ci/e2e/macos/install_docker.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Copyright 2020 Tetrate +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +# Docker for Mac 2.0.0.3-ce-mac81,31259 (the last version of 'Docker for Mac' that can be installed in CI environment) +E2E_MACOS_DOCKER_CASK_VERSION="${E2E_MACOS_DOCKER_CASK_VERSION:-8ce4e89d10716666743b28c5a46cd54af59a9cc2}" + +# install Docker for Mac +brew cask install https://raw.githubusercontent.com/Homebrew/homebrew-cask/${E2E_MACOS_DOCKER_CASK_VERSION}/Casks/docker.rb + +# follow instructions from: +# https://github.com/microsoft/azure-pipelines-image-generation/issues/738#issuecomment-496211237 +# https://github.com/microsoft/azure-pipelines-image-generation/issues/738#issuecomment-522301481 +sudo /Applications/Docker.app/Contents/MacOS/Docker --quit-after-install --unattended +nohup /Applications/Docker.app/Contents/MacOS/Docker --unattended > /dev/stdout & +while ! docker info 2> /dev/null; do + sleep 5 + echo "Waiting for docker service to be in the running state" +done + +# sanity check +docker run --rm -t busybox date From 98e0f9e5a051fa82c453a92bcf9612286b2b12a9 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 19:53:55 +0900 Subject: [PATCH 11/39] fix e2e Signed-off-by: mathetake --- ci/e2e/macos/install_docker.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ci/e2e/macos/install_docker.sh diff --git a/ci/e2e/macos/install_docker.sh b/ci/e2e/macos/install_docker.sh old mode 100644 new mode 100755 From e5687069270b14fccb098ecfc2c94b7637045b16 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 22 Dec 2020 20:09:41 +0900 Subject: [PATCH 12/39] Clean up e2e Signed-off-by: mathetake --- test/e2e/util/data.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index 12c38ea5..f0cda09e 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -16,7 +16,6 @@ package util import ( "fmt" - "strings" "github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension" ) @@ -37,13 +36,7 @@ func (t CategoryLanguageTuple) String() string { func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { - if !strings.Contains(category.String(), "http") { - continue - } for _, language := range extension.Languages { - if strings.Contains(language.String(), "rust") { - continue - } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From 54a9e7a31423e2225796df428916b0aaaf01073c Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 14 Jan 2021 09:51:40 +0900 Subject: [PATCH 13/39] Run tinygo with 1.17.0 Signed-off-by: mathetake --- .../tinygo/envoy.access_loggers/default/go.mod | 2 +- .../tinygo/envoy.access_loggers/default/go.sum | 4 ++-- .../tinygo/envoy.filters.http/default/go.mod | 2 +- .../tinygo/envoy.filters.http/default/go.sum | 4 ++-- .../tinygo/envoy.filters.network/default/go.mod | 2 +- .../tinygo/envoy.filters.network/default/go.sum | 9 ++------- images/extension-builders/tinygo/commands.sh | 3 +-- pkg/cmd/extension/init/cmd.go | 13 +++++++++++-- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index 4d2560ee..86154d38 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index fdb00ca2..88ce7e00 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index 4d2560ee..86154d38 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum index fdb00ca2..88ce7e00 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index 4d2560ee..86154d38 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index fdb00ca2..d72d6c52 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -1,13 +1,8 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13 h1:DOKidvWd0WTBvdzTvU6L7wtig+RktRj3S77ObF2YwNQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.13/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 550c184c..ac4eaad2 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,8 +15,7 @@ # limitations under the License. extension_build() { - # TODO: remove abi_010 tag after upgrading wasm:nightly or Envoy 1.17 release - exec tinygo build -o "$1" -tags=abi_010 -scheduler=none -target wasi main.go + exec tinygo build -o "$1" -scheduler=none -target wasi main.go } extension_test() { diff --git a/pkg/cmd/extension/init/cmd.go b/pkg/cmd/extension/init/cmd.go index e0946332..ce926ca6 100644 --- a/pkg/cmd/extension/init/cmd.go +++ b/pkg/cmd/extension/init/cmd.go @@ -55,7 +55,11 @@ var ( // 1. according to command-line options // 2. otherwise, according to the example-specific configuration (.getenvoy/extension/examples//example.yaml) // 3. otherwise, according to extension descriptor (.getenvoy/extension/extension.yaml) - supportedEnvoyVersion = "wasm:1.15" + defaultSupportedEnvoyVersion = "standard:1.17.0" + supportedEnvoyVersions = map[string]string{ + // https://github.com/tetratelabs/envoy-wasm-rust-sdk/issues/65 + extension.LanguageRust.String(): "wasm:1.15", + } ) // NewCmd returns a command that generates the initial set of files @@ -99,7 +103,12 @@ Scaffold a new Envoy extension in a language of your choice.`, return err } descriptor.Name = params.Name.Value - descriptor.Runtime.Envoy.Version = supportedEnvoyVersion + + if ev, ok := supportedEnvoyVersions[params.Language.Value]; ok { + descriptor.Runtime.Envoy.Version = ev + } else { + descriptor.Runtime.Envoy.Version = defaultSupportedEnvoyVersion + } outputDir, err = scaffold.NormalizeOutputPath(params.OutputDir.Value) if err != nil { From 3292cfdceffc263f135421b21891d9d98f6c1aa7 Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 14 Jan 2021 09:55:40 +0900 Subject: [PATCH 14/39] Update tinygo builder Signed-off-by: mathetake --- images/extension-builders/tinygo/commands.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 550c184c..ac4eaad2 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,8 +15,7 @@ # limitations under the License. extension_build() { - # TODO: remove abi_010 tag after upgrading wasm:nightly or Envoy 1.17 release - exec tinygo build -o "$1" -tags=abi_010 -scheduler=none -target wasi main.go + exec tinygo build -o "$1" -scheduler=none -target wasi main.go } extension_test() { From e046f90b7c900c28f6cce2e4ffdd9ba78260d8d5 Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 14 Jan 2021 10:14:41 +0900 Subject: [PATCH 15/39] Fix e2e Signed-off-by: mathetake --- .../templates/tinygo/envoy.filters.network/default/go.sum | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index d72d6c52..88ce7e00 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -1,8 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 25e93d89d00eaec06bc8408759f68cb5d08a6327 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Mon, 8 Mar 2021 11:12:19 +0900 Subject: [PATCH 16/39] Update TinyGo version Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/extension-builders/tinygo/Dockerfile b/images/extension-builders/tinygo/Dockerfile index e3af4f9b..399bef0f 100644 --- a/images/extension-builders/tinygo/Dockerfile +++ b/images/extension-builders/tinygo/Dockerfile @@ -16,7 +16,7 @@ # Builder image for Envoy Wasm extensions written in Go. # -FROM tinygo/tinygo:0.16.0 +FROM tinygo/tinygo:0.17.0 ENV GOCACHE=/source/.gocache ENV GOMODCACHE=/source/.gomodcache From 7afb2c283a6cd1e675fbe9ef0574f6a5fc6fa3b9 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Mon, 8 Mar 2021 12:00:52 +0900 Subject: [PATCH 17/39] Fix e2e Signed-off-by: Takeshi Yoneda --- test/e2e/getenvoy_extension_push_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/getenvoy_extension_push_test.go b/test/e2e/getenvoy_extension_push_test.go index d51ff46e..a39ee30a 100644 --- a/test/e2e/getenvoy_extension_push_test.go +++ b/test/e2e/getenvoy_extension_push_test.go @@ -104,6 +104,7 @@ var _ = Describe("getenvoy extension push", func() { func(given testCase) { By("choosing the output directory") outputDir := filepath.Join(tempDir, "new") + defer CleanUpExtensionDir(outputDir) By("running `extension init` command") _, _, err := GetEnvoy("extension init"). From d5e430ce689da1aafc5e76e15e1a453a9f8e50ee Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 09:31:26 +0900 Subject: [PATCH 18/39] review: fix styles Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/main_test.go | 10 +++++----- .../tinygo/envoy.filters.http/default/main_test.go | 7 +++---- .../tinygo/envoy.filters.network/default/main_test.go | 7 +++---- go.mod | 2 +- go.sum | 4 ++++ images/extension-builders/tinygo/commands.sh | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index c1f2e5f7..01bf6042 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -1,28 +1,28 @@ package main import ( - "strings" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -func TestHelloWorld_OnTick(t *testing.T) { +type headers = [][2]string + +func TestHelloWorld_OnLog(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newAccessLogger) host := proxytest.NewHostEmulator(opt) defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation path := [2]string{":path", "/this/is/path"} - host.CallOnLogForAccessLogger([][2]string{path}, nil) // call OnLog + host.CallOnLogForAccessLogger(headers{path}, nil) // call OnLog logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) msg := logs[len(logs)-1] - assert.True(t, strings.Contains(msg, "/this/is/path")) + require.Contains(t, msg, "/this/is/path") } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index c4bf69d3..b6868a67 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -3,7 +3,6 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" @@ -31,7 +30,7 @@ func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 2) - assert.Equal(t, "key2: value2", logs[len(logs)-1]) - assert.Equal(t, "key1: value1", logs[len(logs)-2]) - assert.Equal(t, "observing request headers", logs[len(logs)-3]) + require.Equal(t, "key2: value2", logs[len(logs)-1]) + require.Equal(t, "key1: value1", logs[len(logs)-2]) + require.Equal(t, "observing request headers", logs[len(logs)-3]) } diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 2c0bf975..47340a49 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -3,7 +3,6 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tetratelabs/proxy-wasm-go-sdk/proxytest" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" @@ -19,7 +18,7 @@ func TestNetwork_OnNewConnection(t *testing.T) { host.NetworkFilterInitConnection() // OnNewConnection is called logs := host.GetLogs(types.LogLevelInfo) // retrieve logs emitted to Envoy - assert.Equal(t, logs[0], "new connection!") + require.Equal(t, logs[0], "new connection!") } func TestNetwork_counter(t *testing.T) { @@ -37,7 +36,7 @@ func TestNetwork_counter(t *testing.T) { logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) - assert.Equal(t, "connection complete!", logs[len(logs)-1]) + require.Equal(t, "connection complete!", logs[len(logs)-1]) actual := counter.Get() - assert.Equal(t, uint64(1), actual) + require.Equal(t, uint64(1), actual) } diff --git a/go.mod b/go.mod index 275f7f40..68d733a2 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984 github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 github.com/spf13/cobra v0.0.5 - github.com/stretchr/testify v1.4.0 + github.com/stretchr/testify v1.6.1 github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 github.com/tetratelabs/multierror v1.1.0 diff --git a/go.sum b/go.sum index 02d16d08..d205728d 100644 --- a/go.sum +++ b/go.sum @@ -749,6 +749,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e h1:P03rR9jXeD2ilkYVsRlDz/EyS2rTg5Nko8T/LzPri5k= github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e/go.mod h1:IrGJ2YZz3+qia1dEU9GFg3QieuMUUwiJf5tjG8uhogg= @@ -1068,6 +1070,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index ac4eaad2..e9eb2c16 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,7 +15,7 @@ # limitations under the License. extension_build() { - exec tinygo build -o "$1" -scheduler=none -target wasi main.go + tinygo build -o "$1" -scheduler=none -target wasi main.go } extension_test() { From 20e83c048e451a4e344e0bfda845b28ef6cd8aec Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 09:33:32 +0900 Subject: [PATCH 19/39] review: fix styles part 2 Signed-off-by: Takeshi Yoneda --- .../templates/tinygo/envoy.filters.http/default/main_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index b6868a67..ddb8d737 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -9,6 +9,8 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) +type headers = [][2]string + func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext). @@ -20,7 +22,7 @@ func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { contextID := host.HttpFilterInitContext() // create http stream - hs := [][2]string{ + hs := headers{ {"key1", "value1"}, {"key2", "value2"}, } From 93b40f69e66a7939bc42f29fbd79a8e29e24e7e0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 18:14:12 +0900 Subject: [PATCH 20/39] improve access logger example: reading config Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/go.mod | 2 +- .../tinygo/envoy.access_loggers/default/go.sum | 2 ++ .../envoy.access_loggers/default/main.go | 18 ++++++++++++++++-- go.mod | 1 + go.sum | 2 ++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index 86154d38..0304f790 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index 88ce7e00..05023519 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -7,6 +7,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index e3f2af62..7f588320 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) func main() { @@ -11,6 +12,7 @@ func main() { type accessLogger struct { // you must embed the default context proxywasm.DefaultRootContext + logMessage string } func newAccessLogger(contextID uint32) proxywasm.RootContext { @@ -18,12 +20,24 @@ func newAccessLogger(contextID uint32) proxywasm.RootContext { } // override -func (ctx *accessLogger) OnLog() { +func (l *accessLogger) OnPluginStart(configurationSize int) bool { + // Read plugin configuration provided in Envoy configuration + data, err := proxywasm.GetPluginConfiguration(configurationSize) + if err != nil && err != types.ErrorStatusNotFound { + proxywasm.LogCriticalf("failed to load config: %v", err) + return false + } + l.logMessage = string(data) + return true +} + +// override +func (l *accessLogger) OnLog() { hdr, err := proxywasm.GetHttpRequestHeader(":path") if err != nil { proxywasm.LogCritical(err.Error()) return } - proxywasm.LogInfof("OnLog: :path = %s", hdr) + proxywasm.LogInfof("OnLog: :path = %s && message = %s", hdr, l.logMessage) } diff --git a/go.mod b/go.mod index 68d733a2..56b75386 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 github.com/tetratelabs/multierror v1.1.0 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 // indirect gotest.tools v2.2.0+incompatible istio.io/api v0.0.0-20200227213531-891bf31f3c32 istio.io/istio v0.0.0-20200304114959-c3c353285578 diff --git a/go.sum b/go.sum index d205728d..033ea551 100644 --- a/go.sum +++ b/go.sum @@ -758,6 +758,8 @@ github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 h1:a7FN/XPymdzttMa github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8/go.mod h1:w+dEBsxcYEFg0I6whrgkMzjD8GBBQgmDq9hykB30pt8= github.com/tetratelabs/multierror v1.1.0 h1:cKmV/Pbf42K5wp8glxa2YIausbxIraPN8fzru9Pn1Cg= github.com/tetratelabs/multierror v1.1.0/go.mod h1:kH3SzI/z+FwEbV9bxQDx4GiIgE2djuyb8wiB2DaUBnY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= From f250078b71591ed411288c0ff785f3b49add6f24 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 18:57:15 +0900 Subject: [PATCH 21/39] improve http example: reading config Signed-off-by: Takeshi Yoneda --- .../envoy.access_loggers/default/go.sum | 2 - .../envoy.access_loggers/default/main_test.go | 7 ++-- .../tinygo/envoy.filters.http/default/go.mod | 2 +- .../tinygo/envoy.filters.http/default/go.sum | 2 + .../tinygo/envoy.filters.http/default/main.go | 41 ++++++++++++++----- .../envoy.filters.http/default/main_test.go | 27 ++++++------ 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index 05023519..083f79ce 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -5,8 +5,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 01bf6042..1db01de4 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -9,16 +9,15 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -type headers = [][2]string - func TestHelloWorld_OnLog(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newAccessLogger) host := proxytest.NewHostEmulator(opt) defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation - path := [2]string{":path", "/this/is/path"} - host.CallOnLogForAccessLogger(headers{path}, nil) // call OnLog + host.CallOnLogForAccessLogger(types.Headers{ + {":path", "/this/is/path"}, + }, nil) // call OnLog logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index 86154d38..0304f790 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum index 88ce7e00..05023519 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -7,6 +7,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index a1f22028..838041e4 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -1,6 +1,10 @@ package main import ( + "bufio" + "bytes" + "strings" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) @@ -12,32 +16,46 @@ var ( func main() { proxywasm.SetNewRootContext(newRootContext) - proxywasm.SetNewHttpContext(newHttpContext) } type rootContext struct { // we must embed the default context proxywasm.DefaultRootContext - contextID uint32 + contextID uint32 + additionalHeaders map[string]string } func newRootContext(rootContextID uint32) proxywasm.RootContext { - return &rootContext{contextID: rootContextID} + return &rootContext{contextID: rootContextID, additionalHeaders: map[string]string{"additional": "header"}} } -func (ctx *rootContext) OnVMStart(vmConfigurationSize int) bool { +func (ctx *rootContext) OnPluginStart(configurationSize int) bool { counter = proxywasm.DefineCounterMetric(requestCounterName) + + // Read plugin configuration provided in Envoy configuration + data, err := proxywasm.GetPluginConfiguration(configurationSize) + if err != nil && err != types.ErrorStatusNotFound { + proxywasm.LogCriticalf("failed to load config: %v", err) + return false + } + + // each line in the configuration is in `KEY=VALUE` format + scanner := bufio.NewScanner(bytes.NewReader(data)) + for scanner.Scan() { + tokens := strings.Split(scanner.Text(), "=") + ctx.additionalHeaders[tokens[0]] = tokens[1] + } return true } type httpContext struct { // you must embed the default context proxywasm.DefaultHttpContext - rootContextID, contextID uint32 + additionalHeaders map[string]string } -func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext { - return &httpContext{contextID: contextID, rootContextID: rootContextID} +func (ctx *rootContext) NewHttpContext(uint32) proxywasm.HttpContext { + return &httpContext{additionalHeaders: ctx.additionalHeaders} } func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { @@ -56,9 +74,12 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t } func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { - if err := proxywasm.SetHttpResponseHeader("additional", "header"); err != nil { - proxywasm.LogCriticalf("failed to add header: %v", err) - return types.ActionPause + for key, value := range ctx.additionalHeaders { + if err := proxywasm.SetHttpResponseHeader(key, value); err != nil { + proxywasm.LogCriticalf("failed to add header: %v", err) + return types.ActionPause + } + proxywasm.LogInfof("header set: %s %s", key, value) } return types.ActionContinue } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index ddb8d737..ca0d7878 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -9,30 +9,33 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -type headers = [][2]string - func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { + configuration := `HELLO=WORLD +ENVOY=ISTIO` + opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext). - WithNewHttpContext(newHttpContext) + WithPluginConfiguration([]byte(configuration)) host := proxytest.NewHostEmulator(opt) defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation - host.StartVM() // call OnVMStart -> the metric is initialized + host.StartPlugin() // call OnPluginStart -> the metric is initialized - contextID := host.HttpFilterInitContext() // create http stream + contextID := host.InitializeHttpContext() // create http stream - hs := headers{ + hs := types.Headers{ {"key1", "value1"}, {"key2", "value2"}, } - host.HttpFilterPutRequestHeaders(contextID, hs) // call OnHttpRequestHeaders + host.CallOnRequestHeaders(contextID, hs, false) // call OnHttpRequestHeaders + host.CallOnResponseHeaders(contextID, nil, false) // call OnHttpRequestHeaders logs := host.GetLogs(types.LogLevelInfo) - require.Greater(t, len(logs), 2) - - require.Equal(t, "key2: value2", logs[len(logs)-1]) - require.Equal(t, "key1: value1", logs[len(logs)-2]) - require.Equal(t, "observing request headers", logs[len(logs)-3]) + require.Greater(t, len(logs), 1) + require.Equal(t, "additional header: ENVOY=ISTIO", logs[len(logs)-1]) + require.Equal(t, "additional header: HELLO=WORLD", logs[len(logs)-2]) + require.Equal(t, "key2: value2", logs[len(logs)-3]) + require.Equal(t, "key1: value1", logs[len(logs)-4]) + require.Equal(t, "observing request headers", logs[len(logs)-5]) } From 482909dfc6b94ead2fe3b84d5c50ce14224cfad0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 19:13:23 +0900 Subject: [PATCH 22/39] improve network example: reading config Signed-off-by: Takeshi Yoneda --- .../envoy.access_loggers/default/main_test.go | 7 +++- .../tinygo/envoy.filters.http/default/main.go | 2 +- .../envoy.filters.http/default/main_test.go | 16 ++++---- .../envoy.filters.network/default/go.mod | 2 +- .../envoy.filters.network/default/go.sum | 2 + .../envoy.filters.network/default/main.go | 26 +++++++++---- .../default/main_test.go | 37 +++++++++++++------ 7 files changed, 61 insertions(+), 31 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 1db01de4..fff7e942 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -13,12 +13,15 @@ func TestHelloWorld_OnLog(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newAccessLogger) host := proxytest.NewHostEmulator(opt) - defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + // Release the host emulation lock so that other test cases can insert their own host emulation. + defer host.Done() + // Call OnLog with the given headers. host.CallOnLogForAccessLogger(types.Headers{ {":path", "/this/is/path"}, - }, nil) // call OnLog + }, nil) + // Check the Envoy logs. logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) msg := logs[len(logs)-1] diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index 838041e4..aa5c73ea 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -39,7 +39,7 @@ func (ctx *rootContext) OnPluginStart(configurationSize int) bool { return false } - // each line in the configuration is in `KEY=VALUE` format + // Each line in the configuration is in the "KEY=VALUE" format scanner := bufio.NewScanner(bytes.NewReader(data)) for scanner.Scan() { tokens := strings.Split(scanner.Text(), "=") diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index ca0d7878..5eb4059f 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -12,25 +12,27 @@ import ( func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { configuration := `HELLO=WORLD ENVOY=ISTIO` - opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext). WithPluginConfiguration([]byte(configuration)) host := proxytest.NewHostEmulator(opt) - defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + // Release the host emulation lock so that other test cases can insert their own host emulation. + defer host.Done() - host.StartPlugin() // call OnPluginStart -> the metric is initialized + // Call OnPluginStart -> the metric is initialized. + host.StartPlugin() - contextID := host.InitializeHttpContext() // create http stream + // Create http context. + contextID := host.InitializeHttpContext() + // Call OnHttpHeaders with the given headers hs := types.Headers{ {"key1", "value1"}, {"key2", "value2"}, } + host.CallOnRequestHeaders(contextID, hs, false) // call OnHttpRequestHeaders - host.CallOnRequestHeaders(contextID, hs, false) // call OnHttpRequestHeaders - host.CallOnResponseHeaders(contextID, nil, false) // call OnHttpRequestHeaders - + // Check Envoy logs. logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 1) require.Equal(t, "additional header: ENVOY=ISTIO", logs[len(logs)-1]) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index 86154d38..0304f790 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index 88ce7e00..05023519 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -7,6 +7,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go index d7a6831c..863a4926 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go @@ -12,40 +12,50 @@ var ( func main() { proxywasm.SetNewRootContext(newRootContext) - proxywasm.SetNewStreamContext(newStreamContext) } type rootContext struct { // we must embed the default context proxywasm.DefaultRootContext - contextID uint32 + config string } func newRootContext(rootContextID uint32) proxywasm.RootContext { - return &rootContext{contextID: rootContextID} + return &rootContext{} } -func (ctx *rootContext) OnVMStart(vmConfigurationSize int) bool { +func (ctx *rootContext) OnPluginStart(configurationSize int) bool { counter = proxywasm.DefineCounterMetric(connectionCounterName) + + data, err := proxywasm.GetPluginConfiguration(configurationSize) + if err != nil && err != types.ErrorStatusNotFound { + proxywasm.LogCriticalf("failed to load config: %v", err) + return false + } + ctx.config = string(data) return true } +func (ctx *rootContext) NewStreamContext(contextID uint32) proxywasm.StreamContext { + return &streamContext{newConnectionMessage: ctx.config} +} + type streamContext struct { // we must embed the default context proxywasm.DefaultStreamContext - rootContextID, contextID uint32 + newConnectionMessage string } func newStreamContext(rootContextID, contextID uint32) proxywasm.StreamContext { - return &streamContext{contextID: contextID, rootContextID: rootContextID} + return &streamContext{} } func (ctx *streamContext) OnNewConnection() types.Action { - proxywasm.LogInfo("new connection!") + proxywasm.LogInfo(ctx.newConnectionMessage) return types.ActionContinue } func (ctx *streamContext) OnStreamDone() { counter.Increment(1) - proxywasm.LogInfo("connection complete!") + proxywasm.LogInfof("connection complete!") } diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 47340a49..f3726c5c 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -9,29 +9,42 @@ import ( ) func TestNetwork_OnNewConnection(t *testing.T) { + configuration := `message: this is new connection!` + opt := proxytest.NewEmulatorOption(). - WithNewRootContext(newRootContext). - WithNewStreamContext(newStreamContext) + WithPluginConfiguration([]byte(configuration)). + WithNewRootContext(newRootContext) + host := proxytest.NewHostEmulator(opt) - defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + // Release the host emulation lock so that other test cases can insert their own host emulation. + defer host.Done() + + // Initialize the plugin and read the config. + host.StartPlugin() - host.NetworkFilterInitConnection() // OnNewConnection is called + // OnNewConnection is called. + host.InitializeConnection() - logs := host.GetLogs(types.LogLevelInfo) // retrieve logs emitted to Envoy - require.Equal(t, logs[0], "new connection!") + // retrieve logs emitted to Envoy. + logs := host.GetLogs(types.LogLevelInfo) + require.Equal(t, logs[0], configuration) } func TestNetwork_counter(t *testing.T) { opt := proxytest.NewEmulatorOption(). - WithNewRootContext(newRootContext). - WithNewStreamContext(newStreamContext) + WithNewRootContext(newRootContext) host := proxytest.NewHostEmulator(opt) - defer host.Done() // release the host emulation lock so that other test cases can insert their own host emulation + // Release the host emulation lock so that other test cases can insert their own host emulation. + defer host.Done() + + // Initialize the plugin and metric. + host.StartPlugin() - host.StartVM() // init metric + // Establish the connection. + contextID := host.InitializeConnection() - contextID := host.NetworkFilterInitConnection() - host.NetworkFilterCompleteConnection(contextID) // call OnDone on contextID -> increment the connection counter + // Call OnDone on contextID -> increment the connection counter. + host.CompleteConnection(contextID) logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) From 2f146fd691ea1e060155d38f32035ed9096c4b2d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 19:25:19 +0900 Subject: [PATCH 23/39] Fix unittests Signed-off-by: Takeshi Yoneda --- .../envoy.access_loggers/default/main.go | 4 +++- .../envoy.access_loggers/default/main_test.go | 5 +---- .../tinygo/envoy.filters.http/default/main.go | 2 +- .../envoy.filters.http/default/main_test.go | 19 +++++++++++-------- .../default/main_test.go | 8 +++++--- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index 7f588320..6d3c4c6c 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -39,5 +39,7 @@ func (l *accessLogger) OnLog() { return } - proxywasm.LogInfof("OnLog: :path = %s && message = %s", hdr, l.logMessage) + proxywasm.LogInfof("OnLog: :path = %s", hdr) + proxywasm.LogInfof("message = %s", l.logMessage) + } diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index fff7e942..a57a25c9 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -23,8 +23,5 @@ func TestHelloWorld_OnLog(t *testing.T) { // Check the Envoy logs. logs := host.GetLogs(types.LogLevelInfo) - require.Greater(t, len(logs), 0) - msg := logs[len(logs)-1] - - require.Contains(t, msg, "/this/is/path") + require.Contains(t, logs, "OnLog: :path = /this/is/path") } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index aa5c73ea..42721f78 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -79,7 +79,7 @@ func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) proxywasm.LogCriticalf("failed to add header: %v", err) return types.ActionPause } - proxywasm.LogInfof("header set: %s %s", key, value) + proxywasm.LogInfof("header set: %s=%s", key, value) } return types.ActionContinue } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index 5eb4059f..eef9f318 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -25,19 +25,22 @@ ENVOY=ISTIO` // Create http context. contextID := host.InitializeHttpContext() - // Call OnHttpHeaders with the given headers + // Call OnHttpRequestHeaders with the given headers. hs := types.Headers{ {"key1", "value1"}, {"key2", "value2"}, } - host.CallOnRequestHeaders(contextID, hs, false) // call OnHttpRequestHeaders + host.CallOnRequestHeaders(contextID, hs, false) + + // Call OnHttpResponseHeaders. + host.CallOnResponseHeaders(contextID, nil, false) // Check Envoy logs. logs := host.GetLogs(types.LogLevelInfo) - require.Greater(t, len(logs), 1) - require.Equal(t, "additional header: ENVOY=ISTIO", logs[len(logs)-1]) - require.Equal(t, "additional header: HELLO=WORLD", logs[len(logs)-2]) - require.Equal(t, "key2: value2", logs[len(logs)-3]) - require.Equal(t, "key1: value1", logs[len(logs)-4]) - require.Equal(t, "observing request headers", logs[len(logs)-5]) + require.Contains(t, logs, "header set: ENVOY=ISTIO") + require.Contains(t, logs, "header set: HELLO=WORLD") + require.Contains(t, logs, "header set: additional=header") + require.Contains(t, logs, "key2: value2") + require.Contains(t, logs, "key1: value1") + require.Contains(t, logs, "observing request headers") } diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index f3726c5c..254050f2 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -25,9 +25,9 @@ func TestNetwork_OnNewConnection(t *testing.T) { // OnNewConnection is called. host.InitializeConnection() - // retrieve logs emitted to Envoy. + // Retrieve logs emitted to Envoy. logs := host.GetLogs(types.LogLevelInfo) - require.Equal(t, logs[0], configuration) + require.Contains(t, logs, configuration) } func TestNetwork_counter(t *testing.T) { @@ -46,10 +46,12 @@ func TestNetwork_counter(t *testing.T) { // Call OnDone on contextID -> increment the connection counter. host.CompleteConnection(contextID) + // Check Envoy logs. logs := host.GetLogs(types.LogLevelInfo) require.Greater(t, len(logs), 0) + require.Contains(t, logs, "connection complete!") - require.Equal(t, "connection complete!", logs[len(logs)-1]) + // Check counter. actual := counter.Get() require.Equal(t, uint64(1), actual) } From 6f2e72c238ae52e100bc8fb375f89480f679a220 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 19:31:50 +0900 Subject: [PATCH 24/39] Improve comments and namings Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/main.go | 6 +++--- .../envoy.access_loggers/default/main_test.go | 2 +- .../tinygo/envoy.filters.http/default/main.go | 15 ++++++++++----- .../envoy.filters.http/default/main_test.go | 2 +- .../tinygo/envoy.filters.network/default/main.go | 12 ++++++------ .../envoy.filters.network/default/main_test.go | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index 6d3c4c6c..2b935a4a 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -10,7 +10,7 @@ func main() { } type accessLogger struct { - // you must embed the default context + // You must embed the default context. proxywasm.DefaultRootContext logMessage string } @@ -19,7 +19,7 @@ func newAccessLogger(contextID uint32) proxywasm.RootContext { return &accessLogger{} } -// override +// Override proxywasm.DefaultRootContext func (l *accessLogger) OnPluginStart(configurationSize int) bool { // Read plugin configuration provided in Envoy configuration data, err := proxywasm.GetPluginConfiguration(configurationSize) @@ -31,7 +31,7 @@ func (l *accessLogger) OnPluginStart(configurationSize int) bool { return true } -// override +// Override proxywasm.DefaultRootContext func (l *accessLogger) OnLog() { hdr, err := proxywasm.GetHttpRequestHeader(":path") if err != nil { diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index a57a25c9..0804ebeb 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -func TestHelloWorld_OnLog(t *testing.T) { +func TestAccessLogger_OnLog(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newAccessLogger) host := proxytest.NewHostEmulator(opt) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index 42721f78..49c09121 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -29,6 +29,7 @@ func newRootContext(rootContextID uint32) proxywasm.RootContext { return &rootContext{contextID: rootContextID, additionalHeaders: map[string]string{"additional": "header"}} } +// Override proxywasm.DefaultRootContext func (ctx *rootContext) OnPluginStart(configurationSize int) bool { counter = proxywasm.DefineCounterMetric(requestCounterName) @@ -48,16 +49,18 @@ func (ctx *rootContext) OnPluginStart(configurationSize int) bool { return true } +// Override proxywasm.DefaultRootContext +func (ctx *rootContext) NewHttpContext(uint32) proxywasm.HttpContext { + return &httpContext{additionalHeaders: ctx.additionalHeaders} +} + type httpContext struct { - // you must embed the default context + // You must embed the default context. proxywasm.DefaultHttpContext additionalHeaders map[string]string } -func (ctx *rootContext) NewHttpContext(uint32) proxywasm.HttpContext { - return &httpContext{additionalHeaders: ctx.additionalHeaders} -} - +// Override proxywasm.DefaultHttpContext func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { hs, err := proxywasm.GetHttpRequestHeaders() if err != nil { @@ -73,6 +76,7 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t return types.ActionContinue } +// Override proxywasm.DefaultHttpContext func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { for key, value := range ctx.additionalHeaders { if err := proxywasm.SetHttpResponseHeader(key, value); err != nil { @@ -84,6 +88,7 @@ func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) return types.ActionContinue } +// Override proxywasm.DefaultHttpContext func (ctx *httpContext) OnHttpStreamDone() { counter.Increment(1) } diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index eef9f318..62442808 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -func TestHttpHeaders_OnHttpRequestHeaders(t *testing.T) { +func TestHttpFilter_OnHttpRequestHeaders(t *testing.T) { configuration := `HELLO=WORLD ENVOY=ISTIO` opt := proxytest.NewEmulatorOption(). diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go index 863a4926..09db78c4 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go @@ -15,7 +15,7 @@ func main() { } type rootContext struct { - // we must embed the default context + // You must embed the default context. proxywasm.DefaultRootContext config string } @@ -24,6 +24,7 @@ func newRootContext(rootContextID uint32) proxywasm.RootContext { return &rootContext{} } +// Override proxywasm.DefaultRootContext func (ctx *rootContext) OnPluginStart(configurationSize int) bool { counter = proxywasm.DefineCounterMetric(connectionCounterName) @@ -36,25 +37,24 @@ func (ctx *rootContext) OnPluginStart(configurationSize int) bool { return true } +// Override proxywasm.DefaultRootContext func (ctx *rootContext) NewStreamContext(contextID uint32) proxywasm.StreamContext { return &streamContext{newConnectionMessage: ctx.config} } type streamContext struct { - // we must embed the default context + // You must embed the default context. proxywasm.DefaultStreamContext newConnectionMessage string } -func newStreamContext(rootContextID, contextID uint32) proxywasm.StreamContext { - return &streamContext{} -} - +// Override proxywasm.DefaultStreamContext func (ctx *streamContext) OnNewConnection() types.Action { proxywasm.LogInfo(ctx.newConnectionMessage) return types.ActionContinue } +// Override proxywasm.DefaultStreamContext func (ctx *streamContext) OnStreamDone() { counter.Increment(1) proxywasm.LogInfof("connection complete!") diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 254050f2..0c3c090e 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -8,7 +8,7 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -func TestNetwork_OnNewConnection(t *testing.T) { +func TestNetworkFilter_OnNewConnection(t *testing.T) { configuration := `message: this is new connection!` opt := proxytest.NewEmulatorOption(). @@ -30,7 +30,7 @@ func TestNetwork_OnNewConnection(t *testing.T) { require.Contains(t, logs, configuration) } -func TestNetwork_counter(t *testing.T) { +func TestNetworkFilter_counter(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext) host := proxytest.NewHostEmulator(opt) From 2a300e9b74717098b102fe95f309a8f95a917430 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 19:40:42 +0900 Subject: [PATCH 25/39] Remove left 'exec' Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/commands.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index e9eb2c16..8aed815c 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -19,7 +19,7 @@ extension_build() { } extension_test() { - exec go test -tags=proxytest -v ./... + go test -tags=proxytest -v ./... } extension_clean() { From b1b223d7e35a56663d1d3b93519361c35b39cf4c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 9 Mar 2021 23:01:18 +0900 Subject: [PATCH 26/39] Remove unnecessary rm in clean command Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/commands.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 8aed815c..68588d27 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -23,7 +23,6 @@ extension_test() { } extension_clean() { - rm /source/extension.wasm || true go clean -modcache rm -rf "${GOCACHE}" "${XDG_CACHE_HOME}" || true } From bbb29b3da734fc17b462da83d0f638d3f396b153 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 10 Mar 2021 13:46:23 +0900 Subject: [PATCH 27/39] Reivew: use enumed OnPluginStart, host.GetCounterMetric Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/go.mod | 2 +- .../tinygo/envoy.access_loggers/default/go.sum | 13 ------------- .../envoy.access_loggers/default/main.go | 11 ++++++----- .../tinygo/envoy.filters.http/default/go.mod | 2 +- .../tinygo/envoy.filters.http/default/go.sum | 15 --------------- .../tinygo/envoy.filters.http/default/main.go | 18 +++++++++++------- .../envoy.filters.http/default/main_test.go | 1 + .../envoy.filters.network/default/go.mod | 2 +- .../envoy.filters.network/default/go.sum | 15 --------------- .../envoy.filters.network/default/main.go | 12 +++++++----- .../envoy.filters.network/default/main_test.go | 7 ++++--- go.mod | 1 - go.sum | 2 -- 13 files changed, 32 insertions(+), 69 deletions(-) delete mode 100644 data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum delete mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum delete mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index 0304f790..b9db23dd 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum deleted file mode 100644 index 083f79ce..00000000 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ /dev/null @@ -1,13 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index 2b935a4a..09374c32 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -10,7 +10,8 @@ func main() { } type accessLogger struct { - // You must embed the default context. + // You'd better embed the default root context + // so that you don't need to reimplement all the methods by yourself. proxywasm.DefaultRootContext logMessage string } @@ -20,15 +21,15 @@ func newAccessLogger(contextID uint32) proxywasm.RootContext { } // Override proxywasm.DefaultRootContext -func (l *accessLogger) OnPluginStart(configurationSize int) bool { - // Read plugin configuration provided in Envoy configuration +func (l *accessLogger) OnPluginStart(configurationSize int) types.OnPluginStartStatus { + // Read plugin configuration provided in Envoy configuration. data, err := proxywasm.GetPluginConfiguration(configurationSize) if err != nil && err != types.ErrorStatusNotFound { proxywasm.LogCriticalf("failed to load config: %v", err) - return false + return types.OnPluginStartStatusFailed } l.logMessage = string(data) - return true + return types.OnPluginStartStatusOK } // Override proxywasm.DefaultRootContext diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index 0304f790..b9db23dd 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum deleted file mode 100644 index 05023519..00000000 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go index 49c09121..18f4dc3a 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main.go @@ -19,7 +19,8 @@ func main() { } type rootContext struct { - // we must embed the default context + // You'd better embed the default root context + // so that you don't need to reimplement all the methods by yourself. proxywasm.DefaultRootContext contextID uint32 additionalHeaders map[string]string @@ -30,23 +31,24 @@ func newRootContext(rootContextID uint32) proxywasm.RootContext { } // Override proxywasm.DefaultRootContext -func (ctx *rootContext) OnPluginStart(configurationSize int) bool { +func (ctx *rootContext) OnPluginStart(configurationSize int) types.OnPluginStartStatus { + // Initialize the counter. counter = proxywasm.DefineCounterMetric(requestCounterName) - // Read plugin configuration provided in Envoy configuration + // Read plugin configuration provided in Envoy configuration. data, err := proxywasm.GetPluginConfiguration(configurationSize) if err != nil && err != types.ErrorStatusNotFound { proxywasm.LogCriticalf("failed to load config: %v", err) - return false + return types.OnPluginStartStatusFailed } - // Each line in the configuration is in the "KEY=VALUE" format + // Each line in the configuration is in the "KEY=VALUE" format. scanner := bufio.NewScanner(bytes.NewReader(data)) for scanner.Scan() { tokens := strings.Split(scanner.Text(), "=") ctx.additionalHeaders[tokens[0]] = tokens[1] } - return true + return types.OnPluginStartStatusOK } // Override proxywasm.DefaultRootContext @@ -55,7 +57,8 @@ func (ctx *rootContext) NewHttpContext(uint32) proxywasm.HttpContext { } type httpContext struct { - // You must embed the default context. + // You'd better embed the default http context + // so that you don't need to reimplement all the methods by yourself. proxywasm.DefaultHttpContext additionalHeaders map[string]string } @@ -78,6 +81,7 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t // Override proxywasm.DefaultHttpContext func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { + // Set additional headers in the response. for key, value := range ctx.additionalHeaders { if err := proxywasm.SetHttpResponseHeader(key, value); err != nil { proxywasm.LogCriticalf("failed to add header: %v", err) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index 62442808..5490c5ab 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -15,6 +15,7 @@ ENVOY=ISTIO` opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext). WithPluginConfiguration([]byte(configuration)) + host := proxytest.NewHostEmulator(opt) // Release the host emulation lock so that other test cases can insert their own host emulation. defer host.Done() diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index 0304f790..b9db23dd 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum deleted file mode 100644 index 05023519..00000000 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14 h1:13uKVfbtQJGshUqrGN7ujlJZwKYCS8N46NvBwKu5VvU= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.14/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go index 09db78c4..2d41b560 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main.go @@ -15,7 +15,8 @@ func main() { } type rootContext struct { - // You must embed the default context. + // You'd better embed the default root context + // so that you don't need to reimplement all the methods by yourself. proxywasm.DefaultRootContext config string } @@ -25,16 +26,16 @@ func newRootContext(rootContextID uint32) proxywasm.RootContext { } // Override proxywasm.DefaultRootContext -func (ctx *rootContext) OnPluginStart(configurationSize int) bool { +func (ctx *rootContext) OnPluginStart(configurationSize int) types.OnPluginStartStatus { counter = proxywasm.DefineCounterMetric(connectionCounterName) data, err := proxywasm.GetPluginConfiguration(configurationSize) if err != nil && err != types.ErrorStatusNotFound { proxywasm.LogCriticalf("failed to load config: %v", err) - return false + return types.OnPluginStartStatusFailed } ctx.config = string(data) - return true + return types.OnPluginStartStatusOK } // Override proxywasm.DefaultRootContext @@ -43,7 +44,8 @@ func (ctx *rootContext) NewStreamContext(contextID uint32) proxywasm.StreamConte } type streamContext struct { - // You must embed the default context. + // You'd better embed the default stream context + // so that you don't need to reimplement all the methods by yourself. proxywasm.DefaultStreamContext newConnectionMessage string } diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 0c3c090e..fa5d1880 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -10,7 +10,6 @@ import ( func TestNetworkFilter_OnNewConnection(t *testing.T) { configuration := `message: this is new connection!` - opt := proxytest.NewEmulatorOption(). WithPluginConfiguration([]byte(configuration)). WithNewRootContext(newRootContext) @@ -33,6 +32,7 @@ func TestNetworkFilter_OnNewConnection(t *testing.T) { func TestNetworkFilter_counter(t *testing.T) { opt := proxytest.NewEmulatorOption(). WithNewRootContext(newRootContext) + host := proxytest.NewHostEmulator(opt) // Release the host emulation lock so that other test cases can insert their own host emulation. defer host.Done() @@ -52,6 +52,7 @@ func TestNetworkFilter_counter(t *testing.T) { require.Contains(t, logs, "connection complete!") // Check counter. - actual := counter.Get() - require.Equal(t, uint64(1), actual) + value, err := host.GetCounterMetric(connectionCounterName) + require.NoError(t, err) + require.Equal(t, uint64(1), value) } diff --git a/go.mod b/go.mod index 56b75386..68d733a2 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,6 @@ require ( github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 github.com/tetratelabs/multierror v1.1.0 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 // indirect gotest.tools v2.2.0+incompatible istio.io/api v0.0.0-20200227213531-891bf31f3c32 istio.io/istio v0.0.0-20200304114959-c3c353285578 diff --git a/go.sum b/go.sum index 033ea551..d205728d 100644 --- a/go.sum +++ b/go.sum @@ -758,8 +758,6 @@ github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 h1:a7FN/XPymdzttMa github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8/go.mod h1:w+dEBsxcYEFg0I6whrgkMzjD8GBBQgmDq9hykB30pt8= github.com/tetratelabs/multierror v1.1.0 h1:cKmV/Pbf42K5wp8glxa2YIausbxIraPN8fzru9Pn1Cg= github.com/tetratelabs/multierror v1.1.0/go.mod h1:kH3SzI/z+FwEbV9bxQDx4GiIgE2djuyb8wiB2DaUBnY= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15 h1:GDMoxdhqcksWXW7ynM2gtTmrWYHC+Op/SqFVL4Trglg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.15/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= From f75cff74120e92ecb16d9f0d2ccd1fe4874524de Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 10 Mar 2021 13:53:21 +0900 Subject: [PATCH 28/39] Add go mod download Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/Dockerfile | 6 +++--- images/extension-builders/tinygo/commands.sh | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/images/extension-builders/tinygo/Dockerfile b/images/extension-builders/tinygo/Dockerfile index 399bef0f..c9c7611e 100644 --- a/images/extension-builders/tinygo/Dockerfile +++ b/images/extension-builders/tinygo/Dockerfile @@ -18,9 +18,9 @@ FROM tinygo/tinygo:0.17.0 -ENV GOCACHE=/source/.gocache -ENV GOMODCACHE=/source/.gomodcache -ENV XDG_CACHE_HOME=/source/.cache +ENV GOCACHE=/source/build/.gocache +ENV GOMODCACHE=/source/build/.gomodcache +ENV XDG_CACHE_HOME=/source/build/.cache COPY ./entrypoint.sh /usr/local/getenvoy/extension/builder/entrypoint.sh COPY ./tinygo/commands.sh /usr/local/getenvoy/extension/builder/commands.sh diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 68588d27..7a593d37 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,6 +15,7 @@ # limitations under the License. extension_build() { + go mod download tinygo build -o "$1" -scheduler=none -target wasi main.go } From f9603799592a6915806e4e65c1043b9b3afbebba Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 10 Mar 2021 16:08:11 +0900 Subject: [PATCH 29/39] Re: fix entrypoint Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/commands.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 7a593d37..68588d27 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -15,7 +15,6 @@ # limitations under the License. extension_build() { - go mod download tinygo build -o "$1" -scheduler=none -target wasi main.go } From 23e8fbc28d0e9cd0fef19322cb25859d463f5ef8 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 10 Mar 2021 16:53:28 +0900 Subject: [PATCH 30/39] Revert: add go.sum Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/go.sum | 13 +++++++++++++ .../tinygo/envoy.filters.http/default/go.sum | 13 +++++++++++++ .../tinygo/envoy.filters.network/default/go.sum | 13 +++++++++++++ test/e2e/util/data.go | 3 +++ 4 files changed, 42 insertions(+) create mode 100644 data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum new file mode 100644 index 00000000..29218c4f --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum new file mode 100644 index 00000000..29218c4f --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum new file mode 100644 index 00000000..29218c4f --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +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 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index f0cda09e..d42e41c3 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -37,6 +37,9 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { + if language != "tinygo" { + continue + } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From 7443281b1d466216ec1c43a73697df12fb32e400 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 10 Mar 2021 16:55:38 +0900 Subject: [PATCH 31/39] Revert debug code Signed-off-by: Takeshi Yoneda --- test/e2e/util/data.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/e2e/util/data.go b/test/e2e/util/data.go index d42e41c3..f0cda09e 100644 --- a/test/e2e/util/data.go +++ b/test/e2e/util/data.go @@ -37,9 +37,6 @@ func GetCategoryLanguageCombinations() []CategoryLanguageTuple { tuples := make([]CategoryLanguageTuple, 0) for _, category := range extension.Categories { for _, language := range extension.Languages { - if language != "tinygo" { - continue - } tuples = append(tuples, CategoryLanguageTuple{category, language}) } } From 45a02f3d8be384ae359161c39478e4d2c7f6de15 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 10:14:25 +0900 Subject: [PATCH 32/39] Add .gitignore, and set extension name in go.mod Signed-off-by: Takeshi Yoneda --- .../templates/tinygo/envoy.access_loggers/default/.gitignore | 1 + .../init/templates/tinygo/envoy.access_loggers/default/go.mod | 2 +- .../init/templates/tinygo/envoy.filters.http/default/.gitignore | 1 + .../init/templates/tinygo/envoy.filters.http/default/go.mod | 2 +- .../templates/tinygo/envoy.filters.network/default/.gitignore | 1 + .../init/templates/tinygo/envoy.filters.network/default/go.mod | 2 +- 6 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 data/extension/init/templates/tinygo/envoy.access_loggers/default/.gitignore create mode 100644 data/extension/init/templates/tinygo/envoy.filters.http/default/.gitignore create mode 100644 data/extension/init/templates/tinygo/envoy.filters.network/default/.gitignore diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/.gitignore b/data/extension/init/templates/tinygo/envoy.access_loggers/default/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index b9db23dd..2fe89072 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -1,4 +1,4 @@ -module my.filters.http +module {{ .Extension.Name }} go 1.15 diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/.gitignore b/data/extension/init/templates/tinygo/envoy.filters.http/default/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index b9db23dd..2fe89072 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -1,4 +1,4 @@ -module my.filters.http +module {{ .Extension.Name }} go 1.15 diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/.gitignore b/data/extension/init/templates/tinygo/envoy.filters.network/default/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index b9db23dd..2fe89072 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -1,4 +1,4 @@ -module my.filters.http +module {{ .Extension.Name }} go 1.15 From b9024b03272fdc0154bc100bbf84b6978afb8b1c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 10:17:09 +0900 Subject: [PATCH 33/39] default output to build/extension.wasm Signed-off-by: Takeshi Yoneda --- .../templates/tinygo/envoy.filters.network/default/main_test.go | 2 +- pkg/extension/workspace/toolchain/builtin/default_config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index fa5d1880..2513ce7c 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -52,7 +52,7 @@ func TestNetworkFilter_counter(t *testing.T) { require.Contains(t, logs, "connection complete!") // Check counter. - value, err := host.GetCounterMetric(connectionCounterName) + value, err := host.GetCounterMetric("my_network_filter.connection_counter") require.NoError(t, err) require.Equal(t, uint64(1), value) } diff --git a/pkg/extension/workspace/toolchain/builtin/default_config.go b/pkg/extension/workspace/toolchain/builtin/default_config.go index 3e949608..65a67ffd 100644 --- a/pkg/extension/workspace/toolchain/builtin/default_config.go +++ b/pkg/extension/workspace/toolchain/builtin/default_config.go @@ -73,7 +73,7 @@ func defaultOutputPathFor(language extensionconfig.Language) string { // keep *.wasm file inside Cargo build dir (to be cleaned up automatically) return "target/getenvoy/extension.wasm" case extensionconfig.LanguageTinyGo: - return "extension.wasm" + return "build/extension.wasm" default: // must be caught by unit tests panic(errors.Errorf("failed to determine default output path for unsupported programming language %q", language)) From 436d5079305ab99f16991c70c67d761911e80ebe Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 13:45:17 +0900 Subject: [PATCH 34/39] Update SDK: fix error Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/go.mod | 2 +- .../tinygo/envoy.access_loggers/default/go.sum | 4 ++-- .../tinygo/envoy.filters.http/default/go.mod | 2 +- .../tinygo/envoy.filters.http/default/go.sum | 4 ++-- .../tinygo/envoy.filters.http/default/main_test.go | 12 +++++++++--- .../tinygo/envoy.filters.network/default/go.mod | 2 +- .../tinygo/envoy.filters.network/default/go.sum | 4 ++-- .../envoy.filters.network/default/main_test.go | 8 ++++++-- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index 2fe89072..ac3c1780 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index 29218c4f..c8b8a159 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index 2fe89072..ac3c1780 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum index 29218c4f..c8b8a159 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index 5490c5ab..61319c52 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -21,7 +21,9 @@ ENVOY=ISTIO` defer host.Done() // Call OnPluginStart -> the metric is initialized. - host.StartPlugin() + status := host.StartPlugin() + // Check the status returned by OnNewConnection is ActionContinue. + require.Equal(t, types.OnPluginStartStatusOK, status) // Create http context. contextID := host.InitializeHttpContext() @@ -31,10 +33,14 @@ ENVOY=ISTIO` {"key1", "value1"}, {"key2", "value2"}, } - host.CallOnRequestHeaders(contextID, hs, false) + action := host.CallOnRequestHeaders(contextID, hs, false) + // Check the action returned by OnRequestHeaders is Continue. + require.Equal(t, types.ActionContinue, action) // Call OnHttpResponseHeaders. - host.CallOnResponseHeaders(contextID, nil, false) + action = host.CallOnResponseHeaders(contextID, nil, false) + // Check the action returned by OnResponseHeaders is Continue. + require.Equal(t, types.ActionContinue, action) // Check Envoy logs. logs := host.GetLogs(types.LogLevelInfo) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index 2fe89072..ac3c1780 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 + github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index 29218c4f..c8b8a159 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8 h1:Epa+Lnq1Erqpsv8T9gQBUaIxIhn9iG2Orrqv/UuwrnQ= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210310041209-1980230c2fb8/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= +github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 2513ce7c..67ec8e4e 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -19,7 +19,9 @@ func TestNetworkFilter_OnNewConnection(t *testing.T) { defer host.Done() // Initialize the plugin and read the config. - host.StartPlugin() + status := host.StartPlugin() + // Check the status returned by OnPluginStart is OK. + require.Equal(t, types.OnPluginStartStatusOK, status) // OnNewConnection is called. host.InitializeConnection() @@ -41,7 +43,9 @@ func TestNetworkFilter_counter(t *testing.T) { host.StartPlugin() // Establish the connection. - contextID := host.InitializeConnection() + contextID, action := host.InitializeConnection() + // Check the status returned by OnNewConnection is ActionContinue. + require.Equal(t, types.ActionContinue, action) // Call OnDone on contextID -> increment the connection counter. host.CompleteConnection(contextID) From b485f0571a8d6060ad883d193cd221a491ea59bc Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 14:11:59 +0900 Subject: [PATCH 35/39] Fix permission on host Signed-off-by: Takeshi Yoneda --- images/extension-builders/tinygo/commands.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 68588d27..18abd33b 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -16,13 +16,18 @@ extension_build() { tinygo build -o "$1" -scheduler=none -target wasi main.go + # This is necessary since the created go caches are with read-only permission, + # and without this, the host user cannot delete the build directory with "rm -rf". + chmod -R a+rw build/ } extension_test() { go test -tags=proxytest -v ./... + # This is necessary since the created go caches are with read-only permission, + # and without this, the host user cannot delete the build directory with "rm -rf". + chmod -R a+rw build/ } extension_clean() { - go clean -modcache - rm -rf "${GOCACHE}" "${XDG_CACHE_HOME}" || true + rm -rf build } From 5ce9aa6c67240860d4e02ff1060ee6e6bc5d9675 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 14:24:21 +0900 Subject: [PATCH 36/39] Fix unittest Signed-off-by: Takeshi Yoneda --- .../builtin/testdata/default_config/tinygo.toolchain.yaml | 2 +- .../builtin/testdata/example_config/tinygo.toolchain.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml b/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml index c5671813..6e991355 100644 --- a/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml +++ b/pkg/extension/workspace/toolchain/builtin/testdata/default_config/tinygo.toolchain.yaml @@ -3,4 +3,4 @@ container: image: getenvoy/extension-tinygo-builder:latest build: output: - wasmFile: extension.wasm + wasmFile: build/extension.wasm diff --git a/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml b/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml index d6adf1d5..d9f49164 100644 --- a/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml +++ b/pkg/extension/workspace/toolchain/builtin/testdata/example_config/tinygo.toolchain.yaml @@ -27,7 +27,7 @@ kind: BuiltinToolchain ## options: [] ## output: ## # Output *.wasm file. -## wasmFile: extension.wasm +## wasmFile: build/extension.wasm # # Configuration of the 'test' command. From b3c33e11f55dbfa4e04a4c893b13f669670b4e45 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 12 Mar 2021 14:28:19 +0900 Subject: [PATCH 37/39] Fix comment Signed-off-by: Takeshi Yoneda --- .../templates/tinygo/envoy.filters.http/default/main_test.go | 2 +- .../tinygo/envoy.filters.network/default/main_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go index 61319c52..0e0efff2 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/main_test.go @@ -22,7 +22,7 @@ ENVOY=ISTIO` // Call OnPluginStart -> the metric is initialized. status := host.StartPlugin() - // Check the status returned by OnNewConnection is ActionContinue. + // Check the status returned by OnPluginStart is OK. require.Equal(t, types.OnPluginStartStatusOK, status) // Create http context. diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go index 67ec8e4e..06a95431 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/main_test.go @@ -40,7 +40,9 @@ func TestNetworkFilter_counter(t *testing.T) { defer host.Done() // Initialize the plugin and metric. - host.StartPlugin() + status := host.StartPlugin() + // Check the status returned by OnPluginStart is OK. + require.Equal(t, types.OnPluginStartStatusOK, status) // Establish the connection. contextID, action := host.InitializeConnection() From 52b79441f959cd834736a7989cabd6f93aee90e0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Mon, 15 Mar 2021 10:01:58 +0900 Subject: [PATCH 38/39] Fix permission, showcase config in access logger Signed-off-by: Takeshi Yoneda --- .../tinygo/envoy.access_loggers/default/main.go | 2 +- .../envoy.access_loggers/default/main_test.go | 13 +++++++++++-- images/extension-builders/tinygo/commands.sh | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go index 09374c32..f00b6f5d 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main.go @@ -40,7 +40,7 @@ func (l *accessLogger) OnLog() { return } - proxywasm.LogInfof("OnLog: :path = %s", hdr) + proxywasm.LogInfof(":path = %s", hdr) proxywasm.LogInfof("message = %s", l.logMessage) } diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go index 0804ebeb..71928db6 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/main_test.go @@ -10,12 +10,20 @@ import ( ) func TestAccessLogger_OnLog(t *testing.T) { + configuration := `this is my log message` opt := proxytest.NewEmulatorOption(). - WithNewRootContext(newAccessLogger) + WithNewRootContext(newAccessLogger). + WithPluginConfiguration([]byte(configuration)) + host := proxytest.NewHostEmulator(opt) // Release the host emulation lock so that other test cases can insert their own host emulation. defer host.Done() + // Call OnPluginStart -> the message field of root context is configured. + status := host.StartPlugin() + // Check the status returned by OnPluginStart is OK. + require.Equal(t, types.OnPluginStartStatusOK, status) + // Call OnLog with the given headers. host.CallOnLogForAccessLogger(types.Headers{ {":path", "/this/is/path"}, @@ -23,5 +31,6 @@ func TestAccessLogger_OnLog(t *testing.T) { // Check the Envoy logs. logs := host.GetLogs(types.LogLevelInfo) - require.Contains(t, logs, "OnLog: :path = /this/is/path") + require.Contains(t, logs, ":path = /this/is/path") + require.Contains(t, logs, "message = this is my log message") } diff --git a/images/extension-builders/tinygo/commands.sh b/images/extension-builders/tinygo/commands.sh index 18abd33b..f38e1273 100755 --- a/images/extension-builders/tinygo/commands.sh +++ b/images/extension-builders/tinygo/commands.sh @@ -18,14 +18,14 @@ extension_build() { tinygo build -o "$1" -scheduler=none -target wasi main.go # This is necessary since the created go caches are with read-only permission, # and without this, the host user cannot delete the build directory with "rm -rf". - chmod -R a+rw build/ + chmod -R u+rw "${GOMODCACHE}" } extension_test() { go test -tags=proxytest -v ./... # This is necessary since the created go caches are with read-only permission, # and without this, the host user cannot delete the build directory with "rm -rf". - chmod -R a+rw build/ + chmod -R u+rw "${GOMODCACHE}" } extension_clean() { From 9715e55761fef2916ba99e505e9fdde62eb54da1 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Mon, 15 Mar 2021 10:44:20 +0900 Subject: [PATCH 39/39] Update SDK Signed-off-by: Takeshi Yoneda --- .../init/templates/tinygo/envoy.access_loggers/default/go.mod | 2 +- .../init/templates/tinygo/envoy.access_loggers/default/go.sum | 4 ++-- .../init/templates/tinygo/envoy.filters.http/default/go.mod | 2 +- .../init/templates/tinygo/envoy.filters.http/default/go.sum | 4 ++-- .../templates/tinygo/envoy.filters.network/default/go.mod | 2 +- .../templates/tinygo/envoy.filters.network/default/go.sum | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod index ac3c1780..02297849 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 ) diff --git a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum index c8b8a159..4a33c4c1 100644 --- a/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.access_loggers/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod index ac3c1780..02297849 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum index c8b8a159..4a33c4c1 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.http/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod index ac3c1780..02297849 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.mod @@ -4,5 +4,5 @@ go 1.15 require ( github.com/stretchr/testify v1.6.1 - github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 + github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 ) diff --git a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum index c8b8a159..4a33c4c1 100644 --- a/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum +++ b/data/extension/init/templates/tinygo/envoy.filters.network/default/go.sum @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757 h1:97z8twAIBLEll7HkPHVaMCLs/+OyzCJyazAFTCiHKhA= -github.com/tetratelabs/proxy-wasm-go-sdk v0.0.16-0.20210312030126-362d11ef7757/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0 h1:9CUaOB8CZInfG/VRCjOEOkzS4JLkri/weqogwmrl2a0= +github.com/tetratelabs/proxy-wasm-go-sdk v0.1.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=