mirror of https://github.com/grpc/grpc-java.git
xds: Move LR and RLS experimental flags to where they are used
That's better for code organization and also removes some grpc-isms from XdsResourceType.
This commit is contained in:
parent
d894c8385d
commit
42b2cbdec3
|
|
@ -22,6 +22,7 @@ import static io.grpc.xds.client.Bootstrapper.ServerInfo;
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.protobuf.Duration;
|
import com.google.protobuf.Duration;
|
||||||
|
|
@ -50,6 +51,12 @@ import java.util.Set;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
class XdsClusterResource extends XdsResourceType<CdsUpdate> {
|
class XdsClusterResource extends XdsResourceType<CdsUpdate> {
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean enableLeastRequest =
|
||||||
|
!Strings.isNullOrEmpty(System.getenv("GRPC_EXPERIMENTAL_ENABLE_LEAST_REQUEST"))
|
||||||
|
? Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_ENABLE_LEAST_REQUEST"))
|
||||||
|
: Boolean.parseBoolean(System.getProperty("io.grpc.xds.experimentalEnableLeastRequest"));
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String AGGREGATE_CLUSTER_TYPE_NAME = "envoy.clusters.aggregate";
|
static final String AGGREGATE_CLUSTER_TYPE_NAME = "envoy.clusters.aggregate";
|
||||||
static final String ADS_TYPE_URL_CDS =
|
static final String ADS_TYPE_URL_CDS =
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import io.envoyproxy.envoy.config.route.v3.RetryPolicy.RetryBackOff;
|
||||||
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
|
import io.envoyproxy.envoy.config.route.v3.RouteConfiguration;
|
||||||
import io.envoyproxy.envoy.type.v3.FractionalPercent;
|
import io.envoyproxy.envoy.type.v3.FractionalPercent;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
|
import io.grpc.internal.GrpcUtil;
|
||||||
import io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig;
|
import io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig;
|
||||||
import io.grpc.xds.ClusterSpecifierPlugin.PluginConfig;
|
import io.grpc.xds.ClusterSpecifierPlugin.PluginConfig;
|
||||||
import io.grpc.xds.Filter.FilterConfig;
|
import io.grpc.xds.Filter.FilterConfig;
|
||||||
|
|
@ -67,6 +68,9 @@ import java.util.Set;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
class XdsRouteConfigureResource extends XdsResourceType<RdsUpdate> {
|
class XdsRouteConfigureResource extends XdsResourceType<RdsUpdate> {
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean enableRouteLookup = GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_RLS_LB", true);
|
||||||
|
|
||||||
static final String ADS_TYPE_URL_RDS =
|
static final String ADS_TYPE_URL_RDS =
|
||||||
"type.googleapis.com/envoy.config.route.v3.RouteConfiguration";
|
"type.googleapis.com/envoy.config.route.v3.RouteConfiguration";
|
||||||
private static final String TYPE_URL_FILTER_CONFIG =
|
private static final String TYPE_URL_FILTER_CONFIG =
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import static io.grpc.xds.client.XdsClient.canonifyResourceName;
|
||||||
import static io.grpc.xds.client.XdsClient.isResourceNameValid;
|
import static io.grpc.xds.client.XdsClient.isResourceNameValid;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.protobuf.Any;
|
import com.google.protobuf.Any;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
|
@ -44,13 +43,6 @@ public abstract class XdsResourceType<T extends ResourceUpdate> {
|
||||||
protected static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls";
|
protected static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final String HASH_POLICY_FILTER_STATE_KEY = "io.grpc.channel_id";
|
public static final String HASH_POLICY_FILTER_STATE_KEY = "io.grpc.channel_id";
|
||||||
@VisibleForTesting
|
|
||||||
public static boolean enableRouteLookup = getFlag("GRPC_EXPERIMENTAL_XDS_RLS_LB", true);
|
|
||||||
@VisibleForTesting
|
|
||||||
public static boolean enableLeastRequest =
|
|
||||||
!Strings.isNullOrEmpty(System.getenv("GRPC_EXPERIMENTAL_ENABLE_LEAST_REQUEST"))
|
|
||||||
? Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_ENABLE_LEAST_REQUEST"))
|
|
||||||
: Boolean.parseBoolean(System.getProperty("io.grpc.xds.experimentalEnableLeastRequest"));
|
|
||||||
|
|
||||||
protected static final String TYPE_URL_CLUSTER_CONFIG =
|
protected static final String TYPE_URL_CLUSTER_CONFIG =
|
||||||
"type.googleapis.com/envoy.extensions.clusters.aggregate.v3.ClusterConfig";
|
"type.googleapis.com/envoy.extensions.clusters.aggregate.v3.ClusterConfig";
|
||||||
|
|
@ -258,15 +250,6 @@ public abstract class XdsResourceType<T extends ResourceUpdate> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getFlag(String envVarName, boolean enableByDefault) {
|
|
||||||
String envVar = System.getenv(envVarName);
|
|
||||||
if (enableByDefault) {
|
|
||||||
return Strings.isNullOrEmpty(envVar) || Boolean.parseBoolean(envVar);
|
|
||||||
} else {
|
|
||||||
return !Strings.isNullOrEmpty(envVar) && Boolean.parseBoolean(envVar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final class StructOrError<T> {
|
public static final class StructOrError<T> {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,15 +173,15 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
originalEnableRouteLookup = XdsResourceType.enableRouteLookup;
|
originalEnableRouteLookup = XdsRouteConfigureResource.enableRouteLookup;
|
||||||
originalEnableLeastRequest = XdsResourceType.enableLeastRequest;
|
originalEnableLeastRequest = XdsClusterResource.enableLeastRequest;
|
||||||
assertThat(originalEnableLeastRequest).isFalse();
|
assertThat(originalEnableLeastRequest).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
XdsResourceType.enableRouteLookup = originalEnableRouteLookup;
|
XdsRouteConfigureResource.enableRouteLookup = originalEnableRouteLookup;
|
||||||
XdsResourceType.enableLeastRequest = originalEnableLeastRequest;
|
XdsClusterResource.enableLeastRequest = originalEnableLeastRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -860,7 +860,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRouteAction_clusterSpecifier_routeLookupDisabled() {
|
public void parseRouteAction_clusterSpecifier_routeLookupDisabled() {
|
||||||
XdsResourceType.enableRouteLookup = false;
|
XdsRouteConfigureResource.enableRouteLookup = false;
|
||||||
io.envoyproxy.envoy.config.route.v3.RouteAction proto =
|
io.envoyproxy.envoy.config.route.v3.RouteAction proto =
|
||||||
io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder()
|
io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder()
|
||||||
.setClusterSpecifierPlugin(CLUSTER_SPECIFIER_PLUGIN.name())
|
.setClusterSpecifierPlugin(CLUSTER_SPECIFIER_PLUGIN.name())
|
||||||
|
|
@ -1465,7 +1465,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseHttpConnectionManager_clusterSpecifierPlugin() throws Exception {
|
public void parseHttpConnectionManager_clusterSpecifierPlugin() throws Exception {
|
||||||
XdsResourceType.enableRouteLookup = true;
|
XdsRouteConfigureResource.enableRouteLookup = true;
|
||||||
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
||||||
.addGrpcKeybuilders(
|
.addGrpcKeybuilders(
|
||||||
GrpcKeyBuilder.newBuilder()
|
GrpcKeyBuilder.newBuilder()
|
||||||
|
|
@ -1521,7 +1521,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseHttpConnectionManager_duplicatePluginName() throws Exception {
|
public void parseHttpConnectionManager_duplicatePluginName() throws Exception {
|
||||||
XdsResourceType.enableRouteLookup = true;
|
XdsRouteConfigureResource.enableRouteLookup = true;
|
||||||
RouteLookupConfig routeLookupConfig1 = RouteLookupConfig.newBuilder()
|
RouteLookupConfig routeLookupConfig1 = RouteLookupConfig.newBuilder()
|
||||||
.addGrpcKeybuilders(
|
.addGrpcKeybuilders(
|
||||||
GrpcKeyBuilder.newBuilder()
|
GrpcKeyBuilder.newBuilder()
|
||||||
|
|
@ -1594,7 +1594,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseHttpConnectionManager_pluginNameNotFound() throws Exception {
|
public void parseHttpConnectionManager_pluginNameNotFound() throws Exception {
|
||||||
XdsResourceType.enableRouteLookup = true;
|
XdsRouteConfigureResource.enableRouteLookup = true;
|
||||||
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
||||||
.addGrpcKeybuilders(
|
.addGrpcKeybuilders(
|
||||||
GrpcKeyBuilder.newBuilder()
|
GrpcKeyBuilder.newBuilder()
|
||||||
|
|
@ -1647,7 +1647,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseHttpConnectionManager_optionalPlugin() throws ResourceInvalidException {
|
public void parseHttpConnectionManager_optionalPlugin() throws ResourceInvalidException {
|
||||||
XdsResourceType.enableRouteLookup = true;
|
XdsRouteConfigureResource.enableRouteLookup = true;
|
||||||
|
|
||||||
// RLS Plugin, and a route to it.
|
// RLS Plugin, and a route to it.
|
||||||
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder()
|
||||||
|
|
@ -1729,7 +1729,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseHttpConnectionManager_validateRdsConfigSource() throws Exception {
|
public void parseHttpConnectionManager_validateRdsConfigSource() throws Exception {
|
||||||
XdsResourceType.enableRouteLookup = true;
|
XdsRouteConfigureResource.enableRouteLookup = true;
|
||||||
|
|
||||||
HttpConnectionManager hcm1 =
|
HttpConnectionManager hcm1 =
|
||||||
HttpConnectionManager.newBuilder()
|
HttpConnectionManager.newBuilder()
|
||||||
|
|
@ -1967,7 +1967,7 @@ public class GrpcXdsClientImplDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCluster_leastRequestLbPolicy_defaultLbConfig() throws ResourceInvalidException {
|
public void parseCluster_leastRequestLbPolicy_defaultLbConfig() throws ResourceInvalidException {
|
||||||
XdsResourceType.enableLeastRequest = true;
|
XdsClusterResource.enableLeastRequest = true;
|
||||||
Cluster cluster = Cluster.newBuilder()
|
Cluster cluster = Cluster.newBuilder()
|
||||||
.setName("cluster-foo.googleapis.com")
|
.setName("cluster-foo.googleapis.com")
|
||||||
.setType(DiscoveryType.EDS)
|
.setType(DiscoveryType.EDS)
|
||||||
|
|
|
||||||
|
|
@ -304,8 +304,8 @@ public abstract class GrpcXdsClientImplTestBase {
|
||||||
when(backoffPolicy2.nextBackoffNanos()).thenReturn(20L, 200L);
|
when(backoffPolicy2.nextBackoffNanos()).thenReturn(20L, 200L);
|
||||||
|
|
||||||
// Start the server and the client.
|
// Start the server and the client.
|
||||||
originalEnableLeastRequest = XdsResourceType.enableLeastRequest;
|
originalEnableLeastRequest = XdsClusterResource.enableLeastRequest;
|
||||||
XdsResourceType.enableLeastRequest = true;
|
XdsClusterResource.enableLeastRequest = true;
|
||||||
xdsServer = cleanupRule.register(InProcessServerBuilder
|
xdsServer = cleanupRule.register(InProcessServerBuilder
|
||||||
.forName(serverName)
|
.forName(serverName)
|
||||||
.addService(adsService)
|
.addService(adsService)
|
||||||
|
|
@ -376,7 +376,7 @@ public abstract class GrpcXdsClientImplTestBase {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
XdsResourceType.enableLeastRequest = originalEnableLeastRequest;
|
XdsClusterResource.enableLeastRequest = originalEnableLeastRequest;
|
||||||
xdsClient.shutdown();
|
xdsClient.shutdown();
|
||||||
channel.shutdown(); // channel not owned by XdsClient
|
channel.shutdown(); // channel not owned by XdsClient
|
||||||
assertThat(adsEnded.get()).isTrue();
|
assertThat(adsEnded.get()).isTrue();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue