test: for envoy integration tests, wait until 's2' is healthy in consul before interrogating envoy (#6108)

When the envoy healthy panic threshold was explicitly disabled as part
of L7 traffic management it changed how envoy decided to load balance to
endpoints in a cluster. This only matters when envoy is in "panic mode"
aka "when you have a bunch of unhealthy endpoints". Panic mode sends
traffic to unhealthy instances in certain circumstances.

Note: Prior to explicitly disabling the healthy panic threshold, the
default value is 50%.

What was happening is that the test harness was bringing up consul the
sidecars, and the service instances all at once and sometimes the
proxies wouldn't have time to be checked by consul to be labeled as
'passing' in the catalog before a round of EDS happened.

The xDS server in consul effectively queries /v1/health/connect/s2 and
gets 1 result, but that one result has a 'critical' check so the xDS
server sends back that endpoint labeled as UNHEALTHY.

Envoy sees that 100% of the endpoints in the cluster are unhealthy and
would enter panic mode and still send traffic to s2. This is why the
test suites PRIOR to disabling the healthy panic threshold worked. They
were _incorrectly_ passing.

When the healthy panic threshol is disabled, envoy never enters panic
mode in this situation and thus the cluster has zero healthy endpoints
so load balancing goes nowhere and the tests fail.

Why does this only affect the test suites for envoy 1.8.0? My guess is
that https://github.com/envoyproxy/envoy/pull/4442 was merged into the
1.9.x series and somehow that plays a role.

This PR modifies the bats scripts to explicitly wait until the upstream
sidecar is healthy as measured by /v1/health/connect/s2?passing BEFORE
trying to interrogate envoy which should make the tests less racy.
This commit is contained in:
R.B. Boyer 2019-07-10 15:58:25 -05:00 committed by GitHub
parent db8be40cae
commit 2165e97efa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 75 additions and 12 deletions

View File

@ -18,6 +18,10 @@ load helpers
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should NOT be able to connect to s2" { @test "s1 upstream should NOT be able to connect to s2" {
run retry_default must_fail_tcp_connection localhost:5000 run retry_default must_fail_tcp_connection localhost:5000

View File

@ -22,6 +22,10 @@ load helpers
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2" { @test "s1 upstream should be able to connect to s2" {
run retry_default curl -s -f -d hello localhost:5000 run retry_default curl -s -f -d hello localhost:5000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]

View File

@ -12,13 +12,16 @@ load helpers
@test "s1 proxy listener should be up and have right cert" { @test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1 assert_proxy_presents_cert_uri localhost:21000 s1
} }
@test "s2 proxy listener should be up and have right cert" { @test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2 with http/1.1" { @test "s1 upstream should be able to connect to s2 with http/1.1" {
run retry_default curl --http1.1 -s -f -d hello localhost:5000 run retry_default curl --http1.1 -s -f -d hello localhost:5000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -46,4 +49,4 @@ load helpers
retry_default \ retry_default \
must_match_in_prometheus_response localhost:1234 \ must_match_in_prometheus_response localhost:1234 \
'[\{,]envoy_http_conn_manager_prefix="upstream_s2_http"[,}]' '[\{,]envoy_http_conn_manager_prefix="upstream_s2_http"[,}]'
} }

View File

@ -10,6 +10,10 @@ load helpers
retry_default curl -f -s localhost:19001/stats -o /dev/null retry_default curl -f -s localhost:19001/stats -o /dev/null
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2" { @test "s1 upstream should be able to connect to s2" {
run retry_default curl -s -f -d hello localhost:5000 run retry_default curl -s -f -d hello localhost:5000
@ -60,4 +64,4 @@ load helpers
echo "INTERVAL = $INTERVAL" echo "INTERVAL = $INTERVAL"
[ "$INTERVAL" == "1s" ] [ "$INTERVAL" == "1s" ]
} }

View File

@ -10,6 +10,10 @@ load helpers
retry_default curl -f -s localhost:19001/stats -o /dev/null retry_default curl -f -s localhost:19001/stats -o /dev/null
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2 via grpc" { @test "s1 upstream should be able to connect to s2 via grpc" {
run fortio grpcping localhost:5000 run fortio grpcping localhost:5000

View File

@ -18,6 +18,10 @@ load helpers
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should NOT be able to connect to s2" { @test "s1 upstream should NOT be able to connect to s2" {
run retry_default must_fail_http_connection localhost:5000 run retry_default must_fail_http_connection localhost:5000

View File

@ -12,13 +12,16 @@ load helpers
@test "s1 proxy listener should be up and have right cert" { @test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1 assert_proxy_presents_cert_uri localhost:21000 s1
} }
@test "s2 proxy listener should be up and have right cert" { @test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2 with http/1.1" { @test "s1 upstream should be able to connect to s2 with http/1.1" {
run retry_default curl --http1.1 -s -f -d hello localhost:5000 run retry_default curl --http1.1 -s -f -d hello localhost:5000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -36,4 +39,4 @@ load helpers
[ "$PUB" = "envoy.ext_authz,envoy.http_connection_manager" ] [ "$PUB" = "envoy.ext_authz,envoy.http_connection_manager" ]
[ "$UPS" = "envoy.http_connection_manager" ] [ "$UPS" = "envoy.http_connection_manager" ]
} }

