Revert EnvoyConfig nesting

pull/8585/head
freddygv 2020-09-11 09:21:43 -06:00
parent 403a180430
commit eab90ea9fa
12 changed files with 388 additions and 492 deletions

View File

@ -746,7 +746,7 @@ func (c *compiler) getSplitterNode(sid structs.ServiceID) (*structs.DiscoveryGra
// We cannot apply multiple hash policies to a splitter node's route action.
// Therefore, we attach the first hash-based load balancer config we encounter.
if !hasLB {
if lb := node.LoadBalancer; lb != nil && lb.EnvoyConfig != nil && lb.EnvoyConfig.IsHashBased() {
if lb := node.LoadBalancer; lb != nil && lb.IsHashBased() {
splitNode.LoadBalancer = node.LoadBalancer
hasLB = true
}

View File

@ -1763,7 +1763,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
"qa": {Filter: "ServiceMeta.env == qa"},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 100,
@ -1775,7 +1774,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
},
},
},
},
&structs.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "main",
@ -1837,7 +1835,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 100,
@ -1849,7 +1846,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
},
},
},
},
"resolver:prod.redirected.default.dc1": {
Type: structs.DiscoveryGraphNodeTypeResolver,
Name: "prod.redirected.default.dc1",
@ -1858,7 +1854,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
Target: "prod.redirected.default.dc1",
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 100,
@ -1870,7 +1865,6 @@ func testcase_AllBellsAndWhistles() compileTestCase {
},
},
},
},
"resolver:v1.main.default.dc1": {
Type: structs.DiscoveryGraphNodeTypeResolver,
Name: "v1.main.default.dc1",
@ -2283,19 +2277,16 @@ func testcase_LBSplitterAndResolver() compileTestCase {
Kind: "service-resolver",
Name: "foo",
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "least_request",
LeastRequestConfig: &structs.LeastRequestConfig{
ChoiceCount: 3,
},
},
},
},
&structs.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "bar",
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 101,
@ -2307,12 +2298,10 @@ func testcase_LBSplitterAndResolver() compileTestCase {
},
},
},
},
&structs.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "baz",
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "maglev",
HashPolicies: []structs.HashPolicy{
{
@ -2327,7 +2316,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
},
},
},
},
)
expect := &structs.CompiledDiscoveryChain{
@ -2354,7 +2342,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
// The LB config from bar is attached because splitters only care about hash-based policies,
// and it's the config from bar not baz because we pick the first one we encounter in the Splits.
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 101,
@ -2366,7 +2353,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
},
},
},
},
// Each service's LB config is passed down from the service-resolver to the resolver node
"resolver:foo.default.dc1": {
Type: structs.DiscoveryGraphNodeTypeResolver,
@ -2377,14 +2363,12 @@ func testcase_LBSplitterAndResolver() compileTestCase {
Target: "foo.default.dc1",
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "least_request",
LeastRequestConfig: &structs.LeastRequestConfig{
ChoiceCount: 3,
},
},
},
},
"resolver:bar.default.dc1": {
Type: structs.DiscoveryGraphNodeTypeResolver,
Name: "bar.default.dc1",
@ -2394,7 +2378,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
Target: "bar.default.dc1",
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 101,
@ -2406,7 +2389,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
},
},
},
},
"resolver:baz.default.dc1": {
Type: structs.DiscoveryGraphNodeTypeResolver,
Name: "baz.default.dc1",
@ -2416,7 +2398,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
Target: "baz.default.dc1",
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "maglev",
HashPolicies: []structs.HashPolicy{
{
@ -2432,7 +2413,6 @@ func testcase_LBSplitterAndResolver() compileTestCase {
},
},
},
},
Targets: map[string]*structs.DiscoveryTarget{
"foo.default.dc1": newTarget("foo", "", "default", "dc1", nil),
"bar.default.dc1": newTarget("bar", "", "default", "dc1", nil),
@ -2453,7 +2433,6 @@ func testcase_LBResolver() compileTestCase {
Kind: "service-resolver",
Name: "main",
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 101,
@ -2465,7 +2444,6 @@ func testcase_LBResolver() compileTestCase {
},
},
},
},
)
expect := &structs.CompiledDiscoveryChain{
@ -2481,7 +2459,6 @@ func testcase_LBResolver() compileTestCase {
Target: "main.default.dc1",
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MaximumRingSize: 101,
@ -2494,7 +2471,6 @@ func testcase_LBResolver() compileTestCase {
},
},
},
},
Targets: map[string]*structs.DiscoveryTarget{
"main.default.dc1": newTarget("main", "", "default", "dc1", nil),
},

