Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix ci pipeline to test all envoy versions #124

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
envoy:
depends_on:
- httpbin
image: envoyproxy/envoy:v1.23-latest
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.23-latest}
command:
- -c
- /conf/envoy-config.yaml
Expand Down
5 changes: 3 additions & 2 deletions e2e/e2e-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
ENVOY_HOST=${ENVOY_HOST:-"localhost:8080"}
HTTPBIN_HOST=${HTTPBIN_HOST:-"localhost:8081"}
TIMEOUT_SECS=${TIMEOUT_SECS:-5}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Envoy 1.24 is currently not working as the request gets trapped. This timeout allows to timeout the request in such case.


[[ "${DEBUG}" == "true" ]] && set -x

Expand Down Expand Up @@ -47,7 +48,7 @@ function check_status() {
local url=${1}
local status=${2}
local args=("${@:3}" --write-out '%{http_code}' --silent --output /dev/null)
status_code=$(curl "${args[@]}" "${url}")
status_code=$(curl --max-time ${TIMEOUT_SECS} "${args[@]}" "${url}")
if [[ "${status_code}" -ne ${status} ]] ; then
echo "[Fail] Unexpected response with code ${status_code} from ${url}"
exit 1
Expand All @@ -64,7 +65,7 @@ function check_body() {
local url=${1}
local empty=${2}
local args=("${@:3}" --silent)
response_body=$(curl "${args[@]}" "${url}")
response_body=$(curl --max-time ${TIMEOUT_SECS} "${args[@]}" "${url}")
if [[ "${empty}" == "true" ]] && [[ -n "${response_body}" ]]; then
echo -e "[Fail] Unexpected response with a body. Body dump:\n${response_body}"
exit 1
Expand Down
6 changes: 5 additions & 1 deletion example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ services:
image: mccutchen/go-httpbin:v2.5.0
environment:
- MAX_BODY_SIZE=15728640 # 15 MiB
ports:
- 8081:8080

chown:
image: alpine:3.16
command:
Expand All @@ -11,11 +14,12 @@ services:
- chown -R 101:101 /home/envoy/logs
volumes:
- logs:/home/envoy/logs:rw

envoy:
depends_on:
- chown
- httpbin
image: envoyproxy/envoy:v1.23-latest
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.23-latest}
command:
- -c
- /conf/envoy-config.yaml
Expand Down
2 changes: 1 addition & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func Ftw() error {

// RunExample spins up the test environment, access at http://localhost:8080. Requires docker-compose.
func RunExample() error {
return sh.RunV("docker-compose", "--file", "example/docker-compose.yml", "up", "-d", "envoy-logs")
return sh.RunWithV(map[string]string{"ENVOY_IMAGE": os.Getenv("ENVOY_IMAGE")}, "docker-compose", "--file", "example/docker-compose.yml", "up", "-d", "envoy-logs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to run the example with different envoy versions.

}

// TeardownExample tears down the test environment. Requires docker-compose.
Expand Down
28 changes: 28 additions & 0 deletions wasmplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ type httpContext struct {
processedResponseBody bool
requestBodySize int
responseBodySize int
interruptionHandled bool
metrics *wafMetrics
}

// Override types.DefaultHttpContext.
func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
if ctx.interruptionHandled {
proxywasm.LogErrorf("interruption already handled")
return types.ActionPause
}

defer logTime("OnHttpRequestHeaders", currentTime())
ctx.metrics.CountTX()
tx := ctx.tx
Expand Down Expand Up @@ -173,6 +179,11 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t
}

func (ctx *httpContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action {
if ctx.interruptionHandled {
proxywasm.LogErrorf("interruption already handled")
return types.ActionPause
}

defer logTime("OnHttpRequestBody", currentTime())
tx := ctx.tx

Expand Down Expand Up @@ -221,6 +232,11 @@ func (ctx *httpContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.
}

func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action {
if ctx.interruptionHandled {
proxywasm.LogErrorf("interruption already handled")
return types.ActionPause
}

defer logTime("OnHttpResponseHeaders", currentTime())
tx := ctx.tx

Expand Down Expand Up @@ -271,6 +287,11 @@ func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool)
}

func (ctx *httpContext) OnHttpResponseBody(bodySize int, endOfStream bool) types.Action {
if ctx.interruptionHandled {
proxywasm.LogErrorf("interruption already handled")
return types.ActionPause
}

defer logTime("OnHttpResponseBody", currentTime())
tx := ctx.tx

Expand Down Expand Up @@ -358,6 +379,11 @@ func (ctx *httpContext) OnHttpStreamDone() {
}

func (ctx *httpContext) handleInterruption(phase string, interruption *ctypes.Interruption) types.Action {
if ctx.interruptionHandled {
// This should never happen
panic("interruption already handled")
}

ctx.metrics.CountTXInterruption(phase, interruption.RuleID)

proxywasm.LogInfof("%d interrupted, action %q", ctx.contextID, interruption.Action)
Expand All @@ -370,6 +396,8 @@ func (ctx *httpContext) handleInterruption(phase string, interruption *ctypes.In
panic(err)
}

ctx.interruptionHandled = true

return types.ActionPause
}

Expand Down