Skip to content

Commit

Permalink
Add Jaeger and Zipkin integration test (aws-observability#261)
Browse files Browse the repository at this point in the history
* add Jaeger and Zipkin trace data emitter

* update dockerfile with VER variable
  • Loading branch information
mxiamxia authored Apr 5, 2021
1 parent 09fdedd commit e64c474
Show file tree
Hide file tree
Showing 58 changed files with 4,006 additions and 4 deletions.
11 changes: 8 additions & 3 deletions load-generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
FROM gradle:6.5.0-jdk11 as builder
FROM gradle as builder

# build
WORKDIR /app
COPY ./build.gradle ./build.gradle
COPY ./src ./src
COPY ./build/ ./build/

# binary version variable --build-arg <VER>=<1.x>
# default 1.0
ARG VER=1.0

RUN gradle build
RUN tar -xvf build/distributions/app.tar
RUN tar -xvf build/distributions/load-generator-${VER}.tar

FROM amazoncorretto:11
WORKDIR /app
COPY --from=builder /app/app .
COPY --from=builder /app/load-generator-${VER} .

ENV OTEL_RESOURCE_ATTRIBUTES 'service.namespace=AWSOTel,service.name=AWSOTelLoadGenerator'

Expand Down
10 changes: 10 additions & 0 deletions load-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@
### StatsD Metrics Load Test Sample Command,
```
./gradlew :load-generator:run --args="metric -r=100 -u=localhost:8125 -d=statsd"
```

### Zipkin Trace Load Test Sample Command,
```
./gradlew :load-generator:run --args="trace -r=100 -u=http://localhost:9411 -d=zipkin"
```

### Jaeger Trace Load Test Sample Command,
```
./gradlew :load-generator:run --args="trace -r=100 -u=http://localhost:14268 -d=jaeger"
```
5 changes: 5 additions & 0 deletions load-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ dependencies {
// log
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'

// local project can't be referenced in Dockerfile
// the workaround is build fat jar and copy it in Dockerfile for building docker image
// implementation files('build/libs/trace-java-client-1.0-all.jar')
implementation project(":trace-java-client")
}

application {
Expand Down
2 changes: 1 addition & 1 deletion load-generator/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ opts=$@

echo ${opts}

validator_path="/app/bin/app"
validator_path="/app/bin/load-generator"

${validator_path} ${opts}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private static Emitter getTraceEmitter(Parameter param) {
return new OtlpTraceEmitter(param);
} else if (param.getDataFormat().equalsIgnoreCase(Constants.XRAY)) {
return new XRayTraceEmitter(param);
} else if (param.getDataFormat().equalsIgnoreCase(Constants.ZIPKIN)) {
return new ZipkinTraceEmitter(param);
} else if (param.getDataFormat().equalsIgnoreCase(Constants.JAEGER)) {
return new JaegerTraceEmitter(param);
} else {
throw new RuntimeException("unknown trace data format specified");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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 com.amazon.opentelemetry.load.generator.emitter;

import com.amazon.opentelemetry.load.generator.factory.AwsTracerConfigurer;
import com.amazon.opentelemetry.load.generator.model.Parameter;
import com.amazon.opentelemetry.trace.client.JaegerTraceEmitClient;
import com.amazon.opentelemetry.trace.client.TraceClient;
import io.grpc.ManagedChannelBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import java.time.Duration;
import java.util.UUID;

public class JaegerTraceEmitter extends TraceEmitter {

private TraceClient client;

public JaegerTraceEmitter(Parameter param) {
super();
this.param = param;
}

@Override
public void emitDataLoad() throws Exception {
this.setupProvider();
this.start(() -> nextDataPoint());
}

@Override
public void setupProvider() throws Exception {
this.client = new JaegerTraceEmitClient(this.param.getEndpoint());
}

@Override
public void nextDataPoint() {
try {
client.emit();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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 com.amazon.opentelemetry.load.generator.emitter;

import com.amazon.opentelemetry.load.generator.model.Parameter;
import com.amazon.opentelemetry.trace.client.TraceClient;
import com.amazon.opentelemetry.trace.client.ZipkinTraceEmitClient;

public class ZipkinTraceEmitter extends TraceEmitter {

private TraceClient client;

public ZipkinTraceEmitter(Parameter param) {
super();
this.param = param;
}

@Override
public void emitDataLoad() throws Exception {
this.setupProvider();
this.start(() -> nextDataPoint());
}

@Override
public void setupProvider() throws Exception {
this.client = new ZipkinTraceEmitClient(this.param.getEndpoint());
}

@Override
public void nextDataPoint() {
try {
client.emit();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class Constants {
public static final String OTLP = "otlp";
public static final String XRAY = "xray";
public static final String STATSD = "statsd";
public static final String ZIPKIN = "zipkin";
public static final String JAEGER = "jaeger";

}
28 changes: 28 additions & 0 deletions sample-apps/jaeger-zipkin-sample-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM gradle as builder

WORKDIR /app
COPY ./build.gradle ./build.gradle
COPY ./src ./src
COPY ./build/ ./build/

# binary version variable --build-arg <VER>=<1.x>
# default 1.0
ARG VER=1.0

RUN gradle build
RUN tar -xvf build/distributions/jaeger-zipkin-sample-app-${VER}.tar

FROM amazoncorretto:11

WORKDIR /app
COPY --from=builder /app/jaeger-zipkin-sample-app-${VER} .

ENV HOME=/root

CMD ["/app/bin/jaeger-zipkin-sample-app"]






52 changes: 52 additions & 0 deletions sample-apps/jaeger-zipkin-sample-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
id 'java'

// Apply the application plugin to add support for building a CLI application.
id 'application'
id 'com.google.cloud.tools.jib' version "2.7.1"
}

group 'com.amazon.sampleapp'
version '1.0'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
mavenCentral()
mavenLocal()
maven {
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
}
flatDir {
dirs 'libs'
}
}

configurations {
extraLibs
}

application {
// Define the main class for the application.
mainClassName = 'com.amazon.sampleapp.App'
}

dependencies {
implementation "com.sparkjava:spark-core:2.9.3"
implementation "com.squareup.okhttp3:okhttp:3.14.8"
implementation "software.amazon.awssdk:s3:2.14.26"
implementation "io.grpc:grpc-api:1.34.1"
implementation "io.grpc:grpc-netty-shaded:1.34.1"

// local project can't be referenced in Dockerfile
// the workaround is build fat jar and copy it in Dockerfile for building docker image
// implementation files('build/libs/trace-java-client-1.0-all.jar')

implementation project(":trace-java-client")


testCompile group: 'junit', name: 'junit', version: '4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.amazon.sampleapp;

import static spark.Spark.exception;
import static spark.Spark.get;
import static spark.Spark.ipAddress;
import static spark.Spark.port;

import com.amazon.opentelemetry.trace.client.JaegerTraceEmitClient;
import com.amazon.opentelemetry.trace.client.TraceClient;
import com.amazon.opentelemetry.trace.client.ZipkinTraceEmitClient;
import java.io.IOException;
import java.io.UncheckedIOException;
import okhttp3.Call;
import okhttp3.OkHttpClient;

public class App {

public static void main(String[] args) throws Exception {

// initialize Jaeger trace emitter client
String collectorUrl = System.getenv("JAEGER_RECEIVER_ENDPOINT");
if (collectorUrl == null) {
collectorUrl = "0.0.0.0:14268";
}
TraceClient jaegerClient = new JaegerTraceEmitClient(collectorUrl);

// initialize Jaeger trace emitter client
collectorUrl = System.getenv("ZIPKIN_RECEIVER_ENDPOINT");
if (collectorUrl == null) {
collectorUrl = "0.0.0.0:9411";
}
TraceClient zipkinClient = new ZipkinTraceEmitClient(collectorUrl);

final Call.Factory httpClient = new OkHttpClient();
String port;
String host;
String listenAddress = System.getenv("LISTEN_ADDRESS");

if (listenAddress == null) {
host = "127.0.0.1";
port = "4567";
} else {
String[] splitAddress = listenAddress.split(":");
host = splitAddress[0];
port = splitAddress[1];
}

// set sampleapp app port number and ip address
port(Integer.parseInt(port));
ipAddress(host);

get(
"/",
(req, res) -> {
return "healthcheck";
});

/** zipkin trace request */
get(
"/outgoing-zipkin-http-call",
(req, res) -> {
String traceId;
try {
traceId = zipkinClient.emit();
} catch (IOException e) {
throw new UncheckedIOException("Could not fetch endpoint", e);
}

return String.format("{\"traceId\": \"%s\"}", traceId);
});

/** jaeger trace request */
get(
"/outgoing-jaeger-http-call",
(req, res) -> {
String traceId;
try {
traceId = jaegerClient.emit();
} catch (IOException e) {
throw new UncheckedIOException("Could not fetch endpoint", e);
}

return String.format("{\"traceId\": \"%s\"}", traceId);
});

exception(
Exception.class,
(exception, request, response) -> {
// Handle the exception here
exception.printStackTrace();
});
}

}
Loading

0 comments on commit e64c474

Please sign in to comment.