@@ -46,6 +46,7 @@ import (
4646 "google.golang.org/grpc/internal/grpclog"
4747 "google.golang.org/grpc/internal/grpcsync"
4848 iserviceconfig "google.golang.org/grpc/internal/serviceconfig"
49+ xdsinternal "google.golang.org/grpc/internal/xds"
4950 "google.golang.org/grpc/orca"
5051 "google.golang.org/grpc/resolver"
5152 "google.golang.org/grpc/serviceconfig"
6263 Description : "EXPERIMENTAL. Number of scheduler updates in which there were not enough endpoints with valid weight, which caused the WRR policy to fall back to RR behavior." ,
6364 Unit : "{update}" ,
6465 Labels : []string {"grpc.target" },
65- OptionalLabels : []string {"grpc.lb.locality" },
66+ OptionalLabels : []string {"grpc.lb.locality" , "grpc.lb.backend_service" },
6667 Default : false ,
6768 })
6869
7172 Description : "EXPERIMENTAL. Number of endpoints from each scheduler update that don't yet have usable weight information (i.e., either the load report has not yet been received, or it is within the blackout period)." ,
7273 Unit : "{endpoint}" ,
7374 Labels : []string {"grpc.target" },
74- OptionalLabels : []string {"grpc.lb.locality" },
75+ OptionalLabels : []string {"grpc.lb.locality" , "grpc.lb.backend_service" },
7576 Default : false ,
7677 })
7778
@@ -80,15 +81,15 @@ var (
8081 Description : "EXPERIMENTAL. Number of endpoints from each scheduler update whose latest weight is older than the expiration period." ,
8182 Unit : "{endpoint}" ,
8283 Labels : []string {"grpc.target" },
83- OptionalLabels : []string {"grpc.lb.locality" },
84+ OptionalLabels : []string {"grpc.lb.locality" , "grpc.lb.backend_service" },
8485 Default : false ,
8586 })
8687 endpointWeightsMetric = estats .RegisterFloat64Histo (estats.MetricDescriptor {
8788 Name : "grpc.lb.wrr.endpoint_weights" ,
8889 Description : "EXPERIMENTAL. Weight of each endpoint, recorded on every scheduler update. Endpoints without usable weights will be recorded as weight 0." ,
8990 Unit : "{endpoint}" ,
9091 Labels : []string {"grpc.target" },
91- OptionalLabels : []string {"grpc.lb.locality" },
92+ OptionalLabels : []string {"grpc.lb.locality" , "grpc.lb.backend_service" },
9293 Default : false ,
9394 })
9495)
@@ -173,6 +174,7 @@ func (b *wrrBalancer) updateEndpointsLocked(endpoints []resolver.Endpoint) {
173174 metricsRecorder : b .metricsRecorder ,
174175 target : b .target ,
175176 locality : b .locality ,
177+ cluster : b .clusterName ,
176178 }
177179 for _ , addr := range endpoint .Addresses {
178180 b .addressWeights .Set (addr , ew )
@@ -211,6 +213,7 @@ type wrrBalancer struct {
211213 mu sync.Mutex
212214 cfg * lbConfig // active config
213215 locality string
216+ clusterName string
214217 stopPicker * grpcsync.Event
215218 addressWeights * resolver.AddressMapV2 [* endpointWeight ]
216219 endpointToWeight * resolver.EndpointMap [* endpointWeight ]
@@ -231,6 +234,11 @@ func (b *wrrBalancer) UpdateClientConnState(ccs balancer.ClientConnState) error
231234 b .mu .Lock ()
232235 b .cfg = cfg
233236 b .locality = weightedtarget .LocalityFromResolverState (ccs .ResolverState )
237+ if ccs .ResolverState .Addresses != nil {
238+ if cluster , ok := xdsinternal .GetXDSHandshakeClusterName (ccs .ResolverState .Addresses [0 ].Attributes ); ok {
239+ b .clusterName = cluster
240+ }
241+ }
234242 b .updateEndpointsLocked (ccs .ResolverState .Endpoints )
235243 b .mu .Unlock ()
236244
@@ -288,6 +296,7 @@ func (b *wrrBalancer) UpdateState(state balancer.State) {
288296 metricsRecorder : b .metricsRecorder ,
289297 locality : b .locality ,
290298 target : b .target ,
299+ clusterName : b .clusterName ,
291300 }
292301
293302 b .stopPicker = grpcsync .NewEvent ()
@@ -420,6 +429,7 @@ type picker struct {
420429 // The following fields are immutable.
421430 target string
422431 locality string
432+ clusterName string
423433 metricsRecorder estats.MetricsRecorder
424434}
425435
@@ -499,6 +509,7 @@ type endpointWeight struct {
499509 target string
500510 metricsRecorder estats.MetricsRecorder
501511 locality string
512+ cluster string
502513
503514 // The following fields are only accessed on calls into the LB policy, and
504515 // do not need a mutex.
@@ -602,14 +613,14 @@ func (w *endpointWeight) weight(now time.Time, weightExpirationPeriod, blackoutP
602613
603614 if recordMetrics {
604615 defer func () {
605- endpointWeightsMetric .Record (w .metricsRecorder , weight , w .target , w .locality )
616+ endpointWeightsMetric .Record (w .metricsRecorder , weight , w .target , w .locality , w . cluster )
606617 }()
607618 }
608619
609620 // The endpoint has not received a load report (i.e. just turned READY with
610621 // no load report).
611622 if w .lastUpdated .Equal (time.Time {}) {
612- endpointWeightNotYetUsableMetric .Record (w .metricsRecorder , 1 , w .target , w .locality )
623+ endpointWeightNotYetUsableMetric .Record (w .metricsRecorder , 1 , w .target , w .locality , w . cluster )
613624 return 0
614625 }
615626
@@ -618,7 +629,7 @@ func (w *endpointWeight) weight(now time.Time, weightExpirationPeriod, blackoutP
618629 // start getting data again in the future, and return 0.
619630 if now .Sub (w .lastUpdated ) >= weightExpirationPeriod {
620631 if recordMetrics {
621- endpointWeightStaleMetric .Record (w .metricsRecorder , 1 , w .target , w .locality )
632+ endpointWeightStaleMetric .Record (w .metricsRecorder , 1 , w .target , w .locality , w . cluster )
622633 }
623634 w .nonEmptySince = time.Time {}
624635 return 0
@@ -627,7 +638,7 @@ func (w *endpointWeight) weight(now time.Time, weightExpirationPeriod, blackoutP
627638 // If we don't have at least blackoutPeriod worth of data, return 0.
628639 if blackoutPeriod != 0 && (w .nonEmptySince .Equal (time.Time {}) || now .Sub (w .nonEmptySince ) < blackoutPeriod ) {
629640 if recordMetrics {
630- endpointWeightNotYetUsableMetric .Record (w .metricsRecorder , 1 , w .target , w .locality )
641+ endpointWeightNotYetUsableMetric .Record (w .metricsRecorder , 1 , w .target , w .locality , w . cluster )
631642 }
632643 return 0
633644 }
0 commit comments