connect: Allow upstream listener escape hatch for prepared queries (#11109)

This commit is contained in:
Chris S. Kim 2021-09-22 15:27:10 -04:00 committed by GitHub
parent ba13416b57
commit d222f170a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 24 deletions

3
.changelog/11109.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
connect: Fix upstream listener escape hatch for prepared queries
```

View File

@ -252,6 +252,20 @@ func (s *ResourceGenerator) listenersFromSnapshotConnectProxy(cfgSnap *proxycfg.
// default config if there is an error so it's safe to continue. // default config if there is an error so it's safe to continue.
s.Logger.Warn("failed to parse", "upstream", u.Identifier(), "error", err) s.Logger.Warn("failed to parse", "upstream", u.Identifier(), "error", err)
} }
// If escape hatch is present, create a listener from it and move on to the next
if cfg.EnvoyListenerJSON != "" {
upstreamListener, err := makeListenerFromUserConfig(cfg.EnvoyListenerJSON)
if err != nil {
s.Logger.Error("failed to parse envoy_listener_json",
"upstream", u.Identifier(),
"error", err)
continue
}
resources = append(resources, upstreamListener)
continue
}
upstreamListener := makeListener(id, u, envoy_core_v3.TrafficDirection_OUTBOUND) upstreamListener := makeListener(id, u, envoy_core_v3.TrafficDirection_OUTBOUND)
filterChain, err := s.makeUpstreamFilterChainForDiscoveryChain( filterChain, err := s.makeUpstreamFilterChainForDiscoveryChain(

View File

@ -159,20 +159,30 @@ func TestListenersFromSnapshot(t *testing.T) {
name: "custom-upstream", name: "custom-upstream",
create: proxycfg.TestConfigSnapshot, create: proxycfg.TestConfigSnapshot,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.Proxy.Upstreams[0].Config["envoy_listener_json"] = for i := range snap.Proxy.Upstreams {
if snap.Proxy.Upstreams[i].Config == nil {
snap.Proxy.Upstreams[i].Config = map[string]interface{}{}
}
snap.Proxy.Upstreams[i].Config["envoy_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{ customListenerJSON(t, customListenerJSONOptions{
Name: "custom-upstream", Name: snap.Proxy.Upstreams[i].Identifier() + ":custom-upstream",
}) })
}
}, },
}, },
{ {
name: "custom-upstream-ignored-with-disco-chain", name: "custom-upstream-ignored-with-disco-chain",
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailover, create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailover,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.Proxy.Upstreams[0].Config["envoy_listener_json"] = for i := range snap.Proxy.Upstreams {
if snap.Proxy.Upstreams[i].Config == nil {
snap.Proxy.Upstreams[i].Config = map[string]interface{}{}
}
snap.Proxy.Upstreams[i].Config["envoy_listener_json"] =
customListenerJSON(t, customListenerJSONOptions{ customListenerJSON(t, customListenerJSONOptions{
Name: "custom-upstream", Name: snap.Proxy.Upstreams[i].Identifier() + ":custom-upstream",
}) })
}
}, },
}, },
{ {

View File

@ -3,7 +3,7 @@
"resources": [ "resources": [
{ {
"@type": "type.googleapis.com/envoy.config.listener.v3.Listener", "@type": "type.googleapis.com/envoy.config.listener.v3.Listener",
"name": "custom-upstream", "name": "db:custom-upstream",
"address": { "address": {
"socketAddress": { "socketAddress": {
"address": "11.11.11.11", "address": "11.11.11.11",
@ -27,11 +27,11 @@
}, },
{ {
"@type": "type.googleapis.com/envoy.config.listener.v3.Listener", "@type": "type.googleapis.com/envoy.config.listener.v3.Listener",
"name": "prepared_query:geo-cache:127.10.10.10:8181", "name": "prepared_query:geo-cache:custom-upstream",
"address": { "address": {
"socketAddress": { "socketAddress": {
"address": "127.10.10.10", "address": "11.11.11.11",
"portValue": 8181 "portValue": 11111
} }
}, },
"filterChains": [ "filterChains": [
@ -41,14 +41,13 @@
"name": "envoy.filters.network.tcp_proxy", "name": "envoy.filters.network.tcp_proxy",
"typedConfig": { "typedConfig": {
"@type": "type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy", "@type": "type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy",
"statPrefix": "upstream.prepared_query_geo-cache", "statPrefix": "foo-stats",
"cluster": "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul" "cluster": "random-cluster"
} }
} }
] ]
} }
], ]
"trafficDirection": "OUTBOUND"
}, },
{ {
"@type": "type.googleapis.com/envoy.config.listener.v3.Listener", "@type": "type.googleapis.com/envoy.config.listener.v3.Listener",

View File

@ -3,7 +3,7 @@
"resources": [ "resources": [
{ {
"@type": "type.googleapis.com/envoy.api.v2.Listener", "@type": "type.googleapis.com/envoy.api.v2.Listener",
"name": "custom-upstream", "name": "db:custom-upstream",
"address": { "address": {
"socketAddress": { "socketAddress": {
"address": "11.11.11.11", "address": "11.11.11.11",
@ -27,11 +27,11 @@
}, },
{ {
"@type": "type.googleapis.com/envoy.api.v2.Listener", "@type": "type.googleapis.com/envoy.api.v2.Listener",
"name": "prepared_query:geo-cache:127.10.10.10:8181", "name": "prepared_query:geo-cache:custom-upstream",
"address": { "address": {
"socketAddress": { "socketAddress": {
"address": "127.10.10.10", "address": "11.11.11.11",
"portValue": 8181 "portValue": 11111
} }
}, },
"filterChains": [ "filterChains": [
@ -41,14 +41,13 @@
"name": "envoy.filters.network.tcp_proxy", "name": "envoy.filters.network.tcp_proxy",
"typedConfig": { "typedConfig": {
"@type": "type.googleapis.com/envoy.config.filter.network.tcp_proxy.v2.TcpProxy", "@type": "type.googleapis.com/envoy.config.filter.network.tcp_proxy.v2.TcpProxy",
"statPrefix": "upstream.prepared_query_geo-cache", "statPrefix": "foo-stats",
"cluster": "geo-cache.default.dc1.query.11111111-2222-3333-4444-555555555555.consul" "cluster": "random-cluster"
} }
} }
] ]
} }
], ]
"trafficDirection": "OUTBOUND"
}, },
{ {
"@type": "type.googleapis.com/envoy.api.v2.Listener", "@type": "type.googleapis.com/envoy.api.v2.Listener",