Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Add higress e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga committed Oct 26, 2023
1 parent f18af31 commit c1e26cb
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 8 deletions.
42 changes: 42 additions & 0 deletions e2e/higress-gc-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:
chown:
image: alpine:3.16
command:
- /bin/sh
- -c
# Early creates the log file so wasm-logs does not fail even if envoy is not yet healthy
- touch /home/envoy/logs/envoy.log && chown -R 101:101 /home/envoy/logs
volumes:
- logs:/home/envoy/logs:rw
envoy:
depends_on:
- chown
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.28-latest}
command:
- -c
- /conf/envoy-config.yaml
- --log-level
- info
- --log-format [%Y-%m-%d %T.%f][%t][%l][%n] [%g:%#] %v
- --log-path
- /home/envoy/logs/envoy.log
volumes:
- ./build:/build
- .:/conf
- logs:/home/envoy/logs:rw
ports:
- 8080:8080
- 8082:8082
envoy-logs:
depends_on:
- envoy
image: debian:11-slim
entrypoint: bash
command:
- -c
- tail -c +0 -f /home/envoy/logs/envoy.log > /build/envoy.log
volumes:
- logs:/home/envoy/logs:ro
- ./build:/build
volumes:
logs:
58 changes: 58 additions & 0 deletions e2e/higress-gc-test/envoy-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
node:
cluster: test-cluster
id: test-idn

admin:
address:
socket_address: { address: 0.0.0.0, port_value: 8082 }

static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 8080 }
per_connection_buffer_limit_bytes: 1024000000
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
access_log:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
http_filters:
- name: gctest
typed_config:
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
value:
config:
name: basic_auth
vm_config:
runtime: envoy.wasm.runtime.v8
code:
local:
filename: /build/plugin.wasm
allow_precompiled: true
fail_open: true
configuration:
"@type": type.googleapis.com/google.protobuf.StringValue
value: '10485760'
- name: envoy.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains:
- "*"
routes:
- match:
prefix: /
direct_response:
status: 200
body:
inline_string: "hello world"
7 changes: 7 additions & 0 deletions e2e/higress-gc-test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module higress-gc-test

go 1.20

require github.com/tetratelabs/proxy-wasm-go-sdk v0.19.1-0.20220822060051-f9d179a57f8c

require github.com/stretchr/testify v1.8.0 // indirect
72 changes: 72 additions & 0 deletions e2e/higress-gc-test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright wasilibs authors
// SPDX-License-Identifier: MIT

package main

import (
"bytes"
"fmt"
"runtime"
"strconv"

"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"

_ "github.com/wasilibs/nottinygc"
)

func main() {
proxywasm.SetVMContext(&vm{})
}

type vm struct {
types.DefaultVMContext
}

func (v *vm) NewPluginContext(contextID uint32) types.PluginContext {
return &plugin{}
}

type plugin struct {
// Embed the default plugin context here,
// so that we don't need to reimplement all the methods.
types.DefaultPluginContext

size int
}

// OnPluginStart Override types.DefaultPluginContext.
func (h *plugin) OnPluginStart(_ int) types.OnPluginStartStatus {
data, err := proxywasm.GetPluginConfiguration()
if err != nil {
panic(err)
}
sz, err := strconv.Atoi(string(bytes.TrimSpace(data)))
if err != nil {
panic(err)
}
h.size = sz
return types.OnPluginStartStatusOK
}

// NewHttpContext Override types.DefaultPluginContext to allow us to declare a request handler for each
// intercepted request the Envoy Sidecar sends us
func (h *plugin) NewHttpContext(_ uint32) types.HttpContext {
return &tester{size: h.size}
}

type tester struct {
types.DefaultHttpContext
size int
}

func (c *tester) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
b := make([]byte, c.size)
var m runtime.MemStats
runtime.ReadMemStats(&m)
proxywasm.LogInfof("alloc success, point address: %p", b)
memstats := fmt.Sprintf(`{"Sys": %d,"HeapSys": %d,"HeapIdle": %d,"HeapInuse": %d,"HeapReleased": %d}`, m.Sys, m.HeapSys, m.HeapIdle, m.HeapInuse, m.HeapReleased)
proxywasm.LogInfo(memstats)
proxywasm.SendHttpResponse(200, [][2]string{{"Content-Type", "application/json"}}, []byte(memstats), -1)
return types.ActionContinue
}
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ use (
.
./bench
./e2e/envoy-dispatch-call
./e2e/higress-gc-test
)
52 changes: 44 additions & 8 deletions magefiles/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
)

func E2eCoraza() error {
if err := os.MkdirAll(filepath.Join("build", "logs"), 0o755); err != nil {
return err
}

if _, err := os.Stat(filepath.Join("e2e", "coraza-proxy-wasm")); os.IsNotExist(err) {
// Try not pinning version, there should be no compatibility issues causing unexpected failures from a
// green coraza build so we get to keep forward coverage this way.
Expand Down Expand Up @@ -66,10 +62,6 @@ func E2eCoraza() error {
}

func E2eEnvoyDispatchCall() error {
if err := os.MkdirAll(filepath.Join("build", "logs"), 0o755); err != nil {
return err
}

if err := os.MkdirAll(filepath.Join("e2e", "envoy-dispatch-call", "build"), 0o755); err != nil {
return err
}
Expand Down Expand Up @@ -120,6 +112,44 @@ func E2eEnvoyDispatchCall() error {
return nil
}

func E2eHigressGCTest() error {
if err := os.MkdirAll(filepath.Join("e2e", "higress-gc-test", "build"), 0o755); err != nil {
return err
}
defer func() {
for _, f := range []string{"envoy.log"} {
content, err := os.ReadFile(filepath.Join("build", f))
if err != nil {
panic(err)
}
if err := os.WriteFile(filepath.Join("..", "..", "build", "logs", f), content, 0o644); err != nil {
panic(err)
}
}
}()

if err := sh.RunV("tinygo", "build", "-target=wasi", "-gc=custom", "-tags='custommalloc nottinygc_envoy'", "-scheduler=none",
"-o", filepath.Join("e2e", "higress-gc-test", "build", "plugin.wasm"), "./e2e/higress-gc-test"); err != nil {
return err
}

if err := sh.RunV("docker-compose", "--file", filepath.Join("e2e", "higress-gc-test", "docker-compose.yml"), "up", "-d"); err != nil {
return err
}
defer func() {
if err := sh.RunV("docker-compose", "--file", filepath.Join("e2e", "higress-gc-test", "docker-compose.yml"), "down", "-v"); err != nil {
panic(err)
}
}()

_, err := e2eLoad("http://localhost:8080/hello", "http://localhost:8082/stats")
if err != nil {
return err
}

return nil
}

type counterStat struct {
Name string `json:"name"`
Value int `json:"value"`
Expand Down Expand Up @@ -193,3 +223,9 @@ func e2eLoad(url string, statsURL string) (*counterStats, error) {

return &stats, nil
}

func init() {
if err := os.MkdirAll(filepath.Join("build", "logs"), 0o755); err != nil {
panic(err)
}
}

0 comments on commit c1e26cb

Please sign in to comment.