From 21eb9b339f441f9e6e17ba1bad8d200c341ec76f Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 23 Jan 2024 20:43:36 -0500 Subject: [PATCH] chore: Address PR comments --- .../InstantiatingGrpcChannelProvider.java | 14 +++------- .../InstantiatingGrpcChannelProviderTest.java | 26 ------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index d7b019a7e0..c385b8aef4 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -295,11 +295,6 @@ private void logDirectPathMisconfig() { Level.WARNING, "DirectPath is misconfigured. DirectPath is only available in a GCE environment."); } - // Case 4: Universe Domain is non-GDU - if (!canUseDirectPathWithUniverseDomain()) { - LOG.log( - Level.WARNING, "DirectPath will only work in the the googleapis.com Universe Domain"); - } } } } @@ -338,13 +333,12 @@ static boolean isOnComputeEngine() { // Universe Domain configuration is currently only supported in the GDU @VisibleForTesting boolean canUseDirectPathWithUniverseDomain() { - // ClientContext will set an endpoint if it isn't provided to the TransportChannelProvider - // If the endpoint is null, then the endpoint hasn't been fully resolved yet (client not - // initialized). Before a call goes through with DirectPath, this validation must succeed. - if (endpoint == null) { + if (endpoint.contains(Credentials.GOOGLE_DEFAULT_UNIVERSE)) { return true; } - return endpoint.contains(Credentials.GOOGLE_DEFAULT_UNIVERSE); + // This is only logged if DirectPath is enabled + LOG.log(Level.WARNING, "DirectPath will only work in the the googleapis.com Universe Domain"); + return false; } @VisibleForTesting diff --git a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 93d6d64404..f6fb9d00ac 100644 --- a/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -292,16 +292,6 @@ public void testDirectPathDisallowNullCredentials() throws IOException { assertThat(provider.isCredentialDirectPathCompatible()).isFalse(); } - @Test - public void testDirectPathWithNullEndpoint() { - InstantiatingGrpcChannelProvider provider = - InstantiatingGrpcChannelProvider.newBuilder() - .setAttemptDirectPath(true) - .setAttemptDirectPathXds() - .build(); - assertThat(provider.canUseDirectPathWithUniverseDomain()).isTrue(); - } - @Test public void testDirectPathWithGDUEndpoint() { InstantiatingGrpcChannelProvider provider = @@ -597,22 +587,6 @@ public void testLogDirectPathMisconfigNotOnGCE() { InstantiatingGrpcChannelProvider.LOG.removeHandler(logHandler); } - @Test - public void testLogDirectPathMisconfigNotInGDU() { - FakeLogHandler logHandler = new FakeLogHandler(); - InstantiatingGrpcChannelProvider.LOG.addHandler(logHandler); - InstantiatingGrpcChannelProvider provider = - InstantiatingGrpcChannelProvider.newBuilder() - .setAttemptDirectPathXds() - .setAttemptDirectPath(true) - .setAllowNonDefaultServiceAccount(true) - .setEndpoint("test.random.endpoint.com:443") - .build(); - assertThat(logHandler.getAllMessages()) - .contains("DirectPath will only work in the the googleapis.com Universe Domain"); - InstantiatingGrpcChannelProvider.LOG.removeHandler(logHandler); - } - private static class FakeLogHandler extends Handler { List records = new ArrayList<>();