mirror of https://github.com/grpc/grpc-go.git
balancer: populate endpoint weight by edsbalancer for weighted_round_robin (#2945)
This commit is contained in:
parent
92635fa6bf
commit
a2bdfb40ff
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2019 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 weightedroundrobin defines a weighted roundrobin balancer.
|
||||
package weightedroundrobin
|
||||
|
||||
// Name is the name of weighted_round_robin balancer.
|
||||
const Name = "weighted_round_robin"
|
||||
|
||||
// AddrInfo will be stored inside Address metadata in order to use weighted roundrobin
|
||||
// balancer.
|
||||
type AddrInfo struct {
|
||||
Weight uint32
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"google.golang.org/grpc/balancer"
|
||||
"google.golang.org/grpc/balancer/roundrobin"
|
||||
"google.golang.org/grpc/balancer/weightedroundrobin"
|
||||
"google.golang.org/grpc/balancer/xds/internal"
|
||||
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
|
||||
endpointpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
|
||||
|
|
@ -227,9 +228,16 @@ func (xdsB *EDSBalancer) HandleEDSResponse(edsResp *edspb.ClusterLoadAssignment)
|
|||
var newAddrs []resolver.Address
|
||||
for _, lbEndpoint := range locality.GetLbEndpoints() {
|
||||
socketAddress := lbEndpoint.GetEndpoint().GetAddress().GetSocketAddress()
|
||||
newAddrs = append(newAddrs, resolver.Address{
|
||||
address := resolver.Address{
|
||||
Addr: net.JoinHostPort(socketAddress.GetAddress(), strconv.Itoa(int(socketAddress.GetPortValue()))),
|
||||
})
|
||||
}
|
||||
if xdsB.subBalancerBuilder.Name() == weightedroundrobin.Name &&
|
||||
lbEndpoint.GetLoadBalancingWeight().GetValue() != 0 {
|
||||
address.Metadata = &weightedroundrobin.AddrInfo{
|
||||
Weight: lbEndpoint.GetLoadBalancingWeight().GetValue(),
|
||||
}
|
||||
}
|
||||
newAddrs = append(newAddrs, address)
|
||||
}
|
||||
var weightChanged, addrsChanged bool
|
||||
config, ok := xdsB.lidToConfig[lid]
|
||||
|
|
|
|||
Loading…
Reference in New Issue