feat: add google-c2p dependence to DirectPath #1521
Changes from 7 commits
119b6d1
ce1227a
d8188d3
8bfcd10
77e81d7
70f3af2
90ed61e
baaff18
db57e67
1c288e0
c863608
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 |
---|---|---|
|
@@ -18,7 +18,8 @@ dependencies { | |
libraries['maven.io_grpc_grpc_auth'], | ||
libraries['maven.io_grpc_grpc_netty_shaded'], | ||
libraries['maven.io_grpc_grpc_protobuf'], | ||
libraries['maven.io_grpc_grpc_stub']) | ||
libraries['maven.io_grpc_grpc_stub'], | ||
libraries['maven.io_grpc_grpc_xds']) | ||
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. cc @ejona86 will adding grpc-xds explode dependencies and the size of gax-grpc library? 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. Yes, but that is the design. With added risk, it would be possible to delay adding this as a dependency until users are expected to actually use it. But this would eventually need to happen. With some effort, the C2P-enabled services could add this dependency instead of gax. So only those services using it would pay the price. 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. Maybe we should not add this per my comment above? 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. Per my new comment, I think this should be a runtime classpath. Note that you added this to runtimeOnly libraries['maven.io_grpc_grpc_xds'] 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. done |
||
|
||
compileOnly libraries['maven.com_google_auto_value_auto_value'] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,23 @@ | |
|
||
@RunWith(JUnit4.class) | ||
public class InstantiatingGrpcChannelProviderTest extends AbstractMtlsTransportChannelTest { | ||
static class TestEnvironmentProvider | ||
implements InstantiatingGrpcChannelProvider.EnvironmentProvider { | ||
private final String isDirectPathXdsEnabled; | ||
|
||
TestEnvironmentProvider(String isDirectPathXdsEnabled) { | ||
this.isDirectPathXdsEnabled = isDirectPathXdsEnabled; | ||
} | ||
|
||
@Override | ||
public String getenv(String env) { | ||
if (env.equals("GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS")) { | ||
return isDirectPathXdsEnabled; | ||
} | ||
return System.getenv(env); | ||
} | ||
} | ||
|
||
@Test | ||
public void testEndpoint() { | ||
String endpoint = "localhost:8080"; | ||
|
@@ -390,6 +407,29 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) { | |
provider.getTransportChannel().shutdownNow(); | ||
} | ||
|
||
@Test | ||
public void testWithDirectPathXds() throws IOException { | ||
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. Thanks for trying. I saw this test is failing, and I think I know why. In order to test the section of the interest, we should satisfy the following constraints: if (isDirectPathEnabled(serviceAddress)
&& isNonDefaultServiceAccountAllowed()
&& isOnComputeEngine()) { The problem is that, But at this point, I don't want to make your life too difficult. Let's forget adding this and the 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. Ah, thanks! I will remove the unit test then. |
||
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); | ||
executor.shutdown(); | ||
|
||
InstantiatingGrpcChannelProvider grpcChannelProvider = | ||
InstantiatingGrpcChannelProvider.newBuilder() | ||
.setAttemptDirectPath(true) | ||
.setEnvProvider(new TestEnvironmentProvider(/*isDirectPathXdsEnabled = */ "true")) | ||
.build(); | ||
|
||
TransportChannelProvider transportChannelProvider = | ||
grpcChannelProvider | ||
.withHeaders(Collections.<String, String>emptyMap()) | ||
.withExecutor((Executor) executor) | ||
.withEndpoint("localhost:8080") | ||
.withCredentials(ComputeEngineCredentials.create()); | ||
|
||
transportChannelProvider.getTransportChannel().shutdownNow(); | ||
|
||
assertEquals(grpcChannelProvider.getActiveEndpoint(), "google-c2p:///localhost"); | ||
} | ||
|
||
@Test | ||
public void testWithIPv6Address() throws IOException { | ||
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that this should be added to
dependencies.properties
, not here, so that both Bazel and Gradle resolve and use the dependency.However, the Bazel build didn't break, meaning that this is unnecessary. I also just compiled the project with Gradle manually without this, and it compiled successfully. In fact, I don't see any new class being used in the code below. Obviously, this dependency is not required for compilation. Should we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me an example about how to add the dependency to
dependencies.properties
? And should I also remove change in bothgax-grpc/build.gradle
?Compilation can succeed because as you said, no new class is added. However, this dependency is actually registering
google-c2p
resolver to the build binary, otherwise gRPC can not recognize thegoogle-c2p:///
URI scheme and we will get error likeJava.lang.IllegalArgumentException: cannot find a NameResolver for google-c2p:///localhost
. So we should keep the dependency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. What you are saying sounds like the dependency is required to exist in the runtime classpath of the user consuming the gax-java library.
Since it's not required for compiling the project, let's have this as a Gradle-only dependency. I'm pretty new to this repo, so I don't know whether the Bazel build will also need this for something. However, gax-java libraries are released from Gradle, at least they will be okay. If there comes an issue on the Bazel side later, we'll take care of it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks!