Move gcp-observability interop binary out of interop-testing

gcp-observability has many dependencies so is a bit annoying in some
build systems to get working... just for it not to be used in
non-observability scenarios.

grpc-go and c core are using separate binaries for gcp-observability
interop testing, so do the same in Java, which makes interop-testing a
bit lighter.
This commit is contained in:
Eric Anderson 2023-03-06 18:15:11 -08:00
parent 7aa5598dc0
commit 4229191a23
9 changed files with 93 additions and 42 deletions

View File

@ -22,7 +22,7 @@ FROM openjdk:11.0.16-jdk-slim-bullseye AS build
WORKDIR /grpc-java WORKDIR /grpc-java
COPY . . COPY . .
RUN ./gradlew installDist -x test -PskipCodegen=true -PskipAndroid=true RUN ./gradlew :grpc-gcp-observability:interop:installDist -PskipCodegen=true -PskipAndroid=true
# #
@ -35,8 +35,8 @@ RUN ./gradlew installDist -x test -PskipCodegen=true -PskipAndroid=true
FROM openjdk:11.0.16-jdk-slim-bullseye FROM openjdk:11.0.16-jdk-slim-bullseye
WORKDIR /grpc-java/interop-testing/build WORKDIR /grpc-java/
COPY --from=build /grpc-java/interop-testing/build/. . COPY --from=build /grpc-java/gcp-observability/interop/build/install/interop/. .
WORKDIR /grpc-java/buildscripts/observability-test WORKDIR /grpc-java/buildscripts/observability-test
COPY --from=build /grpc-java/buildscripts/observability-test/run.sh . COPY --from=build /grpc-java/buildscripts/observability-test/run.sh .

View File

@ -28,13 +28,13 @@ cd "$(dirname "$0")"/../..
# $5: num_times # $5: num_times
if [ "$1" = "server" ] ; then if [ "$1" = "server" ] ; then
/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/test-server \ /grpc-java/bin/gcp-observability-interop \
--use_tls=false --enable_observability=true \ server --use_tls=false \
--port=$2 --port=$2
elif [ "$1" = "client" ] ; then elif [ "$1" = "client" ] ; then
/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/test-client \ /grpc-java/bin/gcp-observability-interop \
--use_tls=false --enable_observability=true \ client --use_tls=false \
--server_host=$2 --server_port=$3 \ --server_host=$2 --server_port=$3 \
--test_case=$4 --num_times=$5 --test_case=$4 --num_times=$5

View File

@ -51,7 +51,6 @@ dependencies {
// Avoid grpc-netty-shaded dependency // Avoid grpc-netty-shaded dependency
exclude group: 'io.grpc', module: 'grpc-alts' exclude group: 'io.grpc', module: 'grpc-alts'
exclude group: 'io.grpc', module: 'grpc-xds' exclude group: 'io.grpc', module: 'grpc-xds'
exclude group: 'io.grpc', module: 'grpc-gcp-observability'
} }
implementation libraries.junit implementation libraries.junit
implementation libraries.protobuf.java implementation libraries.protobuf.java

View File

