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

Add peering integration tests #14836

Merged
merged 4 commits into from
Oct 4, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config_entries {
bootstrap = [
{
kind = "proxy-defaults"
name = "global"

config {
protocol = "tcp"
}
},
{
kind = "exported-services"
name = "default"
services = [
{
name = "s2"
consumers = [
{
peer_name = "alpha-to-primary"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services {
name = "mesh-gateway"
kind = "mesh-gateway"
port = 4432
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# We don't want an s1 service in this peer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services {
name = "s2"
port = 8181
checks = []
connect {
sidecar_service {
checks = []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -euo pipefail

register_services alpha

gen_envoy_bootstrap s2 19002 alpha
gen_envoy_bootstrap mesh-gateway 19003 alpha true

wait_for_config_entry proxy-defaults global alpha
wait_for_config_entry exported-services default alpha
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bats

load helpers

@test "s2 proxy is running correct version" {
assert_envoy_version 19002
}

@test "s2 proxy admin is up on :19002" {
retry_default curl -f -s localhost:19002/stats -o /dev/null
}

@test "gateway-alpha proxy admin is up on :19003" {
retry_default curl -f -s localhost:19003/stats -o /dev/null
}

@test "s2 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s2 alpha
}

@test "s2 proxy should be healthy" {
assert_service_has_healthy_instances s2 1 alpha
}

@test "gateway-alpha should be up and listening" {
retry_long nc -z consul-alpha-client:4432
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bind_addr = "0.0.0.0"
advertise_addr = "{{ GetInterfaceIP \"eth0\" }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

snapshot_envoy_admin localhost:19000 s1 primary || true
snapshot_envoy_admin localhost:19001 s2 primary || true
snapshot_envoy_admin localhost:19002 s2 alpha || true
snapshot_envoy_admin localhost:19003 mesh-gateway alpha || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
config_entries {
bootstrap {
kind = "proxy-defaults"
name = "global"

config {
protocol = "http"
}
}

bootstrap {
kind = "service-splitter"
name = "split-s2"
splits = [
{
Weight = 50
Service = "local-s2"
ResponseHeaders {
Set {
"x-test-split" = "primary"
}
}
},
{
Weight = 50
Service = "peer-s2"
ResponseHeaders {
Set {
"x-test-split" = "alpha"
}
}
},
]
}

bootstrap {
kind = "service-resolver"
name = "local-s2"
redirect = {
service = "s2"
}
}

bootstrap {
kind = "service-resolver"
name = "peer-s2"

redirect = {
service = "s2"
peer = "primary-to-alpha"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services {
name = "s1"
port = 8080
checks = []
connect {
sidecar_service {
checks = []
proxy {
upstreams = [
{
destination_name = "split-s2"
local_bind_port = 5000
},
{
destination_name = "peer-s2"
local_bind_port = 5001
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services {
name = "s2"
port = 8181
checks = []
connect {
sidecar_service {
checks = []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

register_services primary

gen_envoy_bootstrap s1 19000 primary
gen_envoy_bootstrap s2 19001 primary

wait_for_config_entry proxy-defaults global
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bats

load helpers

@test "s1 proxy is running correct version" {
assert_envoy_version 19000
}

@test "s1 proxy admin is up" {
retry_default curl -f -s localhost:19000/stats -o /dev/null
}

@test "s2 proxy admin is up" {
retry_default curl -f -s localhost:19001/stats -o /dev/null
}

@test "s1 proxy listener should be up and have right cert" {
assert_proxy_presents_cert_uri localhost:21000 s1
}

@test "s2 proxies should be healthy in primary" {
assert_service_has_healthy_instances s2 1 primary
}

@test "s2 proxies should be healthy in alpha" {
assert_service_has_healthy_instances s2 1 alpha
}

@test "gateway-alpha should be up and listening" {
retry_long nc -z consul-alpha-client:4432
}

@test "peer the two clusters together" {
create_peering primary alpha
}

@test "s2 alpha proxies should be healthy in primary" {
assert_service_has_healthy_instances s2 1 primary "" "" primary-to-alpha
}

@test "s1 upstream should have healthy endpoints for s2 primary and alpha" {
assert_upstream_has_endpoints_in_status 127.0.0.1:19000 s2.default.primary.internal HEALTHY 1
assert_upstream_has_endpoints_in_status 127.0.0.1:19000 s2.default.primary-to-alpha.external HEALTHY 1
}

@test "s1 upstream should be split between peer and local dc" {
retry_long assert_url_header "http://127.0.0.1:5000/" "x-test-split" "primary"
[ "$status" -eq 0 ]
retry_long assert_url_header "http://127.0.0.1:5000/" "x-test-split" "alpha"
[ "$status" -eq 0 ]
hashi-derek marked this conversation as resolved.
Show resolved Hide resolved
retry_long assert_expected_fortio_name s2 127.0.0.1 5000
retry_long assert_expected_fortio_name s2-alpha 127.0.0.1 5000
}

@test "s1 upstream made 2 connections to primary s2 split" {
retry_long assert_envoy_metric_at_least 127.0.0.1:19000 "cluster.s2.default.primary.internal.*upstream_rq_total" 1
}

@test "s1 upstream made 2 connections to alpha s2 split" {
retry_long assert_envoy_metric_at_least 127.0.0.1:19000 "cluster.s2.default.primary-to-alpha.external.*upstream_rq_total" 1
}

@test "reset envoy statistics" {
reset_envoy_metrics 127.0.0.1:19000
retry_long assert_envoy_metric 127.0.0.1:19000 "cluster.s2.default.primary-to-alpha.external.*upstream_rq_total" 0
}

@test "s1 upstream should be able to connect to s2 via peer-s2" {
assert_expected_fortio_name s2-alpha 127.0.0.1 5001
}

@test "s1 upstream made 1 connection to s2 via peer-s2" {
retry_long assert_envoy_metric_at_least 127.0.0.1:19000 "http.upstream.peer-s2.default.default.primary.rq_total" 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export REQUIRED_SERVICES="s1 s1-sidecar-proxy s2 s2-sidecar-proxy s2-alpha s2-sidecar-proxy-alpha gateway-alpha"
export REQUIRE_PEERS=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
primary_datacenter = "alpha"
log_level = "trace"
peering {
enabled = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
config_entries {
bootstrap = [
{
kind = "proxy-defaults"
name = "global"

config {
protocol = "tcp"
}
},
{
kind = "exported-services"
name = "default"
services = [
{
name = "s1"
consumers = [
{
peer_name = "alpha-to-primary"
}
]
},
{
name = "s2"
consumers = [
{
peer_name = "alpha-to-primary"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services {
name = "mesh-gateway"
kind = "mesh-gateway"
port = 4432
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services {
name = "s1"
port = 8080
checks = []
connect {
sidecar_service {
checks = []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services {
name = "s2"
port = 8181
checks = []
connect {
sidecar_service {
checks = []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -euo pipefail

wait_for_config_entry proxy-defaults global alpha
wait_for_config_entry exported-services default alpha

register_services alpha

gen_envoy_bootstrap s1 19001 alpha
gen_envoy_bootstrap s2 19002 alpha
gen_envoy_bootstrap mesh-gateway 19003 alpha true
Loading