1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
2020import static io .grpc .xds .client .Bootstrapper .ServerInfo ;
21+ import static io .grpc .xds .client .LoadStatsManager2 .isEnabledOrcaLrsPropagation ;
2122
2223import com .google .auto .value .AutoValue ;
2324import com .google .common .annotations .VisibleForTesting ;
4748import io .grpc .xds .EnvoyServerProtoData .OutlierDetection ;
4849import io .grpc .xds .EnvoyServerProtoData .UpstreamTlsContext ;
4950import io .grpc .xds .XdsClusterResource .CdsUpdate ;
51+ import io .grpc .xds .client .BackendMetricPropagation ;
5052import io .grpc .xds .client .XdsClient .ResourceUpdate ;
5153import io .grpc .xds .client .XdsResourceType ;
5254import io .grpc .xds .internal .security .CommonTlsContextUtil ;
@@ -227,6 +229,12 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
227229 UpstreamTlsContext upstreamTlsContext = null ;
228230 OutlierDetection outlierDetection = null ;
229231 boolean isHttp11ProxyAvailable = false ;
232+ BackendMetricPropagation backendMetricPropagation = null ;
233+
234+ if (isEnabledOrcaLrsPropagation ) {
235+ backendMetricPropagation = BackendMetricPropagation .fromMetricSpecs (
236+ cluster .getLrsReportEndpointMetricsList ());
237+ }
230238 if (cluster .hasLrsServer ()) {
231239 if (!cluster .getLrsServer ().hasSelf ()) {
232240 return StructOrError .fromError (
@@ -326,7 +334,7 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
326334
327335 return StructOrError .fromStruct (CdsUpdate .forEds (
328336 clusterName , edsServiceName , lrsServerInfo , maxConcurrentRequests , upstreamTlsContext ,
329- outlierDetection , isHttp11ProxyAvailable ));
337+ outlierDetection , isHttp11ProxyAvailable , backendMetricPropagation ));
330338 } else if (type .equals (Cluster .DiscoveryType .LOGICAL_DNS )) {
331339 if (!cluster .hasLoadAssignment ()) {
332340 return StructOrError .fromError (
@@ -362,7 +370,7 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
362370 Locale .US , "%s:%d" , socketAddress .getAddress (), socketAddress .getPortValue ());
363371 return StructOrError .fromStruct (CdsUpdate .forLogicalDns (
364372 clusterName , dnsHostName , lrsServerInfo , maxConcurrentRequests ,
365- upstreamTlsContext , isHttp11ProxyAvailable ));
373+ upstreamTlsContext , isHttp11ProxyAvailable , backendMetricPropagation ));
366374 }
367375 return StructOrError .fromError (
368376 "Cluster " + clusterName + ": unsupported built-in discovery type: " + type );
@@ -614,6 +622,9 @@ abstract static class CdsUpdate implements ResourceUpdate {
614622
615623 abstract ImmutableMap <String , Object > parsedMetadata ();
616624
625+ @ Nullable
626+ abstract BackendMetricPropagation backendMetricPropagation ();
627+
617628 private static Builder newBuilder (String clusterName ) {
618629 return new AutoValue_XdsClusterResource_CdsUpdate .Builder ()
619630 .clusterName (clusterName )
@@ -622,7 +633,8 @@ private static Builder newBuilder(String clusterName) {
622633 .choiceCount (0 )
623634 .filterMetadata (ImmutableMap .of ())
624635 .parsedMetadata (ImmutableMap .of ())
625- .isHttp11ProxyAvailable (false );
636+ .isHttp11ProxyAvailable (false )
637+ .backendMetricPropagation (null );
626638 }
627639
628640 static Builder forAggregate (String clusterName , List <String > prioritizedClusterNames ) {
@@ -636,29 +648,33 @@ static Builder forEds(String clusterName, @Nullable String edsServiceName,
636648 @ Nullable ServerInfo lrsServerInfo , @ Nullable Long maxConcurrentRequests ,
637649 @ Nullable UpstreamTlsContext upstreamTlsContext ,
638650 @ Nullable OutlierDetection outlierDetection ,
639- boolean isHttp11ProxyAvailable ) {
651+ boolean isHttp11ProxyAvailable ,
652+ BackendMetricPropagation backendMetricPropagation ) {
640653 return newBuilder (clusterName )
641654 .clusterType (ClusterType .EDS )
642655 .edsServiceName (edsServiceName )
643656 .lrsServerInfo (lrsServerInfo )
644657 .maxConcurrentRequests (maxConcurrentRequests )
645658 .upstreamTlsContext (upstreamTlsContext )
646659 .outlierDetection (outlierDetection )
647- .isHttp11ProxyAvailable (isHttp11ProxyAvailable );
660+ .isHttp11ProxyAvailable (isHttp11ProxyAvailable )
661+ .backendMetricPropagation (backendMetricPropagation );
648662 }
649663
650664 static Builder forLogicalDns (String clusterName , String dnsHostName ,
651665 @ Nullable ServerInfo lrsServerInfo ,
652666 @ Nullable Long maxConcurrentRequests ,
653667 @ Nullable UpstreamTlsContext upstreamTlsContext ,
654- boolean isHttp11ProxyAvailable ) {
668+ boolean isHttp11ProxyAvailable ,
669+ BackendMetricPropagation backendMetricPropagation ) {
655670 return newBuilder (clusterName )
656671 .clusterType (ClusterType .LOGICAL_DNS )
657672 .dnsHostName (dnsHostName )
658673 .lrsServerInfo (lrsServerInfo )
659674 .maxConcurrentRequests (maxConcurrentRequests )
660675 .upstreamTlsContext (upstreamTlsContext )
661- .isHttp11ProxyAvailable (isHttp11ProxyAvailable );
676+ .isHttp11ProxyAvailable (isHttp11ProxyAvailable )
677+ .backendMetricPropagation (backendMetricPropagation );
662678 }
663679
664680 enum ClusterType {
@@ -749,6 +765,9 @@ Builder leastRequestLbPolicy(Integer choiceCount) {
749765
750766 protected abstract Builder parsedMetadata (ImmutableMap <String , Object > parsedMetadata );
751767
768+ protected abstract Builder backendMetricPropagation (
769+ BackendMetricPropagation backendMetricPropagation );
770+
752771 abstract CdsUpdate build ();
753772 }
754773 }
0 commit comments