mirror of https://github.com/grpc/grpc-go.git
cdsbalancer: test cleanup part 1/N (#6546)
This commit is contained in:
parent
33f9fa2e6e
commit
b07bf5d036
|
@ -460,6 +460,9 @@ type ClusterOptions struct {
|
|||
Policy LoadBalancingPolicy
|
||||
// SecurityLevel determines the security configuration for the Cluster.
|
||||
SecurityLevel SecurityLevel
|
||||
// EnableLRS adds a load reporting configuration with a config source
|
||||
// pointing to self.
|
||||
EnableLRS bool
|
||||
}
|
||||
|
||||
// ClusterResourceWithOptions returns an xDS Cluster resource configured with
|
||||
|
@ -521,6 +524,13 @@ func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster {
|
|||
},
|
||||
}
|
||||
}
|
||||
if opts.EnableLRS {
|
||||
cluster.LrsServer = &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
}
|
||||
}
|
||||
return cluster
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,11 @@ import (
|
|||
// NewBuilderWithScheme creates a new test resolver builder with the given scheme.
|
||||
func NewBuilderWithScheme(scheme string) *Resolver {
|
||||
return &Resolver{
|
||||
BuildCallback: func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) {},
|
||||
ResolveNowCallback: func(resolver.ResolveNowOptions) {},
|
||||
CloseCallback: func() {},
|
||||
scheme: scheme,
|
||||
BuildCallback: func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) {},
|
||||
UpdateStateCallback: func(error) {},
|
||||
ResolveNowCallback: func(resolver.ResolveNowOptions) {},
|
||||
CloseCallback: func() {},
|
||||
scheme: scheme,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +43,11 @@ type Resolver struct {
|
|||
// BuildCallback is called when the Build method is called. Must not be
|
||||
// nil. Must not be changed after the resolver may be built.
|
||||
BuildCallback func(resolver.Target, resolver.ClientConn, resolver.BuildOptions)
|
||||
// UpdateStateCallback is called when the UpdateState method is called on
|
||||
// the resolver. The value passed as argument to this callback is the value
|
||||
// returned by the resolver.ClientConn. Must not be nil. Must not be
|
||||
// changed after the resolver may be built.
|
||||
UpdateStateCallback func(err error)
|
||||
// ResolveNowCallback is called when the ResolveNow method is called on the
|
||||
// resolver. Must not be nil. Must not be changed after the resolver may
|
||||
// be built.
|
||||
|
@ -93,8 +99,9 @@ func (r *Resolver) Close() {
|
|||
// UpdateState calls CC.UpdateState.
|
||||
func (r *Resolver) UpdateState(s resolver.State) {
|
||||
r.mu.Lock()
|
||||
r.CC.UpdateState(s)
|
||||
err := r.CC.UpdateState(s)
|
||||
r.mu.Unlock()
|
||||
r.UpdateStateCallback(err)
|
||||
}
|
||||
|
||||
// ReportError calls CC.ReportError.
|
||||
|
|
|
@ -381,7 +381,7 @@ func (b *cdsBalancer) handleWatchUpdate(update clusterHandlerUpdate) {
|
|||
|
||||
var sc serviceconfig.LoadBalancingConfig
|
||||
if sc, err = b.crParser.ParseConfig(crLBCfgJSON); err != nil {
|
||||
b.logger.Errorf("cds_balancer: cluster_resolver config generated %v is invalid: %v", crLBCfgJSON, err)
|
||||
b.logger.Errorf("cds_balancer: cluster_resolver config generated %v is invalid: %v", string(crLBCfgJSON), err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -588,24 +588,11 @@ func (s) TestHandleClusterResponseFromManagementServer(t *testing.T) {
|
|||
resourceName1 = "resource-name-1"
|
||||
resourceName2 = "resource-name-2"
|
||||
)
|
||||
resource1 := &v3clusterpb.Cluster{
|
||||
Name: resourceName1,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
ServiceName: "eds-service-name",
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
|
||||
LrsServer: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
},
|
||||
}
|
||||
resource1 := e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
|
||||
ClusterName: resourceName1,
|
||||
ServiceName: "eds-service-name",
|
||||
EnableLRS: true,
|
||||
})
|
||||
resource2 := proto.Clone(resource1).(*v3clusterpb.Cluster)
|
||||
resource2.Name = resourceName2
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"google.golang.org/grpc/internal/grpctest"
|
||||
iserviceconfig "google.golang.org/grpc/internal/serviceconfig"
|
||||
"google.golang.org/grpc/internal/testutils"
|
||||
"google.golang.org/grpc/internal/testutils/xds/e2e"
|
||||
"google.golang.org/grpc/serviceconfig"
|
||||
_ "google.golang.org/grpc/xds" // Register the xDS LB Registry Converters.
|
||||
"google.golang.org/grpc/xds/internal/balancer/ringhash"
|
||||
|
@ -182,19 +183,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "happy-case-no-service-name-no-lrs",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
|
||||
},
|
||||
name: "happy-case-no-service-name-no-lrs",
|
||||
cluster: e2e.DefaultCluster(clusterName, "", e2e.SecurityLevelNone),
|
||||
wantUpdate: emptyUpdate,
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
|
@ -206,21 +196,12 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "happy-case-no-lrs",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
ServiceName: serviceName,
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
|
||||
name: "happy-case-no-lrs",
|
||||
cluster: e2e.DefaultCluster(clusterName, serviceName, e2e.SecurityLevelNone),
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{ClusterName: clusterName, EDSServiceName: serviceName, LRSServerConfig: xdsresource.ClusterLRSOff},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
Config: &wrrlocality.LBConfig{
|
||||
|
@ -232,25 +213,16 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "happiest-case",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
ServiceName: serviceName,
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
|
||||
LrsServer: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
},
|
||||
cluster: e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
|
||||
ClusterName: clusterName,
|
||||
ServiceName: serviceName,
|
||||
EnableLRS: true,
|
||||
}),
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
LRSServerConfig: xdsresource.ClusterLRSServerSelf,
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{ClusterName: clusterName, EDSServiceName: serviceName, LRSServerConfig: xdsresource.ClusterLRSServerSelf},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
Config: &wrrlocality.LBConfig{
|
||||
|
@ -262,19 +234,13 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "happiest-case-with-circuitbreakers",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
cluster: func() *v3clusterpb.Cluster {
|
||||
c := e2e.ClusterResourceWithOptions(e2e.ClusterOptions{
|
||||
ClusterName: clusterName,
|
||||
ServiceName: serviceName,
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_ROUND_ROBIN,
|
||||
CircuitBreakers: &v3clusterpb.CircuitBreakers{
|
||||
EnableLRS: true,
|
||||
})
|
||||
c.CircuitBreakers = &v3clusterpb.CircuitBreakers{
|
||||
Thresholds: []*v3clusterpb.CircuitBreakers_Thresholds{
|
||||
{
|
||||
Priority: v3corepb.RoutingPriority_DEFAULT,
|
||||
|
@ -285,14 +251,15 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
MaxRequests: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
LrsServer: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
},
|
||||
}
|
||||
return c
|
||||
}(),
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
LRSServerConfig: xdsresource.ClusterLRSServerSelf,
|
||||
MaxRequests: func() *uint32 { i := uint32(512); return &i }(),
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{ClusterName: clusterName, EDSServiceName: serviceName, LRSServerConfig: xdsresource.ClusterLRSServerSelf, MaxRequests: func() *uint32 { i := uint32(512); return &i }()},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
Config: &wrrlocality.LBConfig{
|
||||
|
@ -304,26 +271,14 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "happiest-case-with-ring-hash-lb-policy-with-default-config",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
ServiceName: serviceName,
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_RING_HASH,
|
||||
LrsServer: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
cluster: func() *v3clusterpb.Cluster {
|
||||
c := e2e.DefaultCluster(clusterName, serviceName, e2e.SecurityLevelNone)
|
||||
c.LbPolicy = v3clusterpb.Cluster_RING_HASH
|
||||
return c
|
||||
}(),
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName, LRSServerConfig: xdsresource.ClusterLRSServerSelf,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: "ring_hash_experimental",
|
||||
|
@ -360,32 +315,20 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "happiest-case-with-ring-hash-lb-policy-with-none-default-config",
|
||||
cluster: &v3clusterpb.Cluster{
|
||||
Name: clusterName,
|
||||
ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
|
||||
EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
|
||||
EdsConfig: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Ads{
|
||||
Ads: &v3corepb.AggregatedConfigSource{},
|
||||
},
|
||||
},
|
||||
ServiceName: serviceName,
|
||||
},
|
||||
LbPolicy: v3clusterpb.Cluster_RING_HASH,
|
||||
LbConfig: &v3clusterpb.Cluster_RingHashLbConfig_{
|
||||
cluster: func() *v3clusterpb.Cluster {
|
||||
c := e2e.DefaultCluster(clusterName, serviceName, e2e.SecurityLevelNone)
|
||||
c.LbPolicy = v3clusterpb.Cluster_RING_HASH
|
||||
c.LbConfig = &v3clusterpb.Cluster_RingHashLbConfig_{
|
||||
RingHashLbConfig: &v3clusterpb.Cluster_RingHashLbConfig{
|
||||
MinimumRingSize: wrapperspb.UInt64(10),
|
||||
MaximumRingSize: wrapperspb.UInt64(100),
|
||||
},
|
||||
},
|
||||
LrsServer: &v3corepb.ConfigSource{
|
||||
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
|
||||
Self: &v3corepb.SelfConfigSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return c
|
||||
}(),
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName, LRSServerConfig: xdsresource.ClusterLRSServerSelf,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: "ring_hash_experimental",
|
||||
|
@ -453,7 +396,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: "ring_hash_experimental",
|
||||
|
@ -487,7 +431,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
|
@ -525,7 +470,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: wrrlocality.Name,
|
||||
|
@ -572,7 +518,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: "ring_hash_experimental",
|
||||
|
@ -618,7 +565,8 @@ func (s) TestValidateCluster_Success(t *testing.T) {
|
|||
},
|
||||
},
|
||||
wantUpdate: xdsresource.ClusterUpdate{
|
||||
ClusterName: clusterName, EDSServiceName: serviceName,
|
||||
ClusterName: clusterName,
|
||||
EDSServiceName: serviceName,
|
||||
},
|
||||
wantLBConfig: &iserviceconfig.BalancerConfig{
|
||||
Name: "ring_hash_experimental",
|
||||
|
|
Loading…
Reference in New Issue