github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/xds/internal/balancer/clusterimpl/config.go (about) 1 /* 2 * 3 * Copyright 2020 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package clusterimpl 20 21 import ( 22 "encoding/json" 23 24 internalserviceconfig "github.com/hxx258456/ccgo/grpc/internal/serviceconfig" 25 "github.com/hxx258456/ccgo/grpc/serviceconfig" 26 ) 27 28 // DropConfig contains the category, and drop ratio. 29 type DropConfig struct { 30 Category string 31 RequestsPerMillion uint32 32 } 33 34 // LBConfig is the balancer config for cluster_impl balancer. 35 type LBConfig struct { 36 serviceconfig.LoadBalancingConfig `json:"-"` 37 38 Cluster string `json:"cluster,omitempty"` 39 EDSServiceName string `json:"edsServiceName,omitempty"` 40 LoadReportingServerName *string `json:"lrsLoadReportingServerName,omitempty"` 41 MaxConcurrentRequests *uint32 `json:"maxConcurrentRequests,omitempty"` 42 DropCategories []DropConfig `json:"dropCategories,omitempty"` 43 ChildPolicy *internalserviceconfig.BalancerConfig `json:"childPolicy,omitempty"` 44 } 45 46 func parseConfig(c json.RawMessage) (*LBConfig, error) { 47 var cfg LBConfig 48 if err := json.Unmarshal(c, &cfg); err != nil { 49 return nil, err 50 } 51 return &cfg, nil 52 } 53 54 func equalDropCategories(a, b []DropConfig) bool { 55 if len(a) != len(b) { 56 return false 57 } 58 for i := range a { 59 if a[i] != b[i] { 60 return false 61 } 62 } 63 return true 64 }