google.golang.org/grpc@v1.62.1/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 "google.golang.org/grpc/internal/serviceconfig" 25 "google.golang.org/grpc/serviceconfig" 26 "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" 27 ) 28 29 // DropConfig contains the category, and drop ratio. 30 type DropConfig struct { 31 Category string 32 RequestsPerMillion uint32 33 } 34 35 // LBConfig is the balancer config for cluster_impl balancer. 36 type LBConfig struct { 37 serviceconfig.LoadBalancingConfig `json:"-"` 38 39 Cluster string `json:"cluster,omitempty"` 40 EDSServiceName string `json:"edsServiceName,omitempty"` 41 // LoadReportingServer is the LRS server to send load reports to. If not 42 // present, load reporting will be disabled. 43 LoadReportingServer *bootstrap.ServerConfig `json:"lrsLoadReportingServer,omitempty"` 44 MaxConcurrentRequests *uint32 `json:"maxConcurrentRequests,omitempty"` 45 DropCategories []DropConfig `json:"dropCategories,omitempty"` 46 ChildPolicy *internalserviceconfig.BalancerConfig `json:"childPolicy,omitempty"` 47 } 48 49 func parseConfig(c json.RawMessage) (*LBConfig, error) { 50 var cfg LBConfig 51 if err := json.Unmarshal(c, &cfg); err != nil { 52 return nil, err 53 } 54 return &cfg, nil 55 } 56 57 func equalDropCategories(a, b []DropConfig) bool { 58 if len(a) != len(b) { 59 return false 60 } 61 for i := range a { 62 if a[i] != b[i] { 63 return false 64 } 65 } 66 return true 67 }