View File

@ -1275,7 +1275,6 @@ func setupTestVariationConfigEntriesAndSnapshot(
Kind: structs.ServiceResolver,
Name: "db",
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
@ -1298,7 +1297,6 @@ func setupTestVariationConfigEntriesAndSnapshot(
},
},
},
},
)
case "http-multiple-services":
default:

View File

@ -843,27 +843,27 @@ func (e *ServiceResolverConfigEntry) Validate() error {
return fmt.Errorf("Bad ConnectTimeout '%s', must be >= 0", e.ConnectTimeout)
}
if e.LoadBalancer != nil && e.LoadBalancer.EnvoyConfig != nil {
ec := e.LoadBalancer.EnvoyConfig
if e.LoadBalancer != nil {
lb := e.LoadBalancer
if ok := validLBPolicies[ec.Policy]; !ok {
return fmt.Errorf("Bad LoadBalancer policy: %q is not supported", ec.Policy)
if ok := validLBPolicies[lb.Policy]; !ok {
return fmt.Errorf("Bad LoadBalancer policy: %q is not supported", lb.Policy)
}
if ec.Policy != LBPolicyRingHash && ec.RingHashConfig != nil {
if lb.Policy != LBPolicyRingHash && lb.RingHashConfig != nil {
return fmt.Errorf("Bad LoadBalancer configuration. "+
"RingHashConfig specified for incompatible load balancing policy %q", ec.Policy)
"RingHashConfig specified for incompatible load balancing policy %q", lb.Policy)
}
if ec.Policy != LBPolicyLeastRequest && ec.LeastRequestConfig != nil {
if lb.Policy != LBPolicyLeastRequest && lb.LeastRequestConfig != nil {
return fmt.Errorf("Bad LoadBalancer configuration. "+
"LeastRequestConfig specified for incompatible load balancing policy %q", ec.Policy)
"LeastRequestConfig specified for incompatible load balancing policy %q", lb.Policy)
}
if !ec.IsHashBased() && len(ec.HashPolicies) > 0 {
if !lb.IsHashBased() && len(lb.HashPolicies) > 0 {
return fmt.Errorf("Bad LoadBalancer configuration: "+
"HashPolicies specified for non-hash-based Policy: %q", ec.Policy)
"HashPolicies specified for non-hash-based Policy: %q", lb.Policy)
}
for i, hp := range ec.HashPolicies {
for i, hp := range lb.HashPolicies {
if ok := validHashPolicies[hp.Field]; hp.Field != "" && !ok {
return fmt.Errorf("Bad LoadBalancer HashPolicy[%d]: %q is not a supported field", i, hp.Field)
}
@ -1027,14 +1027,6 @@ type ServiceResolverFailover struct {
// LoadBalancer determines the load balancing policy and configuration for services
// issuing requests to this upstream service.
type LoadBalancer struct {
// EnvoyConfig contains Envoy-specific load balancing configuration for this upstream
EnvoyConfig *EnvoyLBConfig `json:",omitempty" alias:"envoy_config"`
// OpaqueConfig contains load balancing configuration opaque to Consul for 3rd party proxies
OpaqueConfig string `json:",omitempty" alias:"opaque_config"`
}
type EnvoyLBConfig struct {
// Policy is the load balancing policy used to select a host
Policy string `json:",omitempty"`
@ -1102,12 +1094,12 @@ type CookieConfig struct {
Path string `json:",omitempty"`
}
func (ec *EnvoyLBConfig) IsHashBased() bool {
if ec == nil {
func (lb *LoadBalancer) IsHashBased() bool {
if lb == nil {
return false
}
switch ec.Policy {
switch lb.Policy {
case LBPolicyMaglev, LBPolicyRingHash:
return true
default:

View File

@ -555,7 +555,7 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{Policy: ""},
Policy: "",
},
},
},
@ -565,7 +565,7 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{Policy: LBPolicyRandom},
Policy: LBPolicyRandom,
},
},
},
@ -575,7 +575,7 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{Policy: "fake-policy"},
Policy: "fake-policy",
},
},
validateErr: `"fake-policy" is not supported`,
@ -586,12 +586,10 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyRingHash,
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 10},
},
},
},
validateErr: `LeastRequestConfig specified for incompatible load balancing policy`,
},
{
@ -600,12 +598,10 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyLeastRequest,
RingHashConfig: &RingHashConfig{MinimumRingSize: 1024},
},
},
},
validateErr: `RingHashConfig specified for incompatible load balancing policy`,
},
{
@ -614,37 +610,33 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyRingHash,
RingHashConfig: &RingHashConfig{MinimumRingSize: 1024},
},
},
},
},
{
name: "good policy for least request config",
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyLeastRequest,
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 2},
},
},
},
},
{
name: "empty policy is not defaulted",
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{Policy: ""},
Policy: "",
},
},
check: func(t *testing.T, entry *ServiceResolverConfigEntry) {
require.Equal(t, "", entry.LoadBalancer.EnvoyConfig.Policy)
require.Equal(t, "", entry.LoadBalancer.Policy)
},
},
{
@ -653,7 +645,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: "",
HashPolicies: []HashPolicy{
{
@ -662,7 +653,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `HashPolicies specified for non-hash-based Policy`,
},
{
@ -671,7 +661,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -685,7 +674,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `cookie_config provided for "header"`,
},
{
@ -694,7 +682,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -709,14 +696,12 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
{
name: "supported match field",
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -727,14 +712,12 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
{
name: "unsupported match field",
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -743,7 +726,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `"fake-field" is not a supported field`,
},
{
@ -752,7 +734,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -762,7 +743,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `A single hash policy cannot hash both a source address and a "header"`,
},
{
@ -771,7 +751,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -781,7 +760,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `A FieldValue cannot be specified when hashing SourceIP`,
},
{
@ -790,7 +768,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -799,7 +776,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `Field "header" was specified without a FieldValue`,
},
{
@ -808,7 +784,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyMaglev,
HashPolicies: []HashPolicy{
{
@ -817,7 +792,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
validateErr: `FieldValue requires a Field to apply to`,
},
{
@ -826,7 +800,6 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyRingHash,
RingHashConfig: &RingHashConfig{MaximumRingSize: 10, MinimumRingSize: 2},
HashPolicies: []HashPolicy{
@ -843,20 +816,17 @@ func TestServiceResolverConfigEntry_LoadBalancer(t *testing.T) {
},
},
},
},
{
name: "least request kitchen sink",
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test",
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: LBPolicyLeastRequest,
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 20},
},
},
},
},
}
for _, tc := range cases {

View File

@ -206,14 +206,14 @@ func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([
clusterName := connect.ServiceSNI(svc.Name, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
resolver, hasResolver := resolvers[svc]
var loadBalancer *structs.EnvoyLBConfig
var loadBalancer *structs.LoadBalancer
if !hasResolver {
// Use a zero value resolver with no timeout and no subsets
resolver = &structs.ServiceResolverConfigEntry{}
}
if resolver.LoadBalancer != nil {
loadBalancer = resolver.LoadBalancer.EnvoyConfig
loadBalancer = resolver.LoadBalancer
}
// When making service clusters we only pass endpoints with hostnames if the kind is a terminating gateway
@ -514,9 +514,9 @@ func (s *Server) makeUpstreamClustersForDiscoveryChain(
OutlierDetection: cfg.PassiveHealthCheck.AsOutlierDetection(),
}
var lb *structs.EnvoyLBConfig
var lb *structs.LoadBalancer
if node.LoadBalancer != nil {
lb = node.LoadBalancer.EnvoyConfig
lb = node.LoadBalancer
}
if err := injectLBToCluster(lb, c); err != nil {
return nil, fmt.Errorf("failed to apply load balancer configuration to cluster %q: %v", clusterName, err)
@ -595,7 +595,7 @@ func makeClusterFromUserConfig(configJSON string) (*envoy.Cluster, error) {
return &c, err
}
// No @type so try decoding as a straight listener.
// No @type so try decoding as a straight cluster.
err := jsonpb.UnmarshalString(configJSON, &c)
return &c, err
}
@ -783,7 +783,7 @@ func makeLbEndpoint(addr string, port int, health envoycore.HealthStatus, weight
}
}
func injectLBToCluster(ec *structs.EnvoyLBConfig, c *envoy.Cluster) error {
func injectLBToCluster(ec *structs.LoadBalancer, c *envoy.Cluster) error {
if ec == nil {
return nil
}

View File

@ -368,14 +368,12 @@ func TestClustersFromSnapshot(t *testing.T) {
},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "least_request",
LeastRequestConfig: &structs.LeastRequestConfig{
ChoiceCount: 5,
},
},
},
},
}
},
},
@ -397,7 +395,6 @@ func TestClustersFromSnapshot(t *testing.T) {
},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
@ -405,7 +402,6 @@ func TestClustersFromSnapshot(t *testing.T) {
},
},
},
},
}
},
},
@ -625,7 +621,6 @@ func TestClustersFromSnapshot(t *testing.T) {
},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
@ -633,7 +628,6 @@ func TestClustersFromSnapshot(t *testing.T) {
},
},
},
},
}
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("web", nil)] = &structs.ServiceConfigResponse{
ProxyConfig: map[string]interface{}{"protocol": "http"},
@ -862,40 +856,40 @@ func setupTLSRootsAndLeaf(t *testing.T, snap *proxycfg.ConfigSnapshot) {
func TestEnvoyLBConfig_InjectToCluster(t *testing.T) {
var tests = []struct {
name string
lb *structs.EnvoyLBConfig
lb *structs.LoadBalancer
expected envoy.Cluster
}{
{
name: "skip empty",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: "",
},
expected: envoy.Cluster{},
},
{
name: "round robin",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyRoundRobin,
},
expected: envoy.Cluster{LbPolicy: envoy.Cluster_ROUND_ROBIN},
},
{
name: "random",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyRandom,
},
expected: envoy.Cluster{LbPolicy: envoy.Cluster_RANDOM},
},
{
name: "maglev",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyMaglev,
},
expected: envoy.Cluster{LbPolicy: envoy.Cluster_MAGLEV},
},
{
name: "ring_hash",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyRingHash,
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 3,
@ -914,7 +908,7 @@ func TestEnvoyLBConfig_InjectToCluster(t *testing.T) {
},
{
name: "least_request",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: "least_request",
LeastRequestConfig: &structs.LeastRequestConfig{
ChoiceCount: 3,

View File

@ -65,9 +65,9 @@ func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap
resolver = &structs.ServiceResolverConfigEntry{}
}
var lb *structs.EnvoyLBConfig
var lb *structs.LoadBalancer
if resolver.LoadBalancer != nil {
lb = resolver.LoadBalancer.EnvoyConfig
lb = resolver.LoadBalancer
}
route, err := makeNamedDefaultRouteWithLB(clusterName, lb)
if err != nil {
@ -91,7 +91,7 @@ func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap
return resources, nil
}
func makeNamedDefaultRouteWithLB(clusterName string, lb *structs.EnvoyLBConfig) (*envoy.RouteConfiguration, error) {
func makeNamedDefaultRouteWithLB(clusterName string, lb *structs.LoadBalancer) (*envoy.RouteConfiguration, error) {
action := makeRouteActionFromName(clusterName)
if err := injectLBToRouteAction(lb, action.Route); err != nil {
@ -262,7 +262,7 @@ func makeUpstreamRouteForDiscoveryChain(
return nil, fmt.Errorf("missing first node in compiled discovery chain for: %s", chain.ServiceName)
}
var lb *structs.EnvoyLBConfig
var lb *structs.LoadBalancer
switch startNode.Type {
case structs.DiscoveryGraphNodeTypeRouter:
@ -278,7 +278,7 @@ func makeUpstreamRouteForDiscoveryChain(
nextNode := chain.Nodes[discoveryRoute.NextNode]
if nextNode.LoadBalancer != nil {
lb = nextNode.LoadBalancer.EnvoyConfig
lb = nextNode.LoadBalancer
}
switch nextNode.Type {
@ -351,7 +351,7 @@ func makeUpstreamRouteForDiscoveryChain(
}
if startNode.LoadBalancer != nil {
lb = startNode.LoadBalancer.EnvoyConfig
lb = startNode.LoadBalancer
}
if err := injectLBToRouteAction(lb, routeAction.Route); err != nil {
return nil, fmt.Errorf("failed to apply load balancer configuration to route action: %v", err)
@ -368,7 +368,7 @@ func makeUpstreamRouteForDiscoveryChain(
routeAction := makeRouteActionForChainCluster(startNode.Resolver.Target, chain)
if startNode.LoadBalancer != nil {
lb = startNode.LoadBalancer.EnvoyConfig
lb = startNode.LoadBalancer
}
if err := injectLBToRouteAction(lb, routeAction.Route); err != nil {
return nil, fmt.Errorf("failed to apply load balancer configuration to route action: %v", err)
@ -577,13 +577,13 @@ func makeRouteActionForSplitter(splits []*structs.DiscoverySplit, chain *structs
}, nil
}
func injectLBToRouteAction(ec *structs.EnvoyLBConfig, action *envoyroute.RouteAction) error {
if ec == nil || !ec.IsHashBased() {
func injectLBToRouteAction(lb *structs.LoadBalancer, action *envoyroute.RouteAction) error {
if lb == nil || !lb.IsHashBased() {
return nil
}
result := make([]*envoyroute.RouteAction_HashPolicy, 0, len(ec.HashPolicies))
for _, policy := range ec.HashPolicies {
result := make([]*envoyroute.RouteAction_HashPolicy, 0, len(lb.HashPolicies))
for _, policy := range lb.HashPolicies {
if policy.SourceIP {
result = append(result, &envoyroute.RouteAction_HashPolicy{
PolicySpecifier: &envoyroute.RouteAction_HashPolicy_ConnectionProperties_{

View File

@ -206,7 +206,6 @@ func TestRoutesFromSnapshot(t *testing.T) {
},
},
LoadBalancer: &structs.LoadBalancer{
EnvoyConfig: &structs.EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 20,
@ -229,7 +228,6 @@ func TestRoutesFromSnapshot(t *testing.T) {
},
},
},
},
}
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("web", nil)] = &structs.ServiceConfigResponse{
ProxyConfig: map[string]interface{}{"protocol": "http"},
@ -291,12 +289,12 @@ func TestRoutesFromSnapshot(t *testing.T) {
func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
var tests = []struct {
name string
lb *structs.EnvoyLBConfig
lb *structs.LoadBalancer
expected envoyroute.RouteAction
}{
{
name: "empty",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: "",
},
// we only modify route actions for hash-based LB policies
@ -304,7 +302,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
},
{
name: "least request",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyLeastRequest,
LeastRequestConfig: &structs.LeastRequestConfig{
ChoiceCount: 3,
@ -315,7 +313,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
},
{
name: "headers",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: "ring_hash",
RingHashConfig: &structs.RingHashConfig{
MinimumRingSize: 3,
@ -344,7 +342,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
},
{
name: "cookies",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyMaglev,
HashPolicies: []structs.HashPolicy{
{
@ -380,7 +378,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
},
{
name: "source addr",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyMaglev,
HashPolicies: []structs.HashPolicy{
{
@ -404,7 +402,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) {
},
{
name: "kitchen sink",
lb: &structs.EnvoyLBConfig{
lb: &structs.LoadBalancer{
Policy: structs.LBPolicyMaglev,
HashPolicies: []structs.HashPolicy{
{

View File

@ -209,14 +209,6 @@ type ServiceResolverFailover struct {
// LoadBalancer determines the load balancing policy and configuration for services
// issuing requests to this upstream service.
type LoadBalancer struct {
// EnvoyConfig contains Envoy-specific load balancing configuration for this upstream
EnvoyConfig *EnvoyLBConfig `json:",omitempty" alias:"envoy_config"`
// OpaqueConfig contains load balancing configuration opaque to Consul for 3rd party proxies
OpaqueConfig string `json:",omitempty" alias:"opaque_config"`
}
type EnvoyLBConfig struct {
// Policy is the load balancing policy used to select a host
Policy string `json:",omitempty"`

View File

@ -294,12 +294,10 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
Name: "test-least-req",
Namespace: defaultNamespace,
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: "least_request",
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 10},
},
},
},
verify: verifyResolver,
},
{
@ -309,7 +307,6 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
Name: "test-ring-hash",
Namespace: defaultNamespace,
LoadBalancer: &LoadBalancer{
EnvoyConfig: &EnvoyLBConfig{
Policy: "ring_hash",
RingHashConfig: &RingHashConfig{
MinimumRingSize: 1024 * 2,
@ -335,7 +332,6 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
},
},
},
},
verify: verifyResolver,
},
} {

View File

@ -1172,7 +1172,6 @@ func TestParseConfigEntry(t *testing.T) {
kind = "service-resolver"
name = "main"
load_balancer = {
envoy_config = {
policy = "ring_hash"
ring_hash_config = {
minimum_ring_size = 1
@ -1197,13 +1196,11 @@ func TestParseConfigEntry(t *testing.T) {
}
]
}
}
`,
camel: `
Kind = "service-resolver"
Name = "main"
LoadBalancer = {
EnvoyConfig = {
Policy = "ring_hash"
RingHashConfig = {
MinimumRingSize = 1
@ -1228,14 +1225,12 @@ func TestParseConfigEntry(t *testing.T) {
}
]
}
}
`,
snakeJSON: `
{
"kind": "service-resolver",
"name": "main",
"load_balancer": {
"envoy_config": {
"policy": "ring_hash",
"ring_hash_config": {
"minimum_ring_size": 1,
@ -1261,14 +1256,12 @@ func TestParseConfigEntry(t *testing.T) {
]
}
}
}
`,
camelJSON: `
{
"Kind": "service-resolver",
"Name": "main",
"LoadBalancer": {
"EnvoyConfig": {
"Policy": "ring_hash",
"RingHashConfig": {
"MinimumRingSize": 1,
@ -1294,13 +1287,11 @@ func TestParseConfigEntry(t *testing.T) {
]
}
}
}
`,
expect: &api.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "main",
LoadBalancer: &api.LoadBalancer{
EnvoyConfig: &api.EnvoyLBConfig{
Policy: structs.LBPolicyRingHash,
RingHashConfig: &api.RingHashConfig{
MinimumRingSize: 1,
@ -1327,66 +1318,56 @@ func TestParseConfigEntry(t *testing.T) {
},
},
},
},
{
name: "service-resolver: envoy least request kitchen sink",
snake: `
kind = "service-resolver"
name = "main"
load_balancer = {
envoy_config = {
policy = "least_request"
least_request_config = {
choice_count = 2
}
}
}
`,
camel: `
Kind = "service-resolver"
Name = "main"
LoadBalancer = {
EnvoyConfig = {
Policy = "least_request"
LeastRequestConfig = {
ChoiceCount = 2
}
}
}
`,
snakeJSON: `
{
"kind": "service-resolver",
"name": "main",
"load_balancer": {
"envoy_config": {
"policy": "least_request",
"least_request_config": {
"choice_count": 2
}
}
}
}
`,
camelJSON: `
{
"Kind": "service-resolver",
"Name": "main",
"LoadBalancer": {
"EnvoyConfig": {
"Policy": "least_request",
"LeastRequestConfig": {
"ChoiceCount": 2
}
}
}
}
`,
expect: &api.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "main",
LoadBalancer: &api.LoadBalancer{
EnvoyConfig: &api.EnvoyLBConfig{
Policy: structs.LBPolicyLeastRequest,
LeastRequestConfig: &api.LeastRequestConfig{
ChoiceCount: 2,
@ -1394,7 +1375,6 @@ func TestParseConfigEntry(t *testing.T) {
},
},
},
},
{
name: "expose paths: kitchen sink proxy defaults",
snake: `