google.golang.org/grpc@v1.72.2/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/internal/xds/bootstrap" 26 "google.golang.org/grpc/serviceconfig" 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 // TelemetryLabels are the telemetry Labels associated with this cluster. 47 TelemetryLabels map[string]string `json:"telemetryLabels,omitempty"` 48 ChildPolicy *internalserviceconfig.BalancerConfig `json:"childPolicy,omitempty"` 49 } 50 51 func parseConfig(c json.RawMessage) (*LBConfig, error) { 52 var cfg LBConfig 53 if err := json.Unmarshal(c, &cfg); err != nil { 54 return nil, err 55 } 56 return &cfg, nil 57 } 58 59 func equalDropCategories(a, b []DropConfig) bool { 60 if len(a) != len(b) { 61 return false 62 } 63 for i := range a { 64 if a[i] != b[i] { 65 return false 66 } 67 } 68 return true 69 }