make the RLS LB policy name available in the internal package (#5259)

This commit is contained in:
Easwar Swaminathan 2022-03-21 15:47:31 -07:00 committed by GitHub
parent 50d0d0a51a
commit 4635bf287f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import (
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/backoff"
"google.golang.org/grpc/internal/balancergroup"
"google.golang.org/grpc/internal/buffer"
@ -40,7 +41,10 @@ import (
const (
// Name is the name of the RLS LB policy.
Name = "rls_experimental"
//
// It currently has an experimental suffix which would be removed once
// end-to-end testing of the policy is completed.
Name = internal.RLSLoadBalancingPolicyName
// Default frequency for data cache purging.
periodicCachePurgeFreq = time.Minute
)

View File

@ -85,3 +85,9 @@ const (
// that supports backend returned by grpclb balancer.
CredsBundleModeBackendFromBalancer = "backend-from-balancer"
)
// RLSLoadBalancingPolicyName is the name of the RLS LB policy.
//
// It currently has an experimental suffix which would be removed once
// end-to-end testing of the policy is completed.
const RLSLoadBalancingPolicyName = "rls_experimental"

View File

@ -26,14 +26,12 @@ import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/envconfig"
rlspb "google.golang.org/grpc/internal/proto/grpc_lookup_v1"
"google.golang.org/grpc/xds/internal/clusterspecifier"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/anypb"
// Never remove this import as the RLS LB policy is registered in its init().
rlslb "google.golang.org/grpc/balancer/rls"
)
func init() {
@ -89,14 +87,13 @@ func (rls) ParseClusterSpecifierConfig(cfg proto.Message) (clusterspecifier.Bala
return nil, fmt.Errorf("rls_csp: error marshaling load balancing config %v: %v", lbCfgJSON, err)
}
rlsBB := balancer.Get(rlslb.Name)
rlsBB := balancer.Get(internal.RLSLoadBalancingPolicyName)
if rlsBB == nil {
return nil, fmt.Errorf("RLS LB policy not registered")
}
_, err = rlsBB.(balancer.ConfigParser).ParseConfig(rawJSON)
if err != nil {
if _, err = rlsBB.(balancer.ConfigParser).ParseConfig(rawJSON); err != nil {
return nil, fmt.Errorf("rls_csp: validation error from rls lb policy parsing %v", err)
}
return clusterspecifier.BalancerConfig{{rlslb.Name: lbCfgJSON}}, nil
return clusterspecifier.BalancerConfig{{internal.RLSLoadBalancingPolicyName: lbCfgJSON}}, nil
}

View File

@ -25,13 +25,14 @@ import (
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
_ "google.golang.org/grpc/balancer/rls"
"google.golang.org/grpc/internal/grpctest"
rlspb "google.golang.org/grpc/internal/proto/grpc_lookup_v1"
"google.golang.org/grpc/internal/testutils"
_ "google.golang.org/grpc/xds/internal/balancer/cdsbalancer"
"google.golang.org/grpc/xds/internal/clusterspecifier"
"google.golang.org/protobuf/types/known/durationpb"
_ "google.golang.org/grpc/balancer/rls" // Register the RLS LB policy.
_ "google.golang.org/grpc/xds/internal/balancer/cdsbalancer" // Register the CDS LB policy.
)
func init() {

View File

@ -38,6 +38,7 @@ import (
_ "google.golang.org/grpc/credentials/tls/certprovider/pemfile" // Register the file watcher certificate provider plugin.
_ "google.golang.org/grpc/xds/internal/balancer" // Register the balancers.
_ "google.golang.org/grpc/xds/internal/clusterspecifier/rls" // Register the RLS cluster specifier plugin. Note that this does not register the RLS LB policy.
_ "google.golang.org/grpc/xds/internal/httpfilter/fault" // Register the fault injection filter.
_ "google.golang.org/grpc/xds/internal/httpfilter/rbac" // Register the RBAC filter.
_ "google.golang.org/grpc/xds/internal/httpfilter/router" // Register the router filter.