snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / vet-proto (push) Failing after 1s
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / vet-proto (push) Failing after 1s
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
This commit is contained in:
95
internal/xds/clusterspecifier/rls/rls.go
Normal file
95
internal/xds/clusterspecifier/rls/rls.go
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2021 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Package rls implements the RLS cluster specifier plugin.
|
||||
package rls
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc/balancer"
|
||||
"google.golang.org/grpc/internal"
|
||||
rlspb "google.golang.org/grpc/internal/proto/grpc_lookup_v1"
|
||||
"google.golang.org/grpc/internal/xds/clusterspecifier"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
clusterspecifier.Register(rls{})
|
||||
}
|
||||
|
||||
type rls struct{}
|
||||
|
||||
func (rls) TypeURLs() []string {
|
||||
return []string{"type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier"}
|
||||
}
|
||||
|
||||
// lbConfigJSON is the RLS LB Policies configuration in JSON format.
|
||||
// RouteLookupConfig will be a raw JSON string from the passed in proto
|
||||
// configuration, and the other fields will be hardcoded.
|
||||
type lbConfigJSON struct {
|
||||
RouteLookupConfig json.RawMessage `json:"routeLookupConfig"`
|
||||
ChildPolicy []map[string]json.RawMessage `json:"childPolicy"`
|
||||
ChildPolicyConfigTargetFieldName string `json:"childPolicyConfigTargetFieldName"`
|
||||
}
|
||||
|
||||
func (rls) ParseClusterSpecifierConfig(cfg proto.Message) (clusterspecifier.BalancerConfig, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("rls_csp: nil configuration message provided")
|
||||
}
|
||||
m, ok := cfg.(*anypb.Any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("rls_csp: error parsing config %v: unknown type %T", cfg, cfg)
|
||||
}
|
||||
rlcs := new(rlspb.RouteLookupClusterSpecifier)
|
||||
|
||||
if err := m.UnmarshalTo(rlcs); err != nil {
|
||||
return nil, fmt.Errorf("rls_csp: error parsing config %v: %v", cfg, err)
|
||||
}
|
||||
rlcJSON, err := protojson.Marshal(rlcs.GetRouteLookupConfig())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("rls_csp: error marshaling route lookup config: %v: %v", rlcs.GetRouteLookupConfig(), err)
|
||||
}
|
||||
lbCfgJSON := &lbConfigJSON{
|
||||
RouteLookupConfig: rlcJSON, // "JSON form of RouteLookupClusterSpecifier.config" - RLS in xDS Design Doc
|
||||
ChildPolicy: []map[string]json.RawMessage{
|
||||
{
|
||||
"cds_experimental": json.RawMessage(`{"isDynamic":true}`),
|
||||
},
|
||||
},
|
||||
ChildPolicyConfigTargetFieldName: "cluster",
|
||||
}
|
||||
|
||||
rawJSON, err := json.Marshal(lbCfgJSON)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("rls_csp: error marshaling load balancing config %v: %v", lbCfgJSON, err)
|
||||
}
|
||||
|
||||
rlsBB := balancer.Get(internal.RLSLoadBalancingPolicyName)
|
||||
if rlsBB == nil {
|
||||
return nil, fmt.Errorf("RLS LB policy not registered")
|
||||
}
|
||||
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{{internal.RLSLoadBalancingPolicyName: lbCfgJSON}}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user