From c32c776a70007760aac9e410bae63ecf6f282081 Mon Sep 17 00:00:00 2001 From: John Watson Date: Thu, 16 Apr 2020 15:12:30 -0700 Subject: [PATCH] Provides a way to enable/disable the docker integration tests via a gradle property (#1115) * Provides a way to disable the docker integration tests via a gradle property. * switch the property to be the opposite * add a new make target and let CI use it. * Update gradle.properties Co-Authored-By: Armin Ruech * Update exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java Co-Authored-By: Armin Ruech * Update exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java Co-Authored-By: Armin Ruech * simplify the test flow Co-authored-by: Armin Ruech --- .circleci/config.yml | 2 +- CONTRIBUTING.md | 4 ++ Makefile | 4 ++ build.gradle | 4 ++ .../jaeger/JaegerIntegrationTest.java | 46 +++++++++++-------- gradle.properties | 5 ++ 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ca98bab40c3..bc3788d0c5b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ init_task: &init_task command: make init-git-submodules build_task: &build_task name: Build - command: make test + command: make test-with-docker compile_benchmark_task: &compile_benchmark_task name: Compile JMH command: make benchmark diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddf82ba7196..c23ccbdc7b3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,6 +73,10 @@ Continuous integration builds the project, runs the tests, and runs multiple types of static analysis. 1. Note: Currently, to run the full suite of tests, you'll need to be running a docker daemon. +The tests that require docker are disabled by default. If you wish to run them, +you can enable the docker tests by setting a gradle property of +``"enable.docker.tests"`` to true. See the gradle.properties file in the root of the project +for more details. 2. From the root project directory, initialize repository dependencies diff --git a/Makefile b/Makefile index e1fd21bc85c..8ad77977a6a 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ test: ./gradlew clean assemble check --stacktrace +.PHONY: test-with-docker +test-with-docker: + ./gradlew -Penable.docker.tests=true clean assemble check --stacktrace + .PHONY: benchmark benchmark: ./gradlew compileJmhJava diff --git a/build.gradle b/build.gradle index fad0657f627..8246c4ff1ea 100644 --- a/build.gradle +++ b/build.gradle @@ -177,6 +177,10 @@ subprojects { // see: https://github.com/grpc/grpc-java/issues/3633 compile("javax.annotation:javax.annotation-api:1.3.2") } + + test { + systemProperties project.properties.subMap(["enable.docker.tests"]) + } } javadoc.options { diff --git a/exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java b/exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java index ddeb8fc257e..532a91c3a1c 100644 --- a/exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java +++ b/exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java @@ -23,6 +23,7 @@ import io.opentelemetry.OpenTelemetry; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.trace.export.SimpleSpansProcessor; +import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.trace.Span; import io.opentelemetry.trace.Tracer; import io.restassured.http.ContentType; @@ -30,8 +31,9 @@ import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; import org.awaitility.Awaitility; -import org.junit.Before; +import org.junit.Assume; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,35 +51,43 @@ public class JaegerIntegrationTest { private static final String JAEGER_URL = "http://localhost"; private final Tracer tracer = OpenTelemetry.getTracerProvider().get(getClass().getCanonicalName()); - private JaegerGrpcSpanExporter jaegerExporter; @SuppressWarnings("rawtypes") @ClassRule - public static GenericContainer jaeger = - new GenericContainer("jaegertracing/all-in-one:" + JAEGER_VERSION) - .withExposedPorts(COLLECTOR_PORT, QUERY_PORT) - .waitingFor(new HttpWaitStrategy().forPath("/")); + @Nullable + public static GenericContainer jaegerContainer = null; - @Before - public void setupJaegerExporter() { + static { + // make sure that the user has enabled the docker-based tests + if (Boolean.getBoolean("enable.docker.tests")) { + jaegerContainer = + new GenericContainer<>("jaegertracing/all-in-one:" + JAEGER_VERSION) + .withExposedPorts(COLLECTOR_PORT, QUERY_PORT) + .waitingFor(new HttpWaitStrategy().forPath("/")); + } + } + + @Test + public void testJaegerIntegration() { + Assume.assumeNotNull(jaegerContainer); + setupJaegerExporter(); + imitateWork(); + Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace()); + } + + private static void setupJaegerExporter() { ManagedChannel jaegerChannel = - ManagedChannelBuilder.forAddress("127.0.0.1", jaeger.getMappedPort(COLLECTOR_PORT)) + ManagedChannelBuilder.forAddress("127.0.0.1", jaegerContainer.getMappedPort(COLLECTOR_PORT)) .usePlaintext() .build(); - this.jaegerExporter = + SpanExporter jaegerExporter = JaegerGrpcSpanExporter.newBuilder() .setServiceName(SERVICE_NAME) .setChannel(jaegerChannel) .setDeadlineMs(30000) .build(); OpenTelemetrySdk.getTracerProvider() - .addSpanProcessor(SimpleSpansProcessor.newBuilder(this.jaegerExporter).build()); - } - - @Test - public void testJaegerIntegration() { - imitateWork(); - Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace()); + .addSpanProcessor(SimpleSpansProcessor.newBuilder(jaegerExporter).build()); } private void imitateWork() { @@ -99,7 +109,7 @@ public Boolean call() { String url = String.format( "%s/api/traces?service=%s", - String.format(JAEGER_URL + ":%d", jaeger.getMappedPort(QUERY_PORT)), + String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)), SERVICE_NAME); Response response = given() diff --git a/gradle.properties b/gradle.properties index 1ef00f14aa2..9dc134b48ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,8 @@ org.gradle.parallel=true org.gradle.workers.max=4 org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m + +### Override this property to 'true' to enable the end-to-end tests that use docker. +### This can be done via -Penable.docker.tests=true on the command line, or by +### setting this property to true in the gradle.properties in your home directory. +enable.docker.tests=false