test: end to end opentelemetry test with jaeger exporter (#1038)
* test: end to end opentelemetry test with jaeger exporter * fix: add license header * build: circle ci use machine executor type https://www.testcontainers.org/supported_docker_environment/continuous_integration/circle_ci/ * Update exporters/jaeger/src/test/java/io/opentelemetry/exporters/jaeger/JaegerIntegrationTest.java Co-Authored-By: Giovanni Liva <giovanni.liva@dynatrace.com> * refactor: apply review suggestions * style: apply google code style * docs: add comment explaining why executor type machine * fix: remove setup as it run via @Before Co-authored-by: Giovanni Liva <giovanni.liva@dynatrace.com> Co-authored-by: vladislav-kiva <vladislav.kiva@moneyman.ru>
This commit is contained in:
		
							parent
							
								
									0111714ca7
								
							
						
					
					
						commit
						26d4dbfb4b
					
				| 
						 | 
				
			
			@ -19,6 +19,9 @@ publish_release_task: &publish_release_task
 | 
			
		|||
  name: Publish Release Artifacts
 | 
			
		||||
  command: make publish-release-artifacts
 | 
			
		||||
 | 
			
		||||
#for test containers https://www.testcontainers.org/supported_docker_environment/continuous_integration/circle_ci/
 | 
			
		||||
executorType: machine
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  build:
 | 
			
		||||
    environment:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,6 +125,8 @@ subprojects {
 | 
			
		|||
                truth                : 'com.google.truth:truth:1.0.1',
 | 
			
		||||
                slf4jsimple          : 'org.slf4j:slf4j-simple:1.7.25', // Compatibility layer
 | 
			
		||||
                awaitility           : 'org.awaitility:awaitility:3.0.0', // Compatibility layer
 | 
			
		||||
                testcontainers       : 'org.testcontainers:testcontainers:1.13.0',
 | 
			
		||||
                rest_assured         : 'io.rest-assured:rest-assured:4.2.0',
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,11 @@ dependencies {
 | 
			
		|||
            libraries.protobuf,
 | 
			
		||||
            libraries.protobuf_util
 | 
			
		||||
 | 
			
		||||
    testImplementation "io.grpc:grpc-testing:${grpcVersion}"
 | 
			
		||||
    testImplementation "io.grpc:grpc-testing:${grpcVersion}",
 | 
			
		||||
            libraries.testcontainers,
 | 
			
		||||
            libraries.awaitility,
 | 
			
		||||
            libraries.rest_assured
 | 
			
		||||
 | 
			
		||||
    testRuntime "io.grpc:grpc-netty-shaded:${grpcVersion}"
 | 
			
		||||
 | 
			
		||||
    signature "org.codehaus.mojo.signature:java17:1.0@signature"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,121 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2020, OpenTelemetry 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.opentelemetry.exporters.jaeger;
 | 
			
		||||
 | 
			
		||||
import static io.restassured.RestAssured.given;
 | 
			
		||||
 | 
			
		||||
import io.grpc.ManagedChannel;
 | 
			
		||||
import io.grpc.ManagedChannelBuilder;
 | 
			
		||||
import io.opentelemetry.OpenTelemetry;
 | 
			
		||||
import io.opentelemetry.sdk.OpenTelemetrySdk;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.SimpleSpansProcessor;
 | 
			
		||||
import io.opentelemetry.trace.Span;
 | 
			
		||||
import io.opentelemetry.trace.Tracer;
 | 
			
		||||
import io.restassured.http.ContentType;
 | 
			
		||||
import io.restassured.response.Response;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.concurrent.Callable;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import org.awaitility.Awaitility;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.ClassRule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.runner.RunWith;
 | 
			
		||||
import org.junit.runners.JUnit4;
 | 
			
		||||
import org.testcontainers.containers.GenericContainer;
 | 
			
		||||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
 | 
			
		||||
 | 
			
		||||
@RunWith(JUnit4.class)
 | 
			
		||||
public class JaegerIntegrationTest {
 | 
			
		||||
 | 
			
		||||
  private static final int QUERY_PORT = 16686;
 | 
			
		||||
  private static final int COLLECTOR_PORT = 14250;
 | 
			
		||||
  private static final String JAEGER_VERSION = "1.17";
 | 
			
		||||
  private static final String SERVICE_NAME = "E2E-test";
 | 
			
		||||
  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("/"));
 | 
			
		||||
 | 
			
		||||
  @Before
 | 
			
		||||
  public void setupJaegerExporter() {
 | 
			
		||||
    ManagedChannel jaegerChannel =
 | 
			
		||||
        ManagedChannelBuilder.forAddress("127.0.0.1", jaeger.getMappedPort(COLLECTOR_PORT))
 | 
			
		||||
            .usePlaintext()
 | 
			
		||||
            .build();
 | 
			
		||||
    this.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());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void imitateWork() {
 | 
			
		||||
    Span span = this.tracer.spanBuilder("Test span").startSpan();
 | 
			
		||||
    span.addEvent("some event");
 | 
			
		||||
    try {
 | 
			
		||||
      Thread.sleep(1000);
 | 
			
		||||
    } catch (InterruptedException e) {
 | 
			
		||||
      throw new RuntimeException(e);
 | 
			
		||||
    }
 | 
			
		||||
    span.end();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Callable<Boolean> assertJaegerHaveTrace() {
 | 
			
		||||
    return new Callable<Boolean>() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public Boolean call() {
 | 
			
		||||
        try {
 | 
			
		||||
          String url =
 | 
			
		||||
              String.format(
 | 
			
		||||
                  "%s/api/traces?service=%s",
 | 
			
		||||
                  String.format(JAEGER_URL + ":%d", jaeger.getMappedPort(QUERY_PORT)),
 | 
			
		||||
                  SERVICE_NAME);
 | 
			
		||||
          Response response =
 | 
			
		||||
              given()
 | 
			
		||||
                  .headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
 | 
			
		||||
                  .when()
 | 
			
		||||
                  .get(url)
 | 
			
		||||
                  .then()
 | 
			
		||||
                  .contentType(ContentType.JSON)
 | 
			
		||||
                  .extract()
 | 
			
		||||
                  .response();
 | 
			
		||||
          Map<String, String> path = response.jsonPath().getMap("data[0]");
 | 
			
		||||
          return path.get("traceID") != null;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
<configuration>
 | 
			
		||||
 | 
			
		||||
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 | 
			
		||||
    <!-- encoders are assigned the type
 | 
			
		||||
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
 | 
			
		||||
    <encoder>
 | 
			
		||||
      <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
 | 
			
		||||
    </encoder>
 | 
			
		||||
  </appender>
 | 
			
		||||
 | 
			
		||||
  <root level="INFO">
 | 
			
		||||
    <appender-ref ref="STDOUT"/>
 | 
			
		||||
  </root>
 | 
			
		||||
</configuration>
 | 
			
		||||
		Loading…
	
		Reference in New Issue