-
Notifications
You must be signed in to change notification settings - Fork 3.9k
xds: ORCA to LRS propagation changes #12203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2025 The 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 io.grpc.xds; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import io.grpc.Internal; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents the configuration for which ORCA metrics should be propagated from backend | ||
* to LRS load reports, as defined in gRFC A85. | ||
*/ | ||
@Internal | ||
public final class BackendMetricPropagation { | ||
|
||
public final boolean propagateCpuUtilization; | ||
public final boolean propagateMemUtilization; | ||
public final boolean propagateApplicationUtilization; | ||
|
||
private final boolean propagateAllNamedMetrics; | ||
private final ImmutableSet<String> namedMetricKeys; | ||
|
||
private BackendMetricPropagation( | ||
boolean propagateCpuUtilization, | ||
boolean propagateMemUtilization, | ||
boolean propagateApplicationUtilization, | ||
boolean propagateAllNamedMetrics, | ||
ImmutableSet<String> namedMetricKeys) { | ||
this.propagateCpuUtilization = propagateCpuUtilization; | ||
this.propagateMemUtilization = propagateMemUtilization; | ||
this.propagateApplicationUtilization = propagateApplicationUtilization; | ||
this.propagateAllNamedMetrics = propagateAllNamedMetrics; | ||
this.namedMetricKeys = checkNotNull(namedMetricKeys, "namedMetricKeys"); | ||
} | ||
|
||
/** | ||
* Creates a BackendMetricPropagation from a list of metric specifications. | ||
* | ||
* @param metricSpecs list of metric specification strings from CDS resource | ||
* @return BackendMetricPropagation instance | ||
*/ | ||
public static BackendMetricPropagation fromMetricSpecs(@Nullable java.util.List<String> metricSpecs) { | ||
if (metricSpecs == null || metricSpecs.isEmpty()) { | ||
return new BackendMetricPropagation(false, false, false, false, ImmutableSet.of()); | ||
} | ||
|
||
boolean propagateCpuUtilization = false; | ||
boolean propagateMemUtilization = false; | ||
boolean propagateApplicationUtilization = false; | ||
boolean propagateAllNamedMetrics = false; | ||
ImmutableSet.Builder<String> namedMetricKeysBuilder = ImmutableSet.builder(); | ||
for (String spec : metricSpecs) { | ||
if (spec == null) { | ||
continue; | ||
} | ||
switch (spec) { | ||
case "cpu_utilization": | ||
propagateCpuUtilization = true; | ||
break; | ||
case "mem_utilization": | ||
propagateMemUtilization = true; | ||
break; | ||
case "application_utilization": | ||
propagateApplicationUtilization = true; | ||
break; | ||
case "named_metrics.*": | ||
propagateAllNamedMetrics = true; | ||
break; | ||
default: | ||
if (spec.startsWith("named_metrics.")) { | ||
String metricKey = spec.substring("named_metrics.".length()); | ||
if (!metricKey.isEmpty()) { | ||
namedMetricKeysBuilder.add(metricKey); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return new BackendMetricPropagation( | ||
propagateCpuUtilization, | ||
propagateMemUtilization, | ||
propagateApplicationUtilization, | ||
propagateAllNamedMetrics, | ||
namedMetricKeysBuilder.build()); | ||
} | ||
|
||
/** | ||
* Returns whether the given named metric key should be propagated. | ||
*/ | ||
public boolean shouldPropagateNamedMetric(String metricKey) { | ||
return propagateAllNamedMetrics || namedMetricKeys.contains(metricKey); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,11 +191,11 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) { | |
if (instance.type == DiscoveryMechanism.Type.EDS) { | ||
state = new EdsClusterState(instance.cluster, instance.edsServiceName, | ||
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext, | ||
instance.filterMetadata, instance.outlierDetection); | ||
instance.filterMetadata, instance.outlierDetection, instance.backendMetricPropagation); | ||
} else { // logical DNS | ||
state = new LogicalDnsClusterState(instance.cluster, instance.dnsHostName, | ||
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext, | ||
instance.filterMetadata); | ||
instance.filterMetadata, instance.backendMetricPropagation); | ||
} | ||
clusterStates.put(instance.cluster, state); | ||
state.start(); | ||
|
@@ -334,6 +334,8 @@ private abstract class ClusterState { | |
protected final Map<String, Struct> filterMetadata; | ||
@Nullable | ||
protected final OutlierDetection outlierDetection; | ||
@Nullable | ||
protected final BackendMetricPropagation backendMetricPropagation; | ||
// Resolution status, may contain most recent error encountered. | ||
protected Status status = Status.OK; | ||
// True if has received resolution result. | ||
|
@@ -346,13 +348,15 @@ private abstract class ClusterState { | |
|
||
private ClusterState(String name, @Nullable ServerInfo lrsServerInfo, | ||
@Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext, | ||
Map<String, Struct> filterMetadata, @Nullable OutlierDetection outlierDetection) { | ||
Map<String, Struct> filterMetadata, @Nullable OutlierDetection outlierDetection, | ||
@Nullable BackendMetricPropagation backendMetricPropagation) { | ||
this.name = name; | ||
this.lrsServerInfo = lrsServerInfo; | ||
this.maxConcurrentRequests = maxConcurrentRequests; | ||
this.tlsContext = tlsContext; | ||
this.filterMetadata = ImmutableMap.copyOf(filterMetadata); | ||
this.outlierDetection = outlierDetection; | ||
this.backendMetricPropagation = backendMetricPropagation; | ||
} | ||
|
||
abstract void start(); | ||
|
@@ -371,9 +375,10 @@ private final class EdsClusterState extends ClusterState implements ResourceWatc | |
private EdsClusterState(String name, @Nullable String edsServiceName, | ||
@Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, | ||
@Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata, | ||
@Nullable OutlierDetection outlierDetection) { | ||
@Nullable OutlierDetection outlierDetection, | ||
@Nullable BackendMetricPropagation backendMetricPropagation) { | ||
super(name, lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, | ||
outlierDetection); | ||
outlierDetection, backendMetricPropagation); | ||
this.edsServiceName = edsServiceName; | ||
} | ||
|
||
|
@@ -470,8 +475,8 @@ public void run() { | |
Map<String, PriorityChildConfig> priorityChildConfigs = | ||
generateEdsBasedPriorityChildConfigs( | ||
name, edsServiceName, lrsServerInfo, maxConcurrentRequests, tlsContext, | ||
filterMetadata, outlierDetection, endpointLbConfig, lbRegistry, | ||
prioritizedLocalityWeights, dropOverloads); | ||
filterMetadata, backendMetricPropagation, outlierDetection, | ||
endpointLbConfig, lbRegistry, prioritizedLocalityWeights, dropOverloads); | ||
status = Status.OK; | ||
resolved = true; | ||
result = new ClusterResolutionResult(addresses, priorityChildConfigs, | ||
|
@@ -585,8 +590,10 @@ private final class LogicalDnsClusterState extends ClusterState { | |
|
||
private LogicalDnsClusterState(String name, String dnsHostName, | ||
@Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, | ||
@Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata) { | ||
super(name, lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, null); | ||
@Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata, | ||
@Nullable BackendMetricPropagation backendMetricPropagation) { | ||
super(name, lrsServerInfo, maxConcurrentRequests, tlsContext, | ||
filterMetadata, null, backendMetricPropagation); | ||
this.dnsHostName = checkNotNull(dnsHostName, "dnsHostName"); | ||
nameResolverFactory = | ||
checkNotNull(helper.getNameResolverRegistry().asFactory(), "nameResolverFactory"); | ||
|
@@ -688,7 +695,7 @@ public Status onResult2(final ResolutionResult resolutionResult) { | |
} | ||
PriorityChildConfig priorityChildConfig = generateDnsBasedPriorityChildConfig( | ||
name, lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, | ||
lbRegistry, Collections.<DropOverload>emptyList()); | ||
backendMetricPropagation, lbRegistry, Collections.<DropOverload>emptyList()); | ||
status = Status.OK; | ||
resolved = true; | ||
result = new ClusterResolutionResult(addresses, priorityName, priorityChildConfig); | ||
|
@@ -772,13 +779,14 @@ private static class ClusterResolutionResult { | |
private static PriorityChildConfig generateDnsBasedPriorityChildConfig( | ||
String cluster, @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, | ||
@Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata, | ||
@Nullable BackendMetricPropagation backendMetricPropagation, | ||
LoadBalancerRegistry lbRegistry, List<DropOverload> dropOverloads) { | ||
// Override endpoint-level LB policy with pick_first for logical DNS cluster. | ||
Object endpointLbConfig = GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig( | ||
lbRegistry.getProvider("pick_first"), null); | ||
ClusterImplConfig clusterImplConfig = | ||
new ClusterImplConfig(cluster, null, lrsServerInfo, maxConcurrentRequests, | ||
dropOverloads, endpointLbConfig, tlsContext, filterMetadata); | ||
dropOverloads, endpointLbConfig, tlsContext, filterMetadata, backendMetricPropagation); | ||
LoadBalancerProvider clusterImplLbProvider = | ||
lbRegistry.getProvider(XdsLbPolicies.CLUSTER_IMPL_POLICY_NAME); | ||
Object clusterImplPolicy = GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig( | ||
|
@@ -795,15 +803,15 @@ private static PriorityChildConfig generateDnsBasedPriorityChildConfig( | |
private static Map<String, PriorityChildConfig> generateEdsBasedPriorityChildConfigs( | ||
String cluster, @Nullable String edsServiceName, @Nullable ServerInfo lrsServerInfo, | ||
@Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext, | ||
Map<String, Struct> filterMetadata, | ||
Map<String, Struct> filterMetadata, @Nullable BackendMetricPropagation backendMetricPropagation, | ||
@Nullable OutlierDetection outlierDetection, Object endpointLbConfig, | ||
LoadBalancerRegistry lbRegistry, Map<String, | ||
Map<Locality, Integer>> prioritizedLocalityWeights, List<DropOverload> dropOverloads) { | ||
Comment on lines
+806
to
809
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can we add backendMetricPropagation param to the end of the methods for better consistency ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will push it after |
||
Map<String, PriorityChildConfig> configs = new HashMap<>(); | ||
for (String priority : prioritizedLocalityWeights.keySet()) { | ||
ClusterImplConfig clusterImplConfig = | ||
new ClusterImplConfig(cluster, edsServiceName, lrsServerInfo, maxConcurrentRequests, | ||
dropOverloads, endpointLbConfig, tlsContext, filterMetadata); | ||
dropOverloads, endpointLbConfig, tlsContext, filterMetadata, backendMetricPropagation); | ||
LoadBalancerProvider clusterImplLbProvider = | ||
lbRegistry.getProvider(XdsLbPolicies.CLUSTER_IMPL_POLICY_NAME); | ||
Object priorityChildPolicy = GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig( | ||
|
Uh oh!
There was an error while loading. Please reload this page.