@ -0,0 +1,22 @@
plugins {
id "application"
id "ru.vyarus.animalsniffer"
}
description = "gRPC: Google Cloud Platform Observability Interop"
dependencies {
implementation project(':grpc-interop-testing'),
project(':grpc-gcp-observability')
signature libraries.signature.java
}
application {
mainClass = 'io.grpc.gcp.observability.interop.TestServiceInterop'
}
tasks.named('startScripts').configure {
applicationName = 'gcp-observability-interop'
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2023 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.gcp.observability.interop;
import io.grpc.gcp.observability.GcpObservability;
import io.grpc.testing.integration.TestServiceClient;
import io.grpc.testing.integration.TestServiceServer;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
* Combined interop client and server for observability testing.
*/
public final class TestServiceInterop {
public static void main(String[] args) throws Exception {
boolean client;
if (args.length < 1) {
usage();
return;
}
if ("server".equals(args[0])) {
client = false;
} else if ("client".equals(args[0])) {
client = true;
} else {
usage();
return;
}
args = Arrays.asList(args).subList(1, args.length).toArray(new String[0]);
try (GcpObservability gcpObservability = GcpObservability.grpcInit()) {
if (client) {
TestServiceClient.main(args);
} else {
TestServiceServer.main(args);
}
// TODO(stanleycheung): remove this once the observability exporter plugin is able to
// gracefully flush observability data to cloud at shutdown
final int o11yCloseSleepSeconds = 65;
System.out.println("Sleeping " + o11yCloseSleepSeconds + " seconds before exiting");
Thread.sleep(TimeUnit.MILLISECONDS.convert(o11yCloseSleepSeconds, TimeUnit.SECONDS));
}
}
private static void usage() {
System.out.println("Usage: client|server [ARGS...]");
System.exit(1);
}
}

View File

@ -29,7 +29,6 @@ dependencies {
project(':grpc-services'), project(':grpc-services'),
project(':grpc-stub'), project(':grpc-stub'),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-gcp-observability'),
libraries.hdrhistogram, libraries.hdrhistogram,
libraries.junit, libraries.junit,
libraries.truth, libraries.truth,

View File

@ -31,7 +31,6 @@ import io.grpc.TlsChannelCredentials;
import io.grpc.alts.AltsChannelCredentials; import io.grpc.alts.AltsChannelCredentials;
import io.grpc.alts.ComputeEngineChannelCredentials; import io.grpc.alts.ComputeEngineChannelCredentials;
import io.grpc.alts.GoogleDefaultChannelCredentials; import io.grpc.alts.GoogleDefaultChannelCredentials;
import io.grpc.gcp.observability.GcpObservability;
import io.grpc.internal.GrpcUtil; import io.grpc.internal.GrpcUtil;
import io.grpc.internal.JsonParser; import io.grpc.internal.JsonParser;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
@ -63,10 +62,6 @@ public class TestServiceClient {
TestUtils.installConscryptIfAvailable(); TestUtils.installConscryptIfAvailable();
final TestServiceClient client = new TestServiceClient(); final TestServiceClient client = new TestServiceClient();
client.parseArgs(args); client.parseArgs(args);
GcpObservability gcpObservability = null;
if (enableObservability) {
gcpObservability = GcpObservability.grpcInit();
}
customBackendMetricsLoadBalancerProvider = new CustomBackendMetricsLoadBalancerProvider(); customBackendMetricsLoadBalancerProvider = new CustomBackendMetricsLoadBalancerProvider();
LoadBalancerRegistry.getDefaultRegistry().register(customBackendMetricsLoadBalancerProvider); LoadBalancerRegistry.getDefaultRegistry().register(customBackendMetricsLoadBalancerProvider);
client.setUp(); client.setUp();
@ -76,14 +71,6 @@ public class TestServiceClient {
} finally { } finally {
client.tearDown(); client.tearDown();
} }
if (enableObservability) {
gcpObservability.close();
// TODO(stanleycheung): remove this once the observability exporter plugin is able to
// gracefully flush observability data to cloud at shutdown
final int o11yCloseSleepSeconds = 65;
System.out.println("Sleeping " + o11yCloseSleepSeconds + " seconds before exiting");
Thread.sleep(TimeUnit.MILLISECONDS.convert(o11yCloseSleepSeconds, TimeUnit.SECONDS));
}
System.exit(0); System.exit(0);
} }
@ -111,7 +98,6 @@ public class TestServiceClient {
private int soakOverallTimeoutSeconds = private int soakOverallTimeoutSeconds =
soakIterations * soakPerIterationMaxAcceptableLatencyMs / 1000; soakIterations * soakPerIterationMaxAcceptableLatencyMs / 1000;
private static LoadBalancerProvider customBackendMetricsLoadBalancerProvider; private static LoadBalancerProvider customBackendMetricsLoadBalancerProvider;
private static boolean enableObservability = false;
private Tester tester = new Tester(); private Tester tester = new Tester();
@ -188,8 +174,6 @@ public class TestServiceClient {
soakMinTimeMsBetweenRpcs = Integer.parseInt(value); soakMinTimeMsBetweenRpcs = Integer.parseInt(value);
} else if ("soak_overall_timeout_seconds".equals(key)) { } else if ("soak_overall_timeout_seconds".equals(key)) {
soakOverallTimeoutSeconds = Integer.parseInt(value); soakOverallTimeoutSeconds = Integer.parseInt(value);
} else if ("enable_observability".equals(key)) {
enableObservability = Boolean.parseBoolean(value);
} else { } else {
System.err.println("Unknown argument: " + key); System.err.println("Unknown argument: " + key);
usage = true; usage = true;
@ -260,9 +244,6 @@ public class TestServiceClient {
+ "\n should stop and fail, if the desired number of " + "\n should stop and fail, if the desired number of "
+ "\n iterations have not yet completed. Default " + "\n iterations have not yet completed. Default "
+ c.soakOverallTimeoutSeconds + c.soakOverallTimeoutSeconds
+ "\n --enable_observability=true|false "
+ " Whether to enable GCP Observability. Default "
+ TestServiceClient.enableObservability
); );
System.exit(1); System.exit(1);
} }

