From e309a7e2c75bc5d2047ca30aff0be37af1627aff Mon Sep 17 00:00:00 2001 From: oibe Date: Wed, 27 Jul 2016 09:15:32 -0700 Subject: [PATCH] Add crossdock tests (#17) --- .travis.yml | 17 ++ Makefile | 2 +- build.gradle | 1 + jaeger-java-crossdock/Dockerfile | 6 + jaeger-java-crossdock/build.gradle | 66 +++++++ jaeger-java-crossdock/docker-compose.yml | 52 ++++++ jaeger-java-crossdock/rules.mk | 21 +++ .../com/uber/jaeger/crossdock/Constants.java | 28 +++ .../uber/jaeger/crossdock/JerseyServer.java | 110 ++++++++++++ .../deserializers/DownstreamDeserializer.java | 53 ++++++ .../JoinTraceRequestDeserializer.java | 52 ++++++ .../ObservedSpanDeserializer.java | 46 +++++ .../StartTraceRequestDeserializer.java | 55 ++++++ .../TraceResponseDeserializer.java | 58 +++++++ .../resources/behavior/ExceptionMapper.java | 33 ++++ .../behavior/http/TraceBehaviorResource.java | 131 ++++++++++++++ .../tchannel/JoinTraceThriftHandler.java | 38 +++++ .../behavior/tchannel/TChannelServer.java | 49 ++++++ .../resources/health/HealthResource.java | 37 ++++ .../serializers/DownstreamSerializer.java | 50 ++++++ .../serializers/ObservedSpanSerializer.java | 43 +++++ .../serializers/TraceResponseSerializer.java | 51 ++++++ .../tracetest_manual/Downstream.java | 81 +++++++++ .../tracetest_manual/JoinTraceRequest.java | 49 ++++++ .../tracetest_manual/ObservedSpan.java | 58 +++++++ .../tracetest_manual/StartTraceRequest.java | 62 +++++++ .../tracetest_manual/TraceResponse.java | 71 ++++++++ .../src/main/thrift/tracetest.thrift | 47 +++++ .../http/TraceBehaviorResourceTest.java | 161 ++++++++++++++++++ settings.gradle | 1 + travis/publish_docker_image.sh | 18 ++ 31 files changed, 1546 insertions(+), 1 deletion(-) create mode 100644 jaeger-java-crossdock/Dockerfile create mode 100644 jaeger-java-crossdock/build.gradle create mode 100644 jaeger-java-crossdock/docker-compose.yml create mode 100644 jaeger-java-crossdock/rules.mk create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/Constants.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/JerseyServer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/DownstreamDeserializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/JoinTraceRequestDeserializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/ObservedSpanDeserializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/StartTraceRequestDeserializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/TraceResponseDeserializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/ExceptionMapper.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResource.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/TChannelServer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/health/HealthResource.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/DownstreamSerializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/ObservedSpanSerializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/TraceResponseSerializer.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/Downstream.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/JoinTraceRequest.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/ObservedSpan.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/StartTraceRequest.java create mode 100644 jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/TraceResponse.java create mode 100644 jaeger-java-crossdock/src/main/thrift/tracetest.thrift create mode 100644 jaeger-java-crossdock/src/test/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java create mode 100644 travis/publish_docker_image.sh diff --git a/.travis.yml b/.travis.yml index 5c5c63f9c..6bb54b231 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,33 @@ sudo: required + language: java + services: - docker + env: global: - DOCKER_VERSION=1.11.1-0~trusty - DOCKER_COMPOSE_VERSION=1.7.0 - COMMIT=${TRAVIS_COMMIT::8} + # SONATYPE_USERNAME= - secure: PRiEM4oGX4yjIzQlGMg+C28LdrkikUO8fsCXul0O+mJQ6Yua3b+G9HOC586UvyqAY4mFvSGP/EIefBuRLVQhFKvHpxHtfjpGg3w2Txq9KxiY5DjaYFuihKPz8Zs+PAZXd8rWqQvjZFkpHHmXdQG5I4MRSCb5Pkk/T3uwJqDCpcQeaBxWIglwVm4etM4pBxQT7BCVKvh4CJ6vNJuLPRRqn4CqgnZV9ytcrUoOF3binbdP2S2KImBqimAyLW3ThqTaJ2xkGWTKI7oc3k2NCejIFUPcf9dzzZ4aKKu9x9t94v7QSwLOE+9tQh5F0W3C89qcG9SmPVaTS7QwQhKwFP92BfMbobu056VSxSFielQ5DvPTaAiStGBzr/2Uhn+KITjSRNj6dX6tjaL9q/8TFE+g0QZIP00PhfzzNOde5Nlh8fUu3bo+4X6Y+WPXHEe8SfLdVYIb6+1zvxkNyWHQoeN+uDGIDSOgWYT74tz0HBcpt2WIrOPaSc6m6RaZKC8dOuWODY+HRZXetwvsYa/aw+Y/7aGJgh7oJqNM5/D2Cc9tp/Q81J5pGZZEjNF+lcjMX8A8COk4TKtd9SbL+a5BeNUOcu8wWJZ/5vEHi2MaghfCr0xVDqQVrKbHQS1UH/qnholpUOD35iP4wVl9r3ftee1yuH35ZNFUZIGlAmLhvZ5LQgY= + # SONATYPE_PASSWORD= - secure: gqAqV1tCjiqAzbreGsgvlcXCg9M7MLyyc+9v7/booL+eNqjevQ25CEzLSBoQQnJAKNDixHloCwCxRIbCrc3HcAl/8V6NZ8JxzUPoxKzN3yr4SPyD+KcJSNDwPqCHScKnMbuBPGKPcZFng2XyIpKAAAzqmc+zMpKRBdos4l27l5b4NdPHJUPRgFpqyL2oZY5nzeqzB/akP1c0jOZOSbfl4JVdXflYAWiXtA3zesVCJcrsYrQQ/xpL4ziETqy9UFZnMcBH9KADx6gCyoZMsf9OfVCGl0YGBb1LECIUYi/74b8TPp18+oUNYnpZScsOHmUSdmFrkIb/y714OIYPDQPhpny/aPXkBHH2ze+7AQGHNPoNJJZsG/W7/pj4AH91HGLVBxGApuA95WNFoIglHWtII+uvraeiTWaeC6VYOrwDdLHy5Aijtr1lH+zqFOfzSWGyj6Blt8x3aKsZmnFA4b8h+l0y+VjEFqmZIf9yKLlShieyhCWdZtIEwmeB120zbFIJHRfHClOs7Zwel4uE2HCJVSqP24auhA5j7uHYPBBSD/+VZRoeDiDE0qjRO0ZeXAUP6EIrplZecDWZXYZhW6XOHWpHittbCAisz2m43DEXSunISrLS5ONkjeDUfn42q24c80/gwPlG+7zLynwrJ1sO7EHECPhoPmUpilaQ+j4kmt4= + # DOCKER_USERNAME= + - secure: q19fJLh2aO583rOALLKor4FeQr5u3EWKtUNhOyrUR9k7FLVk/9cLIrLr77DWdYxn0DE123DeHHm+GB7vEL85DmhJXUy3Bqpkjqr/eOZwtzGuCeDY9q7pO3eJJ8V3Fhw0p9rvGq1yg/nEO6S9whE+IUFxUanSIsjltM93KEfeaOGEvi5vkfKoD1etgGh8tx3d69Q17SyfHl+xRMW4KOVe3vdjUUnFPINhqmjKaYRmbsZ3yx7cuX+i6qbpW3Biypy/zjeu/35CfjQIiB8rgo8G6qtbGj9gfMzt3xmDL2LEOJtIx4nDJ3wPMVsGUGbu8LhNzX71EddbnqdWwjLnyoYAEYynu13q8rHljA+NlT8mPBP4wX00TTtJoWmwCmMnWgRcFPMS50cVBDwLLANZcVPU6iNY/+0AE4ANlzWHDLD/0pTqvYB5Z2UIVbXPuvkys7xBL5pKFnqTXVlWQuTRkSO8PXnSo24QP04AcjlkHnqNPesjkztFh4DSOfyL/6BiLebKDo6C+KNcN6Ep9SYpVfkwYDLV2qtfbiLxu4wjAgQjxPk701VGMfywmMvHaqa7UQpXQfEvHM/kTYJGknqf80WvXo/ilnvb9esANEP6cJZ3Z9h7Sq9P/ytec5NqPRaKVaMmN5bJXNY30g7MLkyD1fAMKIkaUfFdKNFzZVAAmsC7fho= + # DOCKER_PASSWORD= + - secure: aj5LcCTpFS+e/bgOkyteSj85SplvGAgeje+Rbo8C5jgxScnHutalAEECnlXJBvxdke8OE4s+J8dX4cKoHf0XXial8hwEwfm+r/wPeTpr06L0eleBGfGsiF0dsYApIs3EmIoA+4x3LGB0BTta/XOfNzj9TFkaf3NExn6GClXAzx51tyJm3C8Yt3OP756dga8opU8iIBvKIA7bgn2pOs7xBSd2Dx7J8jBsw3uBXKtpyVLj6n7fl0EaVEVpF9Od7ASeJ0+P9x2pEkiqZhuMHm4mj+BaUqIJABRZ93PqiEDxHG/pnoJiIbXVis3LFTxFKQVYLG53eoZuww1h09TW+m1oDe6cNpkt7TanaKZ8a5oT/sgHUZHzP5Tlvv8UiqcaTQDlxaszYgcOZkfRHctMNVc0Wyr0QEft77c0jsK8lCyudzMhXKxj+MFoYxkUx61vBWQvnToJdP1YHk0c7YWzPADEIwRG2v2rXZvx1CmWcMDtxtcU+gSrtcD/8GMFuKKHDV7EAvApKSLl5OoAioHPVZLNvZbrPFaVV6dpdrGB3kkWNf+WSu6F0IG/CCGStykJbNivyBYv87Ngs6iAVKYUW2uiuICd8Eb+Ak/J2T05t1kJaZRwfzXKVGAOHdn3lloah8bSGRPhbvT3PwkRXPwYRHL/jE5g/el0Bq1LI3tn/6VyDhM= before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ - $HOME/.thrift-build + before_install: - apt-cache madison docker-engine - sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION} @@ -28,8 +39,14 @@ before_install: - sudo mv docker-compose /usr/local/bin - docker-compose version - bash travis/install-thrift.sh + script: - make test +- make crossdock-fresh + after_success: - ./gradlew jacocoTestReport coveralls - ./gradlew uploadArchives -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" + +after_script: +- bash travis/publish_docker_image.sh diff --git a/Makefile b/Makefile index b3be65952..1548ab2e9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ - +-include jaeger-java-crossdock/rules.mk .PHONY: clean clean: diff --git a/build.gradle b/build.gradle index 76d7d49d0..36fa392ff 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id "jacoco" id "com.github.kt3k.coveralls" version "2.5.0" id "com.github.hierynomus.license" version "0.12.1" + id "com.github.johnrengelman.shadow" version "1.2.3" } diff --git a/jaeger-java-crossdock/Dockerfile b/jaeger-java-crossdock/Dockerfile new file mode 100644 index 000000000..1ac606b7a --- /dev/null +++ b/jaeger-java-crossdock/Dockerfile @@ -0,0 +1,6 @@ +FROM maven:3.3-jdk-7 +EXPOSE 8080-8082 + +ADD build/libs/jaeger-java-crossdock.jar / + +CMD ["java", "-jar", "jaeger-java-crossdock.jar"] diff --git a/jaeger-java-crossdock/build.gradle b/jaeger-java-crossdock/build.gradle new file mode 100644 index 000000000..404e08e7e --- /dev/null +++ b/jaeger-java-crossdock/build.gradle @@ -0,0 +1,66 @@ +apply plugin: 'jacoco' +apply plugin: 'com.github.kt3k.coveralls' +apply plugin: 'com.github.johnrengelman.shadow' + + +description = 'A jaeger instrumented java server meant for testing interoperability with different Jaeger clients through the use of crossdock (https://github.com/crossdock/crossdock)' +ext.jacksonVersion = '2.7.4' +shadowJar.archiveName = 'jaeger-java-crossdock.jar' + +dependencies { + compile project(':jaeger-jaxrs2') + + compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion + compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: jerseyVersion + compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: jerseyVersion + compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: jerseyVersion + compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: jerseyVersion + compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.12' + compile group: 'javax.servlet', name: 'servlet-api', version: '2.5' + compile group: 'com.uber.tchannel', name: 'tchannel-core', version: '0.4.1' + + + // Testing Frameworks + testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.16' + testCompile group: 'junit', name: 'junit', version: '4.12' +} + +jacocoTestReport { + reports { + xml.enabled = true // coveralls plugin depends on xml format report + html.enabled = true + html.destination "${buildDir}/jacocoHtml" + } + + afterEvaluate { + classDirectories = files(classDirectories.files.collect { + fileTree(dir: it, + exclude: [ + '**/*Test*', + ]) + }) + } +} + +sourceSets { + main { + java { + srcDir 'src/main/java' + } + } + + test { + java { + srcDir 'src/test/java' + } + } +} + +jar { + from sourceSets.main.output + from sourceSets.test.output + manifest { + attributes('Implementation-jaeger-java-crossdock': 'jaeger-java-crossdock', 'Implementation-Version': project.version) + attributes 'Main-Class': 'com.uber.jaeger.crossdock.JerseyServer' + } +} diff --git a/jaeger-java-crossdock/docker-compose.yml b/jaeger-java-crossdock/docker-compose.yml new file mode 100644 index 000000000..af1b8f497 --- /dev/null +++ b/jaeger-java-crossdock/docker-compose.yml @@ -0,0 +1,52 @@ +version: '2' + +services: + crossdock: + image: crossdock/crossdock + links: + - go + - java + environment: + - WAIT_FOR=go,java + + - AXIS_CLIENT=go + - AXIS_S1NAME=go,java + - AXIS_SAMPLED=true,false + - AXIS_S2NAME=go,java + - AXIS_S2TRANSPORT=http,tchannel + - AXIS_S3NAME=go,java + - AXIS_S3TRANSPORT=http,tchannel + + - BEHAVIOR_TRACE=client,s1name,sampled,s2name,s2transport,s3name,s3transport + + - REPORT=compact + go: + image: jaegertracing/xdock-go + ports: + - "8080-8082" + + java: + build: . + ports: + - "8080-8082" +# node: +# image: yarpc/yarpc-node +# ports: +# - "8080-8082" +# +# java: +# image: yarpc/yarpc-java +# ports: +# - "8080-8082" +# +# python: +# image: yarpc/yarpc-python +# ports: +# - "8080:8082" +# +# python-sync: +# image: yarpc/yarpc-python +# ports: +# - 8080 +# environment: +# - SYNC=1 diff --git a/jaeger-java-crossdock/rules.mk b/jaeger-java-crossdock/rules.mk new file mode 100644 index 000000000..7153bc495 --- /dev/null +++ b/jaeger-java-crossdock/rules.mk @@ -0,0 +1,21 @@ +PROJCT=jaeger-java-crossdock +XDOCK_YAML=$(PROJCT)/docker-compose.yml + +.PHONY: crossdock +crossdock: gradle-compile + docker-compose -f $(XDOCK_YAML) kill java + docker-compose -f $(XDOCK_YAML) rm -f java + docker-compose -f $(XDOCK_YAML) build java + docker-compose -f $(XDOCK_YAML) run crossdock 2>&1 | tee run-crossdock.log + grep 'Tests passed!' run-crossdock.log + +.PHONY: crossdock-fresh +crossdock-fresh: gradle-compile + docker-compose -f $(XDOCK_YAML) kill + docker-compose -f $(XDOCK_YAML) rm --force + docker-compose -f $(XDOCK_YAML) pull + docker-compose -f $(XDOCK_YAML) build + docker-compose -f $(XDOCK_YAML) run crossdock + +gradle-compile: + ./gradlew clean :jaeger-java-crossdock:shadowJar diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/Constants.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/Constants.java new file mode 100644 index 000000000..86a3c629d --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/Constants.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock; + +public class Constants { + public final static String BAGGAGE_KEY = "crossdock-baggage-key"; + public final static String TRANSPORT_HTTP = "HTTP"; + public final static String TRANSPORT_TCHANNEL = "TCHANNEL"; +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/JerseyServer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/JerseyServer.java new file mode 100644 index 000000000..d04f462cc --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/JerseyServer.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock; + +import java.net.URI; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; + +import com.uber.jaeger.context.TraceContext; +import com.uber.jaeger.crossdock.resources.behavior.ExceptionMapper; +import com.uber.jaeger.crossdock.resources.behavior.http.TraceBehaviorResource; +import com.uber.jaeger.crossdock.resources.behavior.tchannel.TChannelServer; +import com.uber.jaeger.crossdock.resources.health.HealthResource; +import com.uber.jaeger.Configuration.ReporterConfiguration; +import com.uber.jaeger.Configuration.SamplerConfiguration; +import com.uber.jaeger.filters.jaxrs2.Configuration; +import com.uber.jaeger.filters.jaxrs2.TracingUtils; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.filter.LoggingFilter; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.server.ResourceConfig; + +public class JerseyServer { + private final HttpServer server; + public static Client client; + public final static String SERVICE_NAME = "java"; + + + public JerseyServer(String hostPort, Class... resourceClasses) { + final String samplingType = SamplerConfiguration.CONST; + final Number samplingParam = 0; + final boolean disable = false; + final boolean logging = true; + + final Configuration config = new Configuration(SERVICE_NAME, disable, + new SamplerConfiguration(samplingType, samplingParam), + new ReporterConfiguration(logging, null, null, null, null)); + + // create a resource config that scans for JAX-RS resources and providers + final ResourceConfig rc = new ResourceConfig(); + + for (Class clz : resourceClasses) { + rc.packages(clz.getPackage().getName()); + } + + rc.register(TracingUtils.serverFilter(config)) + .register(LoggingFilter.class) + .register(ExceptionMapper.class) + .register(JacksonFeature.class) + .register( + new AbstractBinder() { + @Override + protected void configure() { + bind(config).to(Configuration.class); + } + }); + + // create and start a new instance of grizzly http server + // exposing the Jersey application at BASE_URI + String baseURI = String.format("http://%s/", hostPort); + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseURI), rc); + client = initializeClient(config); + } + + private static Client initializeClient(final Configuration config) { + return ClientBuilder.newClient() + .register(ExceptionMapper.class) + .register(TracingUtils.clientFilter(config)) + .register( + new AbstractBinder() { + @Override + protected void configure() { + bind(TracingUtils.getTraceContext()).to(TraceContext.class); + } + }) + .register(JacksonFeature.class); + } + + public void shutdown() { + server.shutdown(); + } + + public static void main(String[] args) throws Exception { + new JerseyServer("0.0.0.0:8081", TraceBehaviorResource.class); + new TChannelServer(8082).start(); + new JerseyServer("0.0.0.0:8080", HealthResource.class); + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/DownstreamDeserializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/DownstreamDeserializer.java new file mode 100644 index 000000000..4cd36832f --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/DownstreamDeserializer.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.deserializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; + +public class DownstreamDeserializer extends JsonDeserializer { + private static final ObjectMapper mapper = new ObjectMapper(); + + @Override + public Downstream deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + JsonNode node = jp.getCodec().readTree(jp); + String serviceName = node.get("serviceName").asText(); + String host = node.get("host").asText(); + String port = node.get("port").asText(); + String transport = node.get("transport").asText(); + String serverRole = node.get("serverRole").asText(); + + JsonNode downstreamNode = node.get("downstream"); + Downstream downstream = null; + if (downstreamNode != null) { + downstream = mapper.reader(Downstream.class).readValue(downstreamNode); + } + + return new Downstream(serviceName, host, port, transport, serverRole, downstream); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/JoinTraceRequestDeserializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/JoinTraceRequestDeserializer.java new file mode 100644 index 000000000..e5c84cfe8 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/JoinTraceRequestDeserializer.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.deserializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; +import com.uber.jaeger.crossdock.tracetest_manual.JoinTraceRequest; + +public class JoinTraceRequestDeserializer extends JsonDeserializer { + private final ObjectMapper mapper = new ObjectMapper(); + + @Override + public JoinTraceRequest deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jp.getCodec().readTree(jp); + + System.out.println("join trace request: " + node.toString()); + + String serverRole = node.get("serverRole").asText(); + JsonNode downstreamNode = node.get("downstream"); + Downstream downstream = null; + if (downstreamNode != null) { + downstream = mapper.reader(Downstream.class).readValue(downstreamNode); + } + + return new JoinTraceRequest(serverRole, downstream); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/ObservedSpanDeserializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/ObservedSpanDeserializer.java new file mode 100644 index 000000000..86e650d95 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/ObservedSpanDeserializer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.deserializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; + +public class ObservedSpanDeserializer extends JsonDeserializer { + private static final ObjectMapper mapper = new ObjectMapper(); + + @Override + public ObservedSpan deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + JsonNode node = jp.getCodec().readTree(jp); + + String traceId = node.get("traceId").asText(); + boolean sampled = node.get("sampled").asBoolean(); + String baggage = node.get("baggage").asText(); + + return new ObservedSpan(traceId, sampled, baggage); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/StartTraceRequestDeserializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/StartTraceRequestDeserializer.java new file mode 100644 index 000000000..d6e928a3d --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/StartTraceRequestDeserializer.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.deserializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; +import com.uber.jaeger.crossdock.tracetest_manual.StartTraceRequest; + +public class StartTraceRequestDeserializer extends JsonDeserializer { + private final ObjectMapper mapper = new ObjectMapper(); + + @Override + public StartTraceRequest deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jp.getCodec().readTree(jp); + + System.out.println("start trace request: " + node.toString()); + + String serverRole = node.get("serverRole").asText(); + boolean sampled = node.get("sampled").asBoolean(); + String baggage = node.get("baggage").asText(); + + JsonNode downstreamNode = node.get("downstream"); + Downstream downstream = null; + if (downstreamNode != null) { + downstream = mapper.reader(Downstream.class).readValue(downstreamNode); + } + + return new StartTraceRequest(serverRole, sampled, baggage, downstream); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/TraceResponseDeserializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/TraceResponseDeserializer.java new file mode 100644 index 000000000..268faba56 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/deserializers/TraceResponseDeserializer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.deserializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; +import com.uber.jaeger.crossdock.tracetest_manual.TraceResponse; + +public class TraceResponseDeserializer extends JsonDeserializer { + private static final ObjectMapper mapper = new ObjectMapper(); + + @Override + public TraceResponse deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + JsonNode node = jp.getCodec().readTree(jp); + + System.out.println("Trace Response: " + node); + + String notImplementedError = node.get("notImplementedError").asText(); + + ObservedSpan span = null; + if (notImplementedError.equals("")) { + span = mapper.reader(ObservedSpan.class).readValue(node.get("span")); + } + + TraceResponse downstream = null; + JsonNode downstreamNode = node.get("downstream"); + if (downstreamNode != null) { + downstream = mapper.reader(TraceResponse.class).readValue(downstreamNode); + } + + return new TraceResponse(notImplementedError, span, downstream); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/ExceptionMapper.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/ExceptionMapper.java new file mode 100644 index 000000000..d6e921b97 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/ExceptionMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.behavior; + +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; + +@Provider +public class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper { + public Response toResponse(Exception exception) { + exception.printStackTrace(); + return Response.status(500).build(); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResource.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResource.java new file mode 100644 index 000000000..bd8db6933 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResource.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.behavior.http; + +import java.io.IOException; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.uber.jaeger.Span; +import com.uber.jaeger.TraceContext; +import com.uber.jaeger.crossdock.Constants; +import com.uber.jaeger.crossdock.JerseyServer; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; +import com.uber.jaeger.crossdock.tracetest_manual.JoinTraceRequest; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; +import com.uber.jaeger.crossdock.tracetest_manual.StartTraceRequest; +import com.uber.jaeger.crossdock.tracetest_manual.TraceResponse; +import com.uber.jaeger.filters.jaxrs2.TracingUtils; +import io.opentracing.tag.Tags; + +@Path("") +@Provider +public class TraceBehaviorResource { + private ObjectMapper mapper = new ObjectMapper(); + + @POST + @Path("start_trace") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public TraceResponse startTrace(StartTraceRequest startRequest) throws IOException { + Span span = (Span) TracingUtils.getTraceContext().getCurrentSpan(); + String baggage = startRequest.getBaggage(); + span.setBaggageItem(Constants.BAGGAGE_KEY, baggage); + if (startRequest.getSampled()) { + Tags.SAMPLING_PRIORITY.set(span, (short) 1); + } + + TraceResponse response = prepareResponse(startRequest.getDownstream()); + + System.out.println("start_trace response: " + mapper.writeValueAsString(response)); + + return response; + } + + @POST + @Path("join_trace") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public TraceResponse joinTrace(JoinTraceRequest joinRequest) throws IOException { + TraceResponse response = prepareResponse(joinRequest.getDownstream()); + System.out.println("join_trace response: " + mapper.writeValueAsString(response)); + return response; + } + + private TraceResponse prepareResponse(Downstream downstream) throws IOException { + TraceResponse response = new TraceResponse(observeSpan()); + + if (downstream != null) { + TraceResponse downstreamResponse = callDownstream(downstream); + response.setDownstream(downstreamResponse); + } + + return response; + } + + private TraceResponse callDownstream(Downstream downstream) throws IOException { + String transport = downstream.getTransport(); + switch (transport) { + case Constants.TRANSPORT_HTTP: + return callDownstreamHTTP(downstream); + case Constants.TRANSPORT_TCHANNEL: + return new TraceResponse("TChannel support not implemented for java"); + default: + throw new IllegalArgumentException("Unrecognized transport received: %s" + transport); + } + } + + private TraceResponse callDownstreamHTTP(Downstream downstream) throws IOException { + String downstreamURL = String.format("http://%s:%s/join_trace", downstream.getHost(), downstream.getPort()); + + System.out.println(String.format("Calling downstream service %s at %s", downstream.getServiceName(), downstreamURL)); + + Response resp = JerseyServer.client.target(downstreamURL) + .request(MediaType.APPLICATION_JSON) + .post(Entity.json(new JoinTraceRequest(downstream.getServerRole(), downstream.getDownstream()))); + + String respStr = resp.readEntity(String.class); + return mapper.readValue(respStr, TraceResponse.class); + } + + private ObservedSpan observeSpan() { + com.uber.jaeger.context.TraceContext traceContext = TracingUtils.getTraceContext(); + Span span = (Span) traceContext.getCurrentSpan(); + if (span == null) { + throw new IllegalStateException("null span received in observeSpan"); + } + + TraceContext context = span.getContext(); + String traceID = String.format("%x", context.getTraceID()); + boolean sampled = context.isSampled(); + String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY); + return new ObservedSpan(traceID, sampled, baggage); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java new file mode 100644 index 000000000..eb7a857e3 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.behavior.tchannel; + +import com.uber.jaeger.crossdock.tracetest.TraceResponse; +import com.uber.jaeger.crossdock.tracetest.TracedService; +import com.uber.tchannel.api.handlers.ThriftRequestHandler; +import com.uber.tchannel.messages.ThriftRequest; +import com.uber.tchannel.messages.ThriftResponse; + +public class JoinTraceThriftHandler extends ThriftRequestHandler { + + @Override + public ThriftResponse handleImpl(ThriftRequest request) { + return new ThriftResponse.Builder(request) + .setBody(new TracedService.joinTrace_result(new TraceResponse("TChannel not implemented for java."))) + .build(); + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/TChannelServer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/TChannelServer.java new file mode 100644 index 000000000..ce8a86746 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/tchannel/TChannelServer.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.behavior.tchannel; + +import com.uber.jaeger.crossdock.JerseyServer; +import com.uber.tchannel.api.TChannel; + +public class TChannelServer { + private final TChannel server; + + public TChannelServer(int port) { + server = new TChannel.Builder(JerseyServer.SERVICE_NAME) + .setServerPort(port) + .build(); + + server.makeSubChannel(JerseyServer.SERVICE_NAME) + .registerHealthHandler() + .register("TracedService::joinTrace", new JoinTraceThriftHandler()); + + } + + public void start() throws InterruptedException { + // listen for incoming connections + server.listen().channel().closeFuture(); + } + + public void shutdown() { + server.shutdown(true); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/health/HealthResource.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/health/HealthResource.java new file mode 100644 index 000000000..c5b8a34ab --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/health/HealthResource.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.health; + +import javax.ws.rs.HEAD; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; + +@Path("") +@Provider +public class HealthResource { + @HEAD + @Path("/") + public Response heathCheck() { + return Response.ok().build(); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/DownstreamSerializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/DownstreamSerializer.java new file mode 100644 index 000000000..c66c45d8f --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/DownstreamSerializer.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.serializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; + +public class DownstreamSerializer extends JsonSerializer { + + @Override + public void serialize(Downstream downstream, + JsonGenerator jgen, + SerializerProvider sp) throws IOException { + jgen.writeStartObject(); + jgen.writeStringField("serviceName", downstream.getServiceName()); + jgen.writeStringField("host", downstream.getHost()); + jgen.writeStringField("port", downstream.getPort()); + jgen.writeStringField("transport", downstream.getTransport()); + jgen.writeStringField("serverRole", downstream.getServerRole()); + + Downstream level2Downstream = downstream.getDownstream(); + if (level2Downstream != null) { + jgen.writeObjectField("downstream", downstream.getDownstream()); + } + jgen.writeEndObject(); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/ObservedSpanSerializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/ObservedSpanSerializer.java new file mode 100644 index 000000000..a52592fcb --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/ObservedSpanSerializer.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.serializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; + +public class ObservedSpanSerializer extends JsonSerializer { + + @Override + public void serialize(ObservedSpan span, + JsonGenerator jgen, + SerializerProvider sp) throws IOException { + jgen.writeStartObject(); + jgen.writeStringField("traceId", span.getTraceID()); + jgen.writeBooleanField("sampled", span.getSampled()); + jgen.writeStringField("baggage", span.getBaggage()); + jgen.writeEndObject(); + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/TraceResponseSerializer.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/TraceResponseSerializer.java new file mode 100644 index 000000000..e6f7948c9 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/serializers/TraceResponseSerializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.serializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; +import com.uber.jaeger.crossdock.tracetest_manual.TraceResponse; + +public class TraceResponseSerializer extends JsonSerializer { + + @Override + public void serialize(TraceResponse response, + JsonGenerator jgen, + SerializerProvider sp) throws IOException { + ObservedSpan span = response.getObservedSpan(); + TraceResponse downstream = response.getDownstream(); + + + jgen.writeStartObject(); + jgen.writeStringField("notImplementedError", response.getNotImplementedError()); + jgen.writeObjectField("span", span); + + if (downstream != null) { + jgen.writeObjectField("downstream", downstream); + } + jgen.writeEndObject(); + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/Downstream.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/Downstream.java new file mode 100644 index 000000000..fb063e911 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/Downstream.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.tracetest_manual; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.uber.jaeger.crossdock.deserializers.DownstreamDeserializer; +import com.uber.jaeger.crossdock.serializers.DownstreamSerializer; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonSerialize(using = DownstreamSerializer.class) +@JsonDeserialize(using = DownstreamDeserializer.class) +public class Downstream { + private String serviceName; + private String host; + private String port; + private String transport; + private String serverRole; + private Downstream downstream; + + @JsonCreator + public Downstream(@JsonProperty("serviceName") String serviceName, + @JsonProperty("host") String host, + @JsonProperty("port") String port, + @JsonProperty("transport") String transport, + @JsonProperty("serverRole") String serverRole, + @JsonProperty("downstream") Downstream downstream) { + this.serviceName = serviceName; + this.host = host; + this.port = port; + this.transport = transport; + this.serverRole = serverRole; + this.downstream = downstream; + } + + public String getServiceName() { + return serviceName; + } + + public String getHost() { + return host; + } + + public String getPort() { + return port; + } + + public String getTransport() { + return transport; + } + + public String getServerRole() { + return serverRole; + } + + public Downstream getDownstream() { + return downstream; + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/JoinTraceRequest.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/JoinTraceRequest.java new file mode 100644 index 000000000..378f806c9 --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/JoinTraceRequest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.tracetest_manual; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.uber.jaeger.crossdock.deserializers.JoinTraceRequestDeserializer; + +@JsonDeserialize(using = JoinTraceRequestDeserializer.class) +public class JoinTraceRequest { + + private String serverRole; + private Downstream downstream; + + @JsonCreator + public JoinTraceRequest(@JsonProperty("serverRole") String serverRole, + @JsonProperty("downstream") Downstream downstream) { + this.serverRole = serverRole; + this.downstream = downstream; + } + + public String getServerRole() { + return serverRole; + } + + public Downstream getDownstream() { + return downstream; + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/ObservedSpan.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/ObservedSpan.java new file mode 100644 index 000000000..22356a2bb --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/ObservedSpan.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.tracetest_manual; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.uber.jaeger.crossdock.deserializers.ObservedSpanDeserializer; +import com.uber.jaeger.crossdock.serializers.ObservedSpanSerializer; + +@JsonSerialize(using = ObservedSpanSerializer.class) +@JsonDeserialize(using = ObservedSpanDeserializer.class) +public class ObservedSpan { + private String traceID; + private boolean sampled; + private String baggage; + + @JsonCreator + public ObservedSpan(@JsonProperty("traceId") String traceID, + @JsonProperty("sampled") boolean sampled, + @JsonProperty("baggage") String baggage) { + this.traceID = traceID; + this.sampled = sampled; + this.baggage = baggage; + } + + public String getTraceID() { + return traceID; + } + + public boolean getSampled() { + return sampled; + } + + public String getBaggage() { + return baggage; + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/StartTraceRequest.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/StartTraceRequest.java new file mode 100644 index 000000000..38aecc38f --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/StartTraceRequest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.tracetest_manual; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.uber.jaeger.crossdock.deserializers.StartTraceRequestDeserializer; + +@JsonDeserialize(using = StartTraceRequestDeserializer.class) +public class StartTraceRequest { + private boolean sampled; + private String baggage; + private Downstream downstream; + private String serverRole; + + @JsonCreator + public StartTraceRequest(@JsonProperty("serverRole") String serverRole, + @JsonProperty("sampled") boolean sampled, + @JsonProperty("baggage") String baggage, + @JsonProperty("downstream") Downstream downstream) { + this.serverRole = serverRole; + this.sampled = sampled; + this.baggage = baggage; + this.downstream = downstream; + } + + public String getServerRole() { + return serverRole; + } + + public boolean getSampled() { + return sampled; + } + + public String getBaggage() { + return baggage; + } + + public Downstream getDownstream() { + return downstream; + } +} diff --git a/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/TraceResponse.java b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/TraceResponse.java new file mode 100644 index 000000000..2d471f94f --- /dev/null +++ b/jaeger-java-crossdock/src/main/java/com/uber/jaeger/crossdock/tracetest_manual/TraceResponse.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.tracetest_manual; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.uber.jaeger.crossdock.deserializers.TraceResponseDeserializer; +import com.uber.jaeger.crossdock.serializers.TraceResponseSerializer; + +@JsonSerialize(using = TraceResponseSerializer.class) +@JsonDeserialize(using = TraceResponseDeserializer.class) +public class TraceResponse { + private String notImplementedError = ""; + private ObservedSpan span; + private TraceResponse downstream; + + public TraceResponse(ObservedSpan span) { + this.span = span; + } + + @JsonCreator + public TraceResponse(@JsonProperty("notImplementedError") String notImplementedError, + @JsonProperty("span") ObservedSpan span, + @JsonProperty("downstream") TraceResponse downstream) { + this.notImplementedError = notImplementedError; + this.span = span; + this.downstream = downstream; + } + + public TraceResponse(String notImplementedError) { + this.notImplementedError = notImplementedError; + } + + public TraceResponse setDownstream(TraceResponse downstream) { + this.downstream = downstream; + return this; + } + + public String getNotImplementedError() { + return notImplementedError; + } + + public ObservedSpan getObservedSpan() { + return span; + } + + public TraceResponse getDownstream() { + return downstream; + } +} \ No newline at end of file diff --git a/jaeger-java-crossdock/src/main/thrift/tracetest.thrift b/jaeger-java-crossdock/src/main/thrift/tracetest.thrift new file mode 100644 index 000000000..29ef50da5 --- /dev/null +++ b/jaeger-java-crossdock/src/main/thrift/tracetest.thrift @@ -0,0 +1,47 @@ +namespace java com.uber.jaeger.crossdock.tracetest + +enum Transport { HTTP, TCHANNEL } + +struct Downstream { + 1: required string serviceName + 2: required string serverRole + 3: required string host + 4: required string port + 5: required Transport transport + 6: optional Downstream downstream +} + +struct StartTraceRequest { + 1: required string serverRole // role of the server (always S1) + 2: required bool sampled + 3: required string baggage + 4: required Downstream downstream +} + +struct JoinTraceRequest { + 1: required string serverRole // role of the server, S2 or S3 + 2: optional Downstream downstream +} + +struct ObservedSpan { + 1: required string traceId + 2: required bool sampled + 3: required string baggage +} + +/** + * Each server must include the information about the span it observed. + * It can only be omitted from the response if notImplementedError field is not empty. + * If the server was instructed to make a downstream call, it must embed the + * downstream response in its own response. + */ +struct TraceResponse { + 1: optional ObservedSpan span + 2: optional TraceResponse downstream + 3: required string notImplementedError +} + +service TracedService { + TraceResponse startTrace(1: StartTraceRequest request) + TraceResponse joinTrace(1: JoinTraceRequest request) +} diff --git a/jaeger-java-crossdock/src/test/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java b/jaeger-java-crossdock/src/test/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java new file mode 100644 index 000000000..a90160063 --- /dev/null +++ b/jaeger-java-crossdock/src/test/java/com/uber/jaeger/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016, Uber Technologies, Inc + * + * 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, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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.uber.jaeger.crossdock.resources.behavior.http; + +import com.uber.jaeger.crossdock.Constants; +import com.uber.jaeger.crossdock.JerseyServer; +import com.uber.jaeger.crossdock.resources.behavior.tchannel.TChannelServer; +import com.uber.jaeger.crossdock.tracetest.TracedService; +import com.uber.jaeger.crossdock.tracetest_manual.Downstream; +import com.uber.jaeger.crossdock.tracetest_manual.JoinTraceRequest; +import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan; +import com.uber.jaeger.crossdock.tracetest_manual.StartTraceRequest; +import com.uber.jaeger.crossdock.tracetest_manual.TraceResponse; +import com.uber.tchannel.api.SubChannel; +import com.uber.tchannel.api.TChannel; +import com.uber.tchannel.api.TFuture; +import com.uber.tchannel.messages.ThriftRequest; +import com.uber.tchannel.messages.ThriftResponse; +import com.uber.tchannel.utils.TChannelUtilities; +import org.apache.log4j.BasicConfigurator; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import static org.junit.Assert.*; + +public class TraceBehaviorResourceTest { + private JerseyServer server; + + private String port; + private String hostPort; + + @BeforeClass + public static void setUpLogger() { + BasicConfigurator.configure(); + } + + @Before + public void setUp() throws Exception { + port = System.getenv("TRACE_TEST_BEHAVIOR_PORT"); + if (port == null) { + port = "32654"; + } + hostPort = String.format("127.0.0.1:%s", port); + server = new JerseyServer(hostPort, TraceBehaviorResource.class); + } + + @After + public void tearDown() { + server.shutdown(); + } + + boolean validateTraceResponse(TraceResponse response, String expectedTraceId, String expectedBaggage, boolean expectedSampled) { + ObservedSpan span = response.getObservedSpan(); + String traceId = span.getTraceID(); + boolean sampled = span.getSampled(); + String baggage = span.getBaggage(); + TraceResponse downstream = response.getDownstream(); + + boolean valid = (expectedTraceId == null || expectedTraceId.equals(traceId)) && + (expectedBaggage == null || expectedBaggage.equals(baggage)) && + (expectedSampled == sampled); + if (valid && (downstream != null)) { + valid = valid && validateTraceResponse(downstream, expectedTraceId, expectedBaggage, expectedSampled); + } + return valid; + } + + @Test + public void testStartTraceHttp() throws Exception { + String expectedTraceId = null; + String expectedBaggage = "baggage-example"; + boolean expectedSampled = true; + + Downstream downstream = new Downstream("java", "127.0.0.1", port, Constants.TRANSPORT_HTTP, "server", null); + StartTraceRequest startTraceRequest = new StartTraceRequest("server-role", expectedSampled, expectedBaggage, downstream); + + Response resp = JerseyServer.client.target(String.format("http://%s/start_trace", hostPort)) + .request(MediaType.APPLICATION_JSON) + .post(Entity.json(startTraceRequest)); + + TraceResponse traceResponse = resp.readEntity(TraceResponse.class); + + assertNotNull(traceResponse.getDownstream()); + assertTrue(validateTraceResponse(traceResponse, expectedTraceId, expectedBaggage, expectedSampled)); + } + + @Test + public void testJoinTraceHttp() throws Exception { + String expectedTraceId = null; + String expectedBaggage = null; + boolean expectedSampled = false; + + Downstream bottomDownstream = new Downstream("java", "127.0.0.1", port, Constants.TRANSPORT_HTTP, "server", null); + Downstream topDownstream = new Downstream("java", "127.0.0.1", port, Constants.TRANSPORT_HTTP, "server", bottomDownstream); + + JoinTraceRequest joinTraceRequest = new JoinTraceRequest("server-role", topDownstream); + + Response resp = JerseyServer.client.target(String.format("http://%s/join_trace", hostPort)) + .request(MediaType.APPLICATION_JSON) + .post(Entity.json(joinTraceRequest)); + + TraceResponse traceResponse = resp.readEntity(TraceResponse.class); + + assertNotNull(traceResponse.getDownstream()); + assertTrue(validateTraceResponse(traceResponse, expectedTraceId, expectedBaggage, expectedSampled)); + } + + @Test + public void testJoinTraceTChannel() throws Exception { + // Start server + TChannelServer server = new TChannelServer(Integer.parseInt(port)); + server.start(); + + // Setup test data used in assertions and parameters + com.uber.jaeger.crossdock.tracetest.JoinTraceRequest joinTraceRequest = new com.uber.jaeger.crossdock.tracetest.JoinTraceRequest("server-role"); + + TChannel tchannel = new TChannel.Builder("java-client").build(); + SubChannel subChannel = tchannel.makeSubChannel(JerseyServer.SERVICE_NAME); + + TFuture> future = subChannel.send( + new ThriftRequest.Builder(JerseyServer.SERVICE_NAME, "TracedService::joinTrace") + .setTimeout(1000) + .setBody(new TracedService.joinTrace_args(joinTraceRequest)) + .build(), + TChannelUtilities.getCurrentIp(), + Integer.parseInt(port) + ); + + try (ThriftResponse traceResponse = future.get()) { + com.uber.jaeger.crossdock.tracetest.TraceResponse response = traceResponse.getBody(TracedService.joinTrace_result.class).getSuccess(); + assertEquals(response.getNotImplementedError(), "TChannel not implemented for java."); + } + + server.shutdown(); + } +} diff --git a/settings.gradle b/settings.gradle index 4a4939417..9bfcb5da4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,3 +3,4 @@ include 'jaeger-core' include 'jaeger-jaxrs2' include 'jaeger-context' include 'jaeger-dropwizard' +include 'jaeger-java-crossdock' diff --git a/travis/publish_docker_image.sh b/travis/publish_docker_image.sh new file mode 100644 index 000000000..d11b68e8b --- /dev/null +++ b/travis/publish_docker_image.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e +set -x + +pushd 'jaeger-java-crossdock' + +export REPO=jaegertracing/xdock-java +export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST +export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi) +export TAG=`if [ "$BRANCH" == "master" ]; then echo "latest"; else echo $BRANCH; fi` +echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, REPO=$REPO, PR=$PR, BRANCH=$BRANCH, TAG=$TAG" +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" +docker build -f Dockerfile -t $REPO:$COMMIT . +docker tag $REPO:$COMMIT $REPO:$TAG +docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER +docker push $REPO + +popd