-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect: Fix Envoy getting stuck during load (#5499)
* Connect: Fix Envoy getting stuck during load Also in this PR: - Enabled outlier detection on upstreams which will mark instances unhealthy after 5 failures (using Envoy's defaults) - Enable weighted load balancing where DNS weights are configured * Fix empty load assignments in the right place * Fix import names from review * Move millisecond parse to a helper function
- Loading branch information
Showing
8 changed files
with
357 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package xds | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" | ||
envoyauth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth" | ||
"github.com/envoyproxy/go-control-plane/envoy/api/v2/cluster" | ||
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/hashicorp/consul/agent/proxycfg" | ||
"github.com/hashicorp/consul/agent/structs" | ||
) | ||
|
||
func Test_makeUpstreamCluster(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
snap proxycfg.ConfigSnapshot | ||
upstream structs.Upstream | ||
want *envoy.Cluster | ||
}{ | ||
{ | ||
name: "timeout override", | ||
snap: proxycfg.ConfigSnapshot{}, | ||
upstream: structs.TestUpstreams(t)[0], | ||
want: &envoy.Cluster{ | ||
Name: "service:db", | ||
Type: envoy.Cluster_EDS, | ||
EdsClusterConfig: &envoy.Cluster_EdsClusterConfig{ | ||
EdsConfig: &envoycore.ConfigSource{ | ||
ConfigSourceSpecifier: &envoycore.ConfigSource_Ads{ | ||
Ads: &envoycore.AggregatedConfigSource{}, | ||
}, | ||
}, | ||
}, | ||
ConnectTimeout: 1 * time.Second, // TestUpstreams overrides to 1000ms | ||
OutlierDetection: &cluster.OutlierDetection{}, | ||
TlsContext: &envoyauth.UpstreamTlsContext{ | ||
CommonTlsContext: makeCommonTLSContext(&proxycfg.ConfigSnapshot{}), | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "timeout default", | ||
snap: proxycfg.ConfigSnapshot{}, | ||
upstream: structs.TestUpstreams(t)[1], | ||
want: &envoy.Cluster{ | ||
Name: "prepared_query:geo-cache", | ||
Type: envoy.Cluster_EDS, | ||
EdsClusterConfig: &envoy.Cluster_EdsClusterConfig{ | ||
EdsConfig: &envoycore.ConfigSource{ | ||
ConfigSourceSpecifier: &envoycore.ConfigSource_Ads{ | ||
Ads: &envoycore.AggregatedConfigSource{}, | ||
}, | ||
}, | ||
}, | ||
ConnectTimeout: 5 * time.Second, // Default | ||
OutlierDetection: &cluster.OutlierDetection{}, | ||
TlsContext: &envoyauth.UpstreamTlsContext{ | ||
CommonTlsContext: makeCommonTLSContext(&proxycfg.ConfigSnapshot{}), | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require := require.New(t) | ||
got, err := makeUpstreamCluster(tt.upstream, &tt.snap) | ||
require.NoError(err) | ||
|
||
require.Equal(tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package xds | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mitchellh/copystructure" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" | ||
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint" | ||
"github.com/hashicorp/consul/agent/structs" | ||
) | ||
|
||
func Test_makeLoadAssignment(t *testing.T) { | ||
|
||
testCheckServiceNodes := structs.CheckServiceNodes{ | ||
structs.CheckServiceNode{ | ||
Node: &structs.Node{ | ||
ID: "node1-id", | ||
Node: "node1", | ||
Address: "10.10.10.10", | ||
Datacenter: "dc1", | ||
}, | ||
Service: &structs.NodeService{ | ||
Service: "web", | ||
Port: 1234, | ||
}, | ||
Checks: structs.HealthChecks{ | ||
&structs.HealthCheck{ | ||
Node: "node1", | ||
CheckID: "serfHealth", | ||
Status: "passing", | ||
}, | ||
&structs.HealthCheck{ | ||
Node: "node1", | ||
ServiceID: "web", | ||
CheckID: "web:check", | ||
Status: "passing", | ||
}, | ||
}, | ||
}, | ||
structs.CheckServiceNode{ | ||
Node: &structs.Node{ | ||
ID: "node2-id", | ||
Node: "node2", | ||
Address: "10.10.10.20", | ||
Datacenter: "dc1", | ||
}, | ||
Service: &structs.NodeService{ | ||
Service: "web", | ||
Port: 1234, | ||
}, | ||
Checks: structs.HealthChecks{ | ||
&structs.HealthCheck{ | ||
Node: "node2", | ||
CheckID: "serfHealth", | ||
Status: "passing", | ||
}, | ||
&structs.HealthCheck{ | ||
Node: "node2", | ||
ServiceID: "web", | ||
CheckID: "web:check", | ||
Status: "passing", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testWeightedCheckServiceNodesRaw, err := copystructure.Copy(testCheckServiceNodes) | ||
require.NoError(t, err) | ||
testWeightedCheckServiceNodes := testWeightedCheckServiceNodesRaw.(structs.CheckServiceNodes) | ||
|
||
testWeightedCheckServiceNodes[0].Service.Weights = &structs.Weights{ | ||
Passing: 10, | ||
Warning: 1, | ||
} | ||
testWeightedCheckServiceNodes[1].Service.Weights = &structs.Weights{ | ||
Passing: 5, | ||
Warning: 0, | ||
} | ||
|
||
testWarningCheckServiceNodesRaw, err := copystructure.Copy(testWeightedCheckServiceNodes) | ||
require.NoError(t, err) | ||
testWarningCheckServiceNodes := testWarningCheckServiceNodesRaw.(structs.CheckServiceNodes) | ||
|
||
testWarningCheckServiceNodes[0].Checks[0].Status = "warning" | ||
testWarningCheckServiceNodes[1].Checks[0].Status = "warning" | ||
|
||
tests := []struct { | ||
name string | ||
clusterName string | ||
endpoints structs.CheckServiceNodes | ||
want *envoy.ClusterLoadAssignment | ||
}{ | ||
{ | ||
name: "no instances", | ||
clusterName: "service:test", | ||
endpoints: structs.CheckServiceNodes{}, | ||
want: &envoy.ClusterLoadAssignment{ | ||
ClusterName: "service:test", | ||
Endpoints: []envoyendpoint.LocalityLbEndpoints{{ | ||
LbEndpoints: []envoyendpoint.LbEndpoint{}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
name: "instances, no weights", | ||
clusterName: "service:test", | ||
endpoints: testCheckServiceNodes, | ||
want: &envoy.ClusterLoadAssignment{ | ||
ClusterName: "service:test", | ||
Endpoints: []envoyendpoint.LocalityLbEndpoints{{ | ||
LbEndpoints: []envoyendpoint.LbEndpoint{ | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.10", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_HEALTHY, | ||
LoadBalancingWeight: makeUint32Value(1), | ||
}, | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.20", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_HEALTHY, | ||
LoadBalancingWeight: makeUint32Value(1), | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
name: "instances, healthy weights", | ||
clusterName: "service:test", | ||
endpoints: testWeightedCheckServiceNodes, | ||
want: &envoy.ClusterLoadAssignment{ | ||
ClusterName: "service:test", | ||
Endpoints: []envoyendpoint.LocalityLbEndpoints{{ | ||
LbEndpoints: []envoyendpoint.LbEndpoint{ | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.10", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_HEALTHY, | ||
LoadBalancingWeight: makeUint32Value(10), | ||
}, | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.20", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_HEALTHY, | ||
LoadBalancingWeight: makeUint32Value(5), | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
{ | ||
name: "instances, warning weights", | ||
clusterName: "service:test", | ||
endpoints: testWarningCheckServiceNodes, | ||
want: &envoy.ClusterLoadAssignment{ | ||
ClusterName: "service:test", | ||
Endpoints: []envoyendpoint.LocalityLbEndpoints{{ | ||
LbEndpoints: []envoyendpoint.LbEndpoint{ | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.10", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_HEALTHY, | ||
LoadBalancingWeight: makeUint32Value(1), | ||
}, | ||
envoyendpoint.LbEndpoint{ | ||
Endpoint: &envoyendpoint.Endpoint{ | ||
Address: makeAddressPtr("10.10.10.20", 1234), | ||
}, | ||
HealthStatus: core.HealthStatus_UNHEALTHY, | ||
LoadBalancingWeight: makeUint32Value(1), | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := makeLoadAssignment(tt.clusterName, tt.endpoints) | ||
require.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
Oops, something went wrong.