2021-04-29 18:54:05 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-09-07 20:29:32 +00:00
|
|
|
"github.com/hashicorp/consul/agent/connect"
|
2022-09-09 14:02:01 +00:00
|
|
|
"github.com/hashicorp/consul/agent/grpc-external/limiter"
|
2023-02-06 17:14:35 +00:00
|
|
|
"github.com/hashicorp/consul/envoyextensions/xdscommon"
|
2021-09-07 20:29:32 +00:00
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
|
|
|
|
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
|
|
|
envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
|
|
|
|
envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
|
|
|
|
envoy_rbac_v3 "github.com/envoyproxy/go-control-plane/envoy/config/rbac/v3"
|
|
|
|
envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
|
2022-04-18 16:36:07 +00:00
|
|
|
envoy_http_router_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
|
2021-04-29 18:54:05 +00:00
|
|
|
envoy_http_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
|
|
|
|
envoy_network_rbac_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/rbac/v3"
|
|
|
|
envoy_tcp_proxy_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
|
|
|
|
envoy_tls_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
|
2022-03-30 16:51:56 +00:00
|
|
|
envoy_upstreams_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
|
2021-04-29 18:54:05 +00:00
|
|
|
envoy_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
|
|
|
|
envoy_type_v3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
|
|
|
|
|
2021-05-14 18:59:13 +00:00
|
|
|
"github.com/armon/go-metrics"
|
2021-04-29 18:54:05 +00:00
|
|
|
"github.com/mitchellh/copystructure"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-01-11 14:39:10 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2022-03-30 16:51:56 +00:00
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
2022-05-25 01:44:54 +00:00
|
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
2023-01-11 14:39:10 +00:00
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
2021-04-29 18:54:05 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: this file is a collection of test helper functions for testing xDS
|
|
|
|
// protocols.
|
|
|
|
|
|
|
|
func newTestSnapshot(
|
|
|
|
t *testing.T,
|
|
|
|
prevSnap *proxycfg.ConfigSnapshot,
|
|
|
|
dbServiceProtocol string,
|
|
|
|
additionalEntries ...structs.ConfigEntry,
|
|
|
|
) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
snap := proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", false, nil, nil, additionalEntries...)
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.PreparedQueryEndpoints = map[proxycfg.UpstreamID]structs.CheckServiceNodes{
|
|
|
|
UID("prepared_query:geo-cache"): proxycfg.TestPreparedQueryNodes(t, "geo-cache"),
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
if prevSnap != nil {
|
|
|
|
snap.Roots = prevSnap.Roots
|
|
|
|
snap.ConnectProxy.Leaf = prevSnap.ConnectProxy.Leaf
|
|
|
|
}
|
|
|
|
if dbServiceProtocol != "" {
|
|
|
|
// Simulate ServiceManager injection of protocol
|
|
|
|
snap.Proxy.Upstreams[0].Config["protocol"] = dbServiceProtocol
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.ConfigSnapshotUpstreams.UpstreamConfig = proxycfg.UpstreamsToMap(snap.Proxy.Upstreams)
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
|
|
|
// testManager is a mock of proxycfg.Manager that's simpler to control for
|
|
|
|
// testing. It also implements ConnectAuthz to allow control over authorization.
|
|
|
|
type testManager struct {
|
|
|
|
sync.Mutex
|
2023-01-18 18:33:21 +00:00
|
|
|
stateChans map[structs.ServiceID]chan *proxycfg.ConfigSnapshot
|
|
|
|
drainChans map[structs.ServiceID]chan struct{}
|
|
|
|
cancels chan structs.ServiceID
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTestManager(t *testing.T) *testManager {
|
|
|
|
return &testManager{
|
2023-01-18 18:33:21 +00:00
|
|
|
stateChans: map[structs.ServiceID]chan *proxycfg.ConfigSnapshot{},
|
|
|
|
drainChans: map[structs.ServiceID]chan struct{}{},
|
|
|
|
cancels: make(chan structs.ServiceID, 10),
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterProxy simulates a proxy registration
|
|
|
|
func (m *testManager) RegisterProxy(t *testing.T, proxyID structs.ServiceID) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2023-01-18 18:33:21 +00:00
|
|
|
m.stateChans[proxyID] = make(chan *proxycfg.ConfigSnapshot, 1)
|
|
|
|
m.drainChans[proxyID] = make(chan struct{})
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Deliver simulates a proxy registration
|
|
|
|
func (m *testManager) DeliverConfig(t *testing.T, proxyID structs.ServiceID, cfg *proxycfg.ConfigSnapshot) {
|
|
|
|
t.Helper()
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
select {
|
2023-01-18 18:33:21 +00:00
|
|
|
case m.stateChans[proxyID] <- cfg:
|
2021-04-29 18:54:05 +00:00
|
|
|
case <-time.After(10 * time.Millisecond):
|
|
|
|
t.Fatalf("took too long to deliver config")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 18:33:21 +00:00
|
|
|
// DrainStreams drains any open streams for the given proxyID. If there aren't
|
|
|
|
// any open streams, it'll create a marker so that future attempts to watch the
|
|
|
|
// given proxyID will return limiter.ErrCapacityReached.
|
|
|
|
func (m *testManager) DrainStreams(proxyID structs.ServiceID) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
|
|
|
ch, ok := m.drainChans[proxyID]
|
|
|
|
if !ok {
|
|
|
|
ch = make(chan struct{})
|
|
|
|
m.drainChans[proxyID] = ch
|
|
|
|
}
|
|
|
|
close(ch)
|
|
|
|
}
|
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
// Watch implements ConfigManager
|
2023-01-18 18:33:21 +00:00
|
|
|
func (m *testManager) Watch(proxyID structs.ServiceID, _ string, _ string) (<-chan *proxycfg.ConfigSnapshot, limiter.SessionTerminatedChan, proxycfg.CancelFunc, error) {
|
2021-04-29 18:54:05 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2023-01-18 18:33:21 +00:00
|
|
|
|
|
|
|
// If the drain chan has already been closed, return limiter.ErrCapacityReached.
|
|
|
|
drainCh := m.drainChans[proxyID]
|
|
|
|
select {
|
|
|
|
case <-drainCh:
|
|
|
|
return nil, nil, nil, limiter.ErrCapacityReached
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
// ch might be nil but then it will just block forever
|
2023-01-18 18:33:21 +00:00
|
|
|
return m.stateChans[proxyID], drainCh, func() {
|
2021-04-29 18:54:05 +00:00
|
|
|
m.cancels <- proxyID
|
2022-05-27 11:38:52 +00:00
|
|
|
}, nil
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AssertWatchCancelled checks that the most recent call to a Watch cancel func
|
|
|
|
// was from the specified proxyID and that one is made in a short time. This
|
|
|
|
// probably won't work if you are running multiple Watches in parallel on
|
|
|
|
// multiple proxyIDS due to timing/ordering issues but I don't think we need to
|
|
|
|
// do that.
|
|
|
|
func (m *testManager) AssertWatchCancelled(t *testing.T, proxyID structs.ServiceID) {
|
|
|
|
t.Helper()
|
|
|
|
select {
|
|
|
|
case got := <-m.cancels:
|
|
|
|
require.Equal(t, proxyID, got)
|
|
|
|
case <-time.After(50 * time.Millisecond):
|
|
|
|
t.Fatalf("timed out waiting for Watch cancel for %s", proxyID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testServerScenario struct {
|
|
|
|
server *Server
|
|
|
|
mgr *testManager
|
|
|
|
envoy *TestEnvoy
|
2021-05-14 18:59:13 +00:00
|
|
|
sink *metrics.InmemSink
|
2021-04-29 18:54:05 +00:00
|
|
|
errCh <-chan error
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestServerDeltaScenario(
|
|
|
|
t *testing.T,
|
2023-02-07 18:26:30 +00:00
|
|
|
resolveTokenSecret ACLResolverFunc,
|
2021-04-29 18:54:05 +00:00
|
|
|
proxyID string,
|
|
|
|
token string,
|
|
|
|
authCheckFrequency time.Duration,
|
|
|
|
) *testServerScenario {
|
|
|
|
mgr := newTestManager(t)
|
|
|
|
envoy := NewTestEnvoy(t, proxyID, token)
|
|
|
|
|
2021-05-14 18:59:13 +00:00
|
|
|
sink := metrics.NewInmemSink(1*time.Minute, 1*time.Minute)
|
|
|
|
cfg := metrics.DefaultConfig("consul.xds.test")
|
|
|
|
cfg.EnableHostname = false
|
|
|
|
cfg.EnableRuntimeMetrics = false
|
|
|
|
metrics.NewGlobal(cfg, sink)
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
2023-02-23 19:52:18 +00:00
|
|
|
envoy.Close()
|
2021-05-14 18:59:13 +00:00
|
|
|
sink := &metrics.BlackholeSink{}
|
|
|
|
metrics.NewGlobal(cfg, sink)
|
|
|
|
})
|
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
s := NewServer(
|
2022-05-27 11:38:52 +00:00
|
|
|
"node-123",
|
2021-04-29 18:54:05 +00:00
|
|
|
testutil.Logger(t),
|
|
|
|
mgr,
|
2023-02-07 18:26:30 +00:00
|
|
|
resolveTokenSecret,
|
2021-04-29 18:54:05 +00:00
|
|
|
nil, /*cfgFetcher ConfigFetcher*/
|
|
|
|
)
|
2021-09-21 14:58:56 +00:00
|
|
|
if authCheckFrequency > 0 {
|
|
|
|
s.AuthCheckFrequency = authCheckFrequency
|
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
|
|
|
|
errCh := make(chan error, 1)
|
|
|
|
go func() {
|
2021-10-28 01:51:35 +00:00
|
|
|
errCh <- s.DeltaAggregatedResources(envoy.deltaStream)
|
2021-04-29 18:54:05 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return &testServerScenario{
|
|
|
|
server: s,
|
|
|
|
mgr: mgr,
|
|
|
|
envoy: envoy,
|
2021-05-14 18:59:13 +00:00
|
|
|
sink: sink,
|
2021-04-29 18:54:05 +00:00
|
|
|
errCh: errCh,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func protoToSortedJSON(t *testing.T, pb proto.Message) string {
|
|
|
|
dup, err := copystructure.Copy(pb)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pb = dup.(proto.Message)
|
|
|
|
|
|
|
|
switch x := pb.(type) {
|
|
|
|
case *envoy_discovery_v3.DeltaDiscoveryResponse:
|
|
|
|
sort.Slice(x.Resources, func(i, j int) bool {
|
|
|
|
return x.Resources[i].Name < x.Resources[j].Name
|
|
|
|
})
|
|
|
|
sort.Strings(x.RemovedResources)
|
|
|
|
}
|
|
|
|
|
|
|
|
return protoToJSON(t, pb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewEndpoint(ip string, port int) *envoy_endpoint_v3.LbEndpoint {
|
|
|
|
return &envoy_endpoint_v3.LbEndpoint{
|
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
|
|
|
Address: makeAddress(ip, port),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewEndpointWithHealth(ip string, port int, health envoy_core_v3.HealthStatus, weight int) *envoy_endpoint_v3.LbEndpoint {
|
|
|
|
ep := xdsNewEndpoint(ip, port)
|
|
|
|
ep.HealthStatus = health
|
|
|
|
ep.LoadBalancingWeight = makeUint32Value(weight)
|
|
|
|
return ep
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewADSConfig() *envoy_core_v3.ConfigSource {
|
|
|
|
return &envoy_core_v3.ConfigSource{
|
|
|
|
ResourceApiVersion: envoy_core_v3.ApiVersion_V3,
|
|
|
|
ConfigSourceSpecifier: &envoy_core_v3.ConfigSource_Ads{
|
|
|
|
Ads: &envoy_core_v3.AggregatedConfigSource{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewPublicTransportSocket(
|
|
|
|
t *testing.T,
|
|
|
|
snap *proxycfg.ConfigSnapshot,
|
|
|
|
) *envoy_core_v3.TransportSocket {
|
2021-08-19 22:33:42 +00:00
|
|
|
return xdsNewTransportSocket(t, snap, true, true, "")
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewUpstreamTransportSocket(
|
|
|
|
t *testing.T,
|
|
|
|
snap *proxycfg.ConfigSnapshot,
|
|
|
|
sni string,
|
2022-05-27 01:24:55 +00:00
|
|
|
spiffeID ...string,
|
2021-04-29 18:54:05 +00:00
|
|
|
) *envoy_core_v3.TransportSocket {
|
2022-05-27 01:24:55 +00:00
|
|
|
return xdsNewTransportSocket(t, snap, false, false, sni, spiffeID...)
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewTransportSocket(
|
|
|
|
t *testing.T,
|
|
|
|
snap *proxycfg.ConfigSnapshot,
|
|
|
|
downstream bool,
|
|
|
|
requireClientCert bool,
|
|
|
|
sni string,
|
2022-05-27 01:24:55 +00:00
|
|
|
spiffeID ...string,
|
2021-04-29 18:54:05 +00:00
|
|
|
) *envoy_core_v3.TransportSocket {
|
|
|
|
// Assume just one root for now, can get fancier later if needed.
|
|
|
|
caPEM := snap.Roots.Roots[0].RootCert
|
|
|
|
|
2021-06-29 01:58:12 +00:00
|
|
|
commonTLSContext := &envoy_tls_v3.CommonTlsContext{
|
2021-04-29 18:54:05 +00:00
|
|
|
TlsParams: &envoy_tls_v3.TlsParameters{},
|
|
|
|
TlsCertificates: []*envoy_tls_v3.TlsCertificate{{
|
|
|
|
CertificateChain: xdsNewInlineString(snap.Leaf().CertPEM),
|
|
|
|
PrivateKey: xdsNewInlineString(snap.Leaf().PrivateKeyPEM),
|
|
|
|
}},
|
|
|
|
ValidationContextType: &envoy_tls_v3.CommonTlsContext_ValidationContext{
|
|
|
|
ValidationContext: &envoy_tls_v3.CertificateValidationContext{
|
|
|
|
TrustedCa: xdsNewInlineString(caPEM),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-05-27 01:24:55 +00:00
|
|
|
if len(spiffeID) > 0 {
|
|
|
|
require.NoError(t, injectSANMatcher(commonTLSContext, spiffeID...))
|
2021-06-29 01:58:12 +00:00
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
|
|
|
|
var tlsContext proto.Message
|
|
|
|
if downstream {
|
2023-01-11 14:39:10 +00:00
|
|
|
var requireClientCertPB *wrapperspb.BoolValue
|
2021-04-29 18:54:05 +00:00
|
|
|
if requireClientCert {
|
|
|
|
requireClientCertPB = makeBoolValue(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsContext = &envoy_tls_v3.DownstreamTlsContext{
|
2021-06-29 01:58:12 +00:00
|
|
|
CommonTlsContext: commonTLSContext,
|
2021-04-29 18:54:05 +00:00
|
|
|
RequireClientCertificate: requireClientCertPB,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tlsContext = &envoy_tls_v3.UpstreamTlsContext{
|
2021-06-29 01:58:12 +00:00
|
|
|
CommonTlsContext: commonTLSContext,
|
2021-04-29 18:54:05 +00:00
|
|
|
Sni: sni,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:39:10 +00:00
|
|
|
any, err := anypb.New(tlsContext)
|
2021-04-29 18:54:05 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return &envoy_core_v3.TransportSocket{
|
|
|
|
Name: "tls",
|
|
|
|
ConfigType: &envoy_core_v3.TransportSocket_TypedConfig{
|
|
|
|
TypedConfig: any,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewInlineString(s string) *envoy_core_v3.DataSource {
|
|
|
|
return &envoy_core_v3.DataSource{
|
|
|
|
Specifier: &envoy_core_v3.DataSource_InlineString{
|
|
|
|
InlineString: s,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewFilter(t *testing.T, name string, cfg proto.Message) *envoy_listener_v3.Filter {
|
|
|
|
f, err := makeFilter(name, cfg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2022-04-18 16:36:07 +00:00
|
|
|
func xdsNewListenerFilter(t *testing.T, name string, cfg proto.Message) *envoy_listener_v3.ListenerFilter {
|
|
|
|
f, err := makeEnvoyListenerFilter(name, cfg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
func xdsNewHttpFilter(t *testing.T, name string, cfg proto.Message) *envoy_http_v3.HttpFilter {
|
|
|
|
f, err := makeEnvoyHTTPFilter(name, cfg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
func mustHashResource(t *testing.T, res proto.Message) string {
|
|
|
|
v, err := hashResource(res)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestResources(t *testing.T, resources ...interface{}) []*envoy_discovery_v3.Resource {
|
|
|
|
var ret []*envoy_discovery_v3.Resource
|
|
|
|
for _, res := range resources {
|
|
|
|
ret = append(ret, makeTestResource(t, res))
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestResource(t *testing.T, raw interface{}) *envoy_discovery_v3.Resource {
|
|
|
|
switch res := raw.(type) {
|
|
|
|
case string:
|
|
|
|
return &envoy_discovery_v3.Resource{
|
|
|
|
Name: res,
|
|
|
|
}
|
|
|
|
case proto.Message:
|
|
|
|
|
2023-01-11 14:39:10 +00:00
|
|
|
any, err := anypb.New(res)
|
2021-04-29 18:54:05 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return &envoy_discovery_v3.Resource{
|
2023-02-03 06:18:10 +00:00
|
|
|
Name: xdscommon.GetResourceName(res),
|
2021-04-29 18:54:05 +00:00
|
|
|
Version: mustHashResource(t, res),
|
|
|
|
Resource: any,
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected type: %T", res)
|
|
|
|
return nil // not possible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName string) *envoy_cluster_v3.Cluster {
|
2021-06-29 01:58:12 +00:00
|
|
|
var (
|
|
|
|
dbSNI = "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
|
2021-06-30 16:16:33 +00:00
|
|
|
dbURI = connect.SpiffeIDService{
|
|
|
|
Host: "11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Namespace: "default",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Service: "db",
|
2022-05-27 01:24:55 +00:00
|
|
|
}.URI().String()
|
2021-06-29 01:58:12 +00:00
|
|
|
|
2021-08-19 00:06:41 +00:00
|
|
|
geocacheSNI = "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul"
|
2022-05-27 01:24:55 +00:00
|
|
|
geocacheURIs = []string{
|
|
|
|
connect.SpiffeIDService{
|
2021-08-19 00:06:41 +00:00
|
|
|
Host: "11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Namespace: "default",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Service: "geo-cache-target",
|
2022-05-27 01:24:55 +00:00
|
|
|
}.URI().String(),
|
|
|
|
connect.SpiffeIDService{
|
2021-08-19 00:06:41 +00:00
|
|
|
Host: "11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Namespace: "default",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
Service: "geo-cache-target",
|
2022-05-27 01:24:55 +00:00
|
|
|
}.URI().String(),
|
2021-06-30 16:16:33 +00:00
|
|
|
}
|
2021-06-29 01:58:12 +00:00
|
|
|
)
|
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
switch fixtureName {
|
|
|
|
case "tcp:local_app":
|
|
|
|
return &envoy_cluster_v3.Cluster{
|
|
|
|
Name: "local_app",
|
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_STATIC,
|
|
|
|
},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(5 * time.Second),
|
2021-04-29 18:54:05 +00:00
|
|
|
LoadAssignment: &envoy_endpoint_v3.ClusterLoadAssignment{
|
|
|
|
ClusterName: "local_app",
|
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
|
|
|
xdsNewEndpoint("127.0.0.1", 8080),
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "tcp:db":
|
|
|
|
return &envoy_cluster_v3.Cluster{
|
2021-06-29 01:58:12 +00:00
|
|
|
Name: dbSNI,
|
2021-04-29 18:54:05 +00:00
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_EDS,
|
|
|
|
},
|
|
|
|
EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{
|
|
|
|
EdsConfig: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{},
|
|
|
|
OutlierDetection: &envoy_cluster_v3.OutlierDetection{},
|
2021-06-29 01:58:12 +00:00
|
|
|
AltStatName: dbSNI,
|
2021-04-29 18:54:05 +00:00
|
|
|
CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{
|
|
|
|
HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(5 * time.Second),
|
2021-06-29 01:58:12 +00:00
|
|
|
TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI),
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
2021-06-14 22:20:27 +00:00
|
|
|
case "tcp:db:timeout":
|
|
|
|
return &envoy_cluster_v3.Cluster{
|
2021-06-29 01:58:12 +00:00
|
|
|
Name: dbSNI,
|
2021-06-14 22:20:27 +00:00
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_EDS,
|
|
|
|
},
|
|
|
|
EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{
|
|
|
|
EdsConfig: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{},
|
|
|
|
OutlierDetection: &envoy_cluster_v3.OutlierDetection{},
|
2021-06-29 01:58:12 +00:00
|
|
|
AltStatName: dbSNI,
|
2021-06-14 22:20:27 +00:00
|
|
|
CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{
|
|
|
|
HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(1337 * time.Second),
|
2021-06-29 01:58:12 +00:00
|
|
|
TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI),
|
2021-06-14 22:20:27 +00:00
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
case "http2:db":
|
2022-03-30 16:51:56 +00:00
|
|
|
c := &envoy_cluster_v3.Cluster{
|
2021-06-29 01:58:12 +00:00
|
|
|
Name: dbSNI,
|
2021-04-29 18:54:05 +00:00
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_EDS,
|
|
|
|
},
|
|
|
|
EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{
|
|
|
|
EdsConfig: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{},
|
|
|
|
OutlierDetection: &envoy_cluster_v3.OutlierDetection{},
|
2021-06-29 01:58:12 +00:00
|
|
|
AltStatName: dbSNI,
|
2021-04-29 18:54:05 +00:00
|
|
|
CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{
|
|
|
|
HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(5 * time.Second),
|
2022-03-30 16:51:56 +00:00
|
|
|
TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI),
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
2022-03-30 16:51:56 +00:00
|
|
|
typedExtensionProtocolOptions := &envoy_upstreams_v3.HttpProtocolOptions{
|
|
|
|
UpstreamProtocolOptions: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig_{
|
|
|
|
ExplicitHttpConfig: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig{
|
|
|
|
ProtocolConfig: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
|
|
|
|
Http2ProtocolOptions: &envoy_core_v3.Http2ProtocolOptions{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-01-11 14:39:10 +00:00
|
|
|
typedExtensionProtocolOptionsEncoded, err := anypb.New(typedExtensionProtocolOptions)
|
2022-03-30 16:51:56 +00:00
|
|
|
require.NoError(t, err)
|
2022-03-30 18:28:00 +00:00
|
|
|
c.TypedExtensionProtocolOptions = map[string]*anypb.Any{
|
|
|
|
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": typedExtensionProtocolOptionsEncoded,
|
|
|
|
}
|
2022-03-30 16:51:56 +00:00
|
|
|
return c
|
2021-06-14 22:20:27 +00:00
|
|
|
case "http:db":
|
|
|
|
return &envoy_cluster_v3.Cluster{
|
2021-06-29 01:58:12 +00:00
|
|
|
Name: dbSNI,
|
2021-06-14 22:20:27 +00:00
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_EDS,
|
|
|
|
},
|
|
|
|
EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{
|
|
|
|
EdsConfig: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{},
|
|
|
|
OutlierDetection: &envoy_cluster_v3.OutlierDetection{},
|
2021-06-29 01:58:12 +00:00
|
|
|
AltStatName: dbSNI,
|
2021-06-14 22:20:27 +00:00
|
|
|
CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{
|
|
|
|
HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(5 * time.Second),
|
2021-06-29 01:58:12 +00:00
|
|
|
TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI),
|
2021-06-14 22:20:27 +00:00
|
|
|
// HttpProtocolOptions: &envoy_core_v3.Http1ProtocolOptions{},
|
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
case "tcp:geo-cache":
|
|
|
|
return &envoy_cluster_v3.Cluster{
|
2021-06-29 01:58:12 +00:00
|
|
|
Name: geocacheSNI,
|
2021-04-29 18:54:05 +00:00
|
|
|
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{
|
|
|
|
Type: envoy_cluster_v3.Cluster_EDS,
|
|
|
|
},
|
|
|
|
EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{
|
|
|
|
EdsConfig: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{},
|
|
|
|
OutlierDetection: &envoy_cluster_v3.OutlierDetection{},
|
2022-05-25 01:44:54 +00:00
|
|
|
ConnectTimeout: durationpb.New(5 * time.Second),
|
2021-08-19 00:06:41 +00:00
|
|
|
TransportSocket: xdsNewUpstreamTransportSocket(t, snap, geocacheSNI, geocacheURIs...),
|
2021-04-29 18:54:05 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected fixture name: %s", fixtureName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestEndpoints(t *testing.T, _ *proxycfg.ConfigSnapshot, fixtureName string) *envoy_endpoint_v3.ClusterLoadAssignment {
|
|
|
|
switch fixtureName {
|
|
|
|
case "tcp:db":
|
|
|
|
return &envoy_endpoint_v3.ClusterLoadAssignment{
|
|
|
|
ClusterName: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{
|
|
|
|
{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.1", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.2", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-15 20:21:07 +00:00
|
|
|
case "tcp:db[0]":
|
|
|
|
return &envoy_endpoint_v3.ClusterLoadAssignment{
|
|
|
|
ClusterName: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{
|
|
|
|
{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.1", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-14 22:20:27 +00:00
|
|
|
case "http2:db", "http:db":
|
2021-04-29 18:54:05 +00:00
|
|
|
return &envoy_endpoint_v3.ClusterLoadAssignment{
|
|
|
|
ClusterName: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{
|
|
|
|
{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.1", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.2", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "tcp:geo-cache":
|
|
|
|
return &envoy_endpoint_v3.ClusterLoadAssignment{
|
|
|
|
ClusterName: "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{
|
|
|
|
{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
|
|
|
xdsNewEndpointWithHealth("10.10.1.1", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
2021-08-19 00:06:41 +00:00
|
|
|
xdsNewEndpointWithHealth("10.20.1.2", 8080, envoy_core_v3.HealthStatus_HEALTHY, 1),
|
2021-04-29 18:54:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected fixture name: %s", fixtureName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestListener(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName string) *envoy_listener_v3.Listener {
|
|
|
|
switch fixtureName {
|
2022-02-10 22:37:36 +00:00
|
|
|
case "tcp:bad_public_listener":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
// Envoy can't bind to port 1
|
|
|
|
Name: "public_listener:0.0.0.0:1",
|
|
|
|
Address: makeAddress("0.0.0.0", 1),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_INBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
TransportSocket: xdsNewPublicTransportSocket(t, snap),
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.rbac", &envoy_network_rbac_v3.RBAC{
|
|
|
|
Rules: &envoy_rbac_v3.RBAC{},
|
|
|
|
StatPrefix: "connect_authz",
|
|
|
|
}),
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.tcp_proxy", &envoy_tcp_proxy_v3.TcpProxy{
|
|
|
|
ClusterSpecifier: &envoy_tcp_proxy_v3.TcpProxy_Cluster{
|
|
|
|
Cluster: "local_app",
|
|
|
|
},
|
|
|
|
StatPrefix: "public_listener",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
case "tcp:public_listener":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "public_listener:0.0.0.0:9999",
|
|
|
|
Address: makeAddress("0.0.0.0", 9999),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_INBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
TransportSocket: xdsNewPublicTransportSocket(t, snap),
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.rbac", &envoy_network_rbac_v3.RBAC{
|
|
|
|
Rules: &envoy_rbac_v3.RBAC{},
|
|
|
|
StatPrefix: "connect_authz",
|
|
|
|
}),
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.tcp_proxy", &envoy_tcp_proxy_v3.TcpProxy{
|
|
|
|
ClusterSpecifier: &envoy_tcp_proxy_v3.TcpProxy_Cluster{
|
|
|
|
Cluster: "local_app",
|
|
|
|
},
|
|
|
|
StatPrefix: "public_listener",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "tcp:db":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "db:127.0.0.1:9191",
|
|
|
|
Address: makeAddress("127.0.0.1", 9191),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_OUTBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.tcp_proxy", &envoy_tcp_proxy_v3.TcpProxy{
|
|
|
|
ClusterSpecifier: &envoy_tcp_proxy_v3.TcpProxy_Cluster{
|
|
|
|
Cluster: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
},
|
2021-09-07 20:29:32 +00:00
|
|
|
StatPrefix: "upstream.db.default.default.dc1",
|
2021-04-29 18:54:05 +00:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "http2:db":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "db:127.0.0.1:9191",
|
|
|
|
Address: makeAddress("127.0.0.1", 9191),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_OUTBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.http_connection_manager", &envoy_http_v3.HttpConnectionManager{
|
|
|
|
HttpFilters: []*envoy_http_v3.HttpFilter{
|
2022-04-18 16:36:07 +00:00
|
|
|
xdsNewHttpFilter(t, "envoy.filters.http.router", &envoy_http_router_v3.Router{}),
|
2021-04-29 18:54:05 +00:00
|
|
|
},
|
|
|
|
RouteSpecifier: &envoy_http_v3.HttpConnectionManager_RouteConfig{
|
|
|
|
RouteConfig: makeTestRoute(t, "http2:db:inline"),
|
|
|
|
},
|
2021-09-07 20:29:32 +00:00
|
|
|
StatPrefix: "upstream.db.default.default.dc1",
|
2021-04-29 18:54:05 +00:00
|
|
|
Tracing: &envoy_http_v3.HttpConnectionManager_Tracing{
|
|
|
|
RandomSampling: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
|
|
|
Http2ProtocolOptions: &envoy_core_v3.Http2ProtocolOptions{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "http2:db:rds":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "db:127.0.0.1:9191",
|
|
|
|
Address: makeAddress("127.0.0.1", 9191),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_OUTBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.http_connection_manager", &envoy_http_v3.HttpConnectionManager{
|
|
|
|
HttpFilters: []*envoy_http_v3.HttpFilter{
|
2022-04-18 16:36:07 +00:00
|
|
|
xdsNewHttpFilter(t, "envoy.filters.http.router", &envoy_http_router_v3.Router{}),
|
2021-04-29 18:54:05 +00:00
|
|
|
},
|
|
|
|
RouteSpecifier: &envoy_http_v3.HttpConnectionManager_Rds{
|
|
|
|
Rds: &envoy_http_v3.Rds{
|
|
|
|
RouteConfigName: "db",
|
|
|
|
ConfigSource: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
},
|
2021-09-07 20:29:32 +00:00
|
|
|
StatPrefix: "upstream.db.default.default.dc1",
|
2021-04-29 18:54:05 +00:00
|
|
|
Tracing: &envoy_http_v3.HttpConnectionManager_Tracing{
|
|
|
|
RandomSampling: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
|
|
|
Http2ProtocolOptions: &envoy_core_v3.Http2ProtocolOptions{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-14 22:20:27 +00:00
|
|
|
case "http:db:rds":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "db:127.0.0.1:9191",
|
|
|
|
Address: makeAddress("127.0.0.1", 9191),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_OUTBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.http_connection_manager", &envoy_http_v3.HttpConnectionManager{
|
|
|
|
HttpFilters: []*envoy_http_v3.HttpFilter{
|
2022-04-18 16:36:07 +00:00
|
|
|
xdsNewHttpFilter(t, "envoy.filters.http.router", &envoy_http_router_v3.Router{}),
|
2021-06-14 22:20:27 +00:00
|
|
|
},
|
|
|
|
RouteSpecifier: &envoy_http_v3.HttpConnectionManager_Rds{
|
|
|
|
Rds: &envoy_http_v3.Rds{
|
|
|
|
RouteConfigName: "db",
|
|
|
|
ConfigSource: xdsNewADSConfig(),
|
|
|
|
},
|
|
|
|
},
|
2021-09-07 20:29:32 +00:00
|
|
|
StatPrefix: "upstream.db.default.default.dc1",
|
2021-06-14 22:20:27 +00:00
|
|
|
Tracing: &envoy_http_v3.HttpConnectionManager_Tracing{
|
|
|
|
RandomSampling: &envoy_type_v3.Percent{Value: 0},
|
|
|
|
},
|
|
|
|
// HttpProtocolOptions: &envoy_core_v3.Http1ProtocolOptions{},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-04-29 18:54:05 +00:00
|
|
|
case "tcp:geo-cache":
|
|
|
|
return &envoy_listener_v3.Listener{
|
|
|
|
Name: "prepared_query:geo-cache:127.10.10.10:8181",
|
|
|
|
Address: makeAddress("127.10.10.10", 8181),
|
|
|
|
TrafficDirection: envoy_core_v3.TrafficDirection_OUTBOUND,
|
|
|
|
FilterChains: []*envoy_listener_v3.FilterChain{
|
|
|
|
{
|
|
|
|
Filters: []*envoy_listener_v3.Filter{
|
|
|
|
xdsNewFilter(t, "envoy.filters.network.tcp_proxy", &envoy_tcp_proxy_v3.TcpProxy{
|
|
|
|
ClusterSpecifier: &envoy_tcp_proxy_v3.TcpProxy_Cluster{
|
|
|
|
Cluster: "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
},
|
|
|
|
StatPrefix: "upstream.prepared_query_geo-cache",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected fixture name: %s", fixtureName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestRoute(t *testing.T, fixtureName string) *envoy_route_v3.RouteConfiguration {
|
|
|
|
switch fixtureName {
|
2021-06-14 22:20:27 +00:00
|
|
|
case "http2:db", "http:db":
|
2021-04-29 18:54:05 +00:00
|
|
|
return &envoy_route_v3.RouteConfiguration{
|
|
|
|
Name: "db",
|
|
|
|
ValidateClusters: makeBoolValue(true),
|
|
|
|
VirtualHosts: []*envoy_route_v3.VirtualHost{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Domains: []string{"*"},
|
|
|
|
Routes: []*envoy_route_v3.Route{
|
|
|
|
{
|
|
|
|
Match: &envoy_route_v3.RouteMatch{
|
|
|
|
PathSpecifier: &envoy_route_v3.RouteMatch_Prefix{
|
|
|
|
Prefix: "/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: &envoy_route_v3.Route_Route{
|
|
|
|
Route: &envoy_route_v3.RouteAction{
|
|
|
|
ClusterSpecifier: &envoy_route_v3.RouteAction_Cluster{
|
|
|
|
Cluster: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "http2:db:inline":
|
|
|
|
return &envoy_route_v3.RouteConfiguration{
|
|
|
|
Name: "db",
|
|
|
|
VirtualHosts: []*envoy_route_v3.VirtualHost{
|
|
|
|
{
|
2021-09-07 20:29:32 +00:00
|
|
|
Name: "db.default.default.dc1",
|
2021-04-29 18:54:05 +00:00
|
|
|
Domains: []string{"*"},
|
|
|
|
Routes: []*envoy_route_v3.Route{
|
|
|
|
{
|
|
|
|
Match: &envoy_route_v3.RouteMatch{
|
|
|
|
PathSpecifier: &envoy_route_v3.RouteMatch_Prefix{
|
|
|
|
Prefix: "/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: &envoy_route_v3.Route_Route{
|
|
|
|
Route: &envoy_route_v3.RouteAction{
|
|
|
|
ClusterSpecifier: &envoy_route_v3.RouteAction_Cluster{
|
|
|
|
Cluster: "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected fixture name: %s", fixtureName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:59:13 +00:00
|
|
|
func requireProtocolVersionGauge(
|
|
|
|
t *testing.T,
|
|
|
|
scenario *testServerScenario,
|
|
|
|
xdsVersion string,
|
|
|
|
expected int,
|
|
|
|
) {
|
|
|
|
data := scenario.sink.Data()
|
|
|
|
require.Len(t, data, 1)
|
|
|
|
|
|
|
|
item := data[0]
|
2023-01-16 17:31:56 +00:00
|
|
|
require.Len(t, item.Gauges, 2)
|
2021-05-14 18:59:13 +00:00
|
|
|
|
|
|
|
val, ok := item.Gauges["consul.xds.test.xds.server.streams;version="+xdsVersion]
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
require.Equal(t, "consul.xds.test.xds.server.streams", val.Name)
|
|
|
|
require.Equal(t, expected, int(val.Value))
|
|
|
|
require.Equal(t, []metrics.Label{{Name: "version", Value: xdsVersion}}, val.Labels)
|
|
|
|
}
|