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
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
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
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (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
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
Stale bot / stale (push) Failing after 1s
This commit is contained in:
82
internal/xds/xdsclient/xdslbregistry/xdslbregistry.go
Normal file
82
internal/xds/xdsclient/xdslbregistry/xdslbregistry.go
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2023 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 xdslbregistry provides a registry of converters that convert proto
|
||||
// from load balancing configuration, defined by the xDS API spec, to JSON load
|
||||
// balancing configuration.
|
||||
package xdslbregistry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
v3clusterpb "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
// m is a map from proto type to Converter.
|
||||
m = make(map[string]Converter)
|
||||
)
|
||||
|
||||
// Register registers the converter to the map keyed on a proto type. Must be
|
||||
// called at init time. Not thread safe.
|
||||
func Register(protoType string, c Converter) {
|
||||
m[protoType] = c
|
||||
}
|
||||
|
||||
// SetRegistry sets the xDS LB registry. Must be called at init time. Not thread
|
||||
// safe.
|
||||
func SetRegistry(registry map[string]Converter) {
|
||||
m = registry
|
||||
}
|
||||
|
||||
// Converter converts raw proto bytes into the internal Go JSON representation
|
||||
// of the proto passed. Returns the json message, and an error. If both
|
||||
// returned are nil, it represents continuing to the next proto.
|
||||
type Converter func([]byte, int) (json.RawMessage, error)
|
||||
|
||||
// ConvertToServiceConfig converts a proto Load Balancing Policy configuration
|
||||
// into a json string. Returns an error if:
|
||||
// - no supported policy found
|
||||
// - there is more than 16 layers of recursion in the configuration
|
||||
// - a failure occurs when converting the policy
|
||||
func ConvertToServiceConfig(lbPolicy *v3clusterpb.LoadBalancingPolicy, depth int) (json.RawMessage, error) {
|
||||
// "Configurations that require more than 16 levels of recursion are
|
||||
// considered invalid and should result in a NACK response." - A51
|
||||
if depth > 15 {
|
||||
return nil, fmt.Errorf("lb policy %v exceeds max depth supported: 16 layers", lbPolicy)
|
||||
}
|
||||
|
||||
// "This function iterate over the list of policy messages in
|
||||
// LoadBalancingPolicy, attempting to convert each one to gRPC form,
|
||||
// stopping at the first supported policy." - A52
|
||||
for _, policy := range lbPolicy.GetPolicies() {
|
||||
converter := m[policy.GetTypedExtensionConfig().GetTypedConfig().GetTypeUrl()]
|
||||
// "Any entry not in the above list is unsupported and will be skipped."
|
||||
// - A52
|
||||
if converter == nil {
|
||||
continue
|
||||
}
|
||||
json, err := converter(policy.GetTypedExtensionConfig().GetTypedConfig().GetValue(), depth)
|
||||
if json == nil && err == nil {
|
||||
continue
|
||||
}
|
||||
return json, err
|
||||
}
|
||||
return nil, fmt.Errorf("no supported policy found in policy list +%v", lbPolicy)
|
||||
}
|
||||
Reference in New Issue
Block a user