View File

@ -12,13 +12,16 @@ load helpers
@test "s1 proxy listener should be up and have right cert" { @test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1 assert_proxy_presents_cert_uri localhost:21000 s1
} }
@test "s2 proxy listener should be up and have right cert" { @test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2 via http2" { @test "s1 upstream should be able to connect to s2 via http2" {
# We use grpc here because it's the easiest way to test http2. The server # We use grpc here because it's the easiest way to test http2. The server
# needs to support h2c since the proxy doesn't talk TLS to the local app. # needs to support h2c since the proxy doesn't talk TLS to the local app.
@ -28,4 +31,4 @@ load helpers
echo "OUTPUT: $output" echo "OUTPUT: $output"
[ "$status" == 0 ] [ "$status" == 0 ]
} }

View File

@ -12,13 +12,16 @@ load helpers
@test "s1 proxy listener should be up and have right cert" { @test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1 assert_proxy_presents_cert_uri localhost:21000 s1
} }
@test "s2 proxy listener should be up and have right cert" { @test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2 with http/1.1" { @test "s1 upstream should be able to connect to s2 with http/1.1" {
run retry_default curl --http1.1 -s -f -d hello localhost:5000 run retry_default curl --http1.1 -s -f -d hello localhost:5000
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -41,4 +44,4 @@ load helpers
retry_default \ retry_default \
must_match_in_prometheus_response localhost:1234 \ must_match_in_prometheus_response localhost:1234 \
'[\{,]envoy_http_conn_manager_prefix="public_listener_http"[,}]' '[\{,]envoy_http_conn_manager_prefix="public_listener_http"[,}]'
} }

View File

@ -10,6 +10,10 @@ load helpers
retry_default curl -f -s localhost:19001/stats -o /dev/null retry_default curl -f -s localhost:19001/stats -o /dev/null
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2" { @test "s1 upstream should be able to connect to s2" {
run retry_default curl -s -f -d hello localhost:5000 run retry_default curl -s -f -d hello localhost:5000
[ "$status" == 0 ] [ "$status" == 0 ]
@ -22,4 +26,4 @@ load helpers
echo "OUTPUT: $output" echo "OUTPUT: $output"
[ "$status" == 0 ] [ "$status" == 0 ]
} }

View File

@ -12,13 +12,16 @@ load helpers
@test "s1 proxy listener should be up and have right cert" { @test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1 assert_proxy_presents_cert_uri localhost:21000 s1
} }
@test "s2 proxy listener should be up and have right cert" { @test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21001 s2 assert_proxy_presents_cert_uri localhost:21001 s2
} }
@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1
}
@test "s1 upstream should be able to connect to s2" { @test "s1 upstream should be able to connect to s2" {
run retry_default curl -s -f -d hello localhost:5000 run retry_default curl -s -f -d hello localhost:5000
[ "$status" == "0" ] [ "$status" == "0" ]
@ -41,4 +44,4 @@ load helpers
# Get the trace from Jaeger. Won't bother parsing it just seeing it show up # Get the trace from Jaeger. Won't bother parsing it just seeing it show up
# there is enough to know that the tracing config worked. # there is enough to know that the tracing config worked.
run retry_default curl -s -f "localhost:16686/api/traces/$TRACEID" run retry_default curl -s -f "localhost:16686/api/traces/$TRACEID"
} }

View File

@ -120,6 +120,30 @@ function snapshot_envoy_admin {
docker_wget "http://${HOSTPORT}/clusters" -q -O - > "./workdir/envoy/${ENVOY_NAME}-clusters.out" docker_wget "http://${HOSTPORT}/clusters" -q -O - > "./workdir/envoy/${ENVOY_NAME}-clusters.out"
} }
function get_healthy_service_count {
local SERVICE_NAME=$1
run retry_default curl -s -f 127.0.0.1:8500/v1/health/connect/${SERVICE_NAME}?passing
[ "$status" -eq 0 ]
echo "$output" | jq --raw-output '. | length'
}
function health_service_count_matches {
local SERVICE_NAME=$1
local EXPECT_COUNT=$2
GOT_COUNT=$(get_healthy_service_count $SERVICE_NAME)
[ "$GOT_COUNT" -eq $EXPECT_COUNT ]
}
function assert_service_has_healthy_instances {
local SERVICE_NAME=$1
local EXPECT_COUNT=$2
run retry 10 2 health_service_count_matches $SERVICE_NAME $EXPECT_COUNT
[ "$status" -eq 0 ]
}
function docker_consul { function docker_consul {
docker run -ti --rm --network container:envoy_consul_1 consul-dev $@ docker run -ti --rm --network container:envoy_consul_1 consul-dev $@
} }