forked from aws-observability/aws-otel-test-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Jaeger and Zipkin integration test (aws-observability#261)
* add Jaeger and Zipkin trace data emitter * update dockerfile with VER variable
- Loading branch information
Showing
58 changed files
with
4,006 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...tor/src/main/java/com/amazon/opentelemetry/load/generator/emitter/JaegerTraceEmitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...tor/src/main/java/com/amazon/opentelemetry/load/generator/emitter/ZipkinTraceEmitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
112 changes: 112 additions & 0 deletions
112
sample-apps/jaeger-zipkin-sample-app/src/main/java/com/amazon/sampleapp/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.