View File

@ -26,7 +26,6 @@ import io.grpc.ServerCredentials;
import io.grpc.ServerInterceptors; import io.grpc.ServerInterceptors;
import io.grpc.TlsServerCredentials; import io.grpc.TlsServerCredentials;
import io.grpc.alts.AltsServerCredentials; import io.grpc.alts.AltsServerCredentials;
import io.grpc.gcp.observability.GcpObservability;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.services.MetricRecorder; import io.grpc.services.MetricRecorder;
import io.grpc.xds.orca.OrcaMetricReportingServerInterceptor; import io.grpc.xds.orca.OrcaMetricReportingServerInterceptor;
@ -59,17 +58,11 @@ public class TestServiceServer {
try { try {
System.out.println("Shutting down"); System.out.println("Shutting down");
server.stop(); server.stop();
if (server.enableObservability) {
server.gcpObservability.close();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}); });
if (server.enableObservability) {
server.gcpObservability = GcpObservability.grpcInit();
}
server.start(); server.start();
System.out.println("Server started on port " + server.port); System.out.println("Server started on port " + server.port);
server.blockUntilShutdown(); server.blockUntilShutdown();
@ -82,8 +75,6 @@ public class TestServiceServer {
private ScheduledExecutorService executor; private ScheduledExecutorService executor;
private Server server; private Server server;
private int localHandshakerPort = -1; private int localHandshakerPort = -1;
private boolean enableObservability = false;
private GcpObservability gcpObservability = null;
@VisibleForTesting @VisibleForTesting
void parseArgs(String[] args) { void parseArgs(String[] args) {
@ -120,8 +111,6 @@ public class TestServiceServer {
usage = true; usage = true;
break; break;
} }
} else if ("enable_observability".equals(key)) {
enableObservability = true;
} else { } else {
System.err.println("Unknown argument: " + key); System.err.println("Unknown argument: " + key);
usage = true; usage = true;
@ -143,9 +132,6 @@ public class TestServiceServer {
+ "\n --local_handshaker_port=PORT" + "\n --local_handshaker_port=PORT"
+ "\n Use local ALTS handshaker service on the specified port " + "\n Use local ALTS handshaker service on the specified port "
+ "\n for testing. Only effective when --use_alts=true." + "\n for testing. Only effective when --use_alts=true."
+ "\n --enable_observability=true|false "
+ "\n Whether to enable GCP Observability. Default: "
+ s.enableObservability
); );
System.exit(1); System.exit(1);
} }

View File

@ -55,6 +55,7 @@ include ":grpc-bom"
include ":grpc-rls" include ":grpc-rls"
include ":grpc-authz" include ":grpc-authz"
include ":grpc-gcp-observability" include ":grpc-gcp-observability"
include ":grpc-gcp-observability:interop"
include ":grpc-istio-interop-testing" include ":grpc-istio-interop-testing"
project(':grpc-api').projectDir = "$rootDir/api" as File project(':grpc-api').projectDir = "$rootDir/api" as File
@ -85,6 +86,7 @@ project(':grpc-bom').projectDir = "$rootDir/bom" as File
project(':grpc-rls').projectDir = "$rootDir/rls" as File project(':grpc-rls').projectDir = "$rootDir/rls" as File
project(':grpc-authz').projectDir = "$rootDir/authz" as File project(':grpc-authz').projectDir = "$rootDir/authz" as File
project(':grpc-gcp-observability').projectDir = "$rootDir/gcp-observability" as File project(':grpc-gcp-observability').projectDir = "$rootDir/gcp-observability" as File
project(':grpc-gcp-observability:interop').projectDir = "$rootDir/gcp-observability/interop" as File
project(':grpc-istio-interop-testing').projectDir = "$rootDir/istio-interop-testing" as File project(':grpc-istio-interop-testing').projectDir = "$rootDir/istio-interop-testing" as File
if (settings.hasProperty('skipCodegen') && skipCodegen.toBoolean()) { if (settings.hasProperty('skipCodegen') && skipCodegen.toBoolean()) {