From 48f969cda6a45e486a55054327756a6e3e300db8 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Wed, 25 Apr 2018 00:08:30 -0400 Subject: [PATCH 1/2] Remove tchannel from crossdock Signed-off-by: Yuri Shkuro --- jaeger-crossdock/build.gradle | 1 - .../io/jaegertracing/crossdock/Constants.java | 3 +- .../jaegertracing/crossdock/JerseyServer.java | 7 -- .../crossdock/api/Downstream.java | 5 - .../resources/behavior/TraceBehavior.java | 46 --------- .../tchannel/JoinTraceThriftHandler.java | 54 ----------- .../behavior/tchannel/TChannelServer.java | 96 ------------------- .../http/TraceBehaviorResourceTest.java | 41 -------- 8 files changed, 1 insertion(+), 252 deletions(-) delete mode 100644 jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java delete mode 100644 jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/TChannelServer.java diff --git a/jaeger-crossdock/build.gradle b/jaeger-crossdock/build.gradle index 7660b6ae5..d0a314fda 100644 --- a/jaeger-crossdock/build.gradle +++ b/jaeger-crossdock/build.gradle @@ -22,7 +22,6 @@ dependencies { 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: 'javax.servlet', name: 'servlet-api', version: '2.5' - compile group: 'com.uber.tchannel', name: 'tchannel-core', version: '0.7.2' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: slf4jVersion // Testing Frameworks diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/Constants.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/Constants.java index 50020a675..e176bc0ab 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/Constants.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/Constants.java @@ -19,7 +19,6 @@ private Constants() {} public static final String BAGGAGE_KEY = "crossdock-baggage-key"; public static final String TRANSPORT_HTTP = "HTTP"; - public static final String TRANSPORT_TCHANNEL = "TCHANNEL"; - + public static final String ENV_PROP_SENDER_TYPE = "SENDER"; } diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java index 1fc250dcc..439b46833 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java @@ -14,16 +14,13 @@ package io.jaegertracing.crossdock; -import com.uber.tchannel.api.TChannel.Builder; import io.jaegertracing.Configuration; import io.jaegertracing.Configuration.ReporterConfiguration; import io.jaegertracing.Configuration.SamplerConfiguration; import io.jaegertracing.crossdock.resources.behavior.EndToEndBehavior; import io.jaegertracing.crossdock.resources.behavior.ExceptionMapper; -import io.jaegertracing.crossdock.resources.behavior.TraceBehavior; import io.jaegertracing.crossdock.resources.behavior.http.EndToEndBehaviorResource; import io.jaegertracing.crossdock.resources.behavior.http.TraceBehaviorResource; -import io.jaegertracing.crossdock.resources.behavior.tchannel.TChannelServer; import io.jaegertracing.crossdock.resources.health.HealthResource; import io.jaegertracing.samplers.ConstSampler; import io.jaegertracing.senders.HttpSender; @@ -131,10 +128,6 @@ public static void main(String[] args) throws Exception { new HealthResource())); server.addNetworkListener(new NetworkListener("health", "0.0.0.0", 8080)); - - Builder tchannelBuilder = new Builder(serviceName); - tchannelBuilder.setServerPort(8082); - new TChannelServer(tchannelBuilder, new TraceBehavior(server.getTracer()), server.getTracer()).start(); } private static String getEvn(String envName, String defaultValue) { diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/api/Downstream.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/api/Downstream.java index e8ec8491b..0c60e408b 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/api/Downstream.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/api/Downstream.java @@ -66,8 +66,6 @@ private static String fromThrift(Transport transport) { switch (transport) { case HTTP: return Constants.TRANSPORT_HTTP; - case TCHANNEL: - return Constants.TRANSPORT_TCHANNEL; default: throw new IllegalArgumentException("Unknown transport " + transport); } @@ -89,9 +87,6 @@ private static Transport toThrift(String transport) { if (Constants.TRANSPORT_HTTP.equals(transport)) { return Transport.HTTP; } - if (Constants.TRANSPORT_TCHANNEL.equals(transport)) { - return Transport.TCHANNEL; - } throw new IllegalArgumentException("Unknown transport " + transport); } } diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/TraceBehavior.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/TraceBehavior.java index fd4fb1744..590ad679b 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/TraceBehavior.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/TraceBehavior.java @@ -15,10 +15,6 @@ package io.jaegertracing.crossdock.resources.behavior; import com.fasterxml.jackson.databind.ObjectMapper; -import com.uber.tchannel.api.SubChannel; -import com.uber.tchannel.api.TFuture; -import com.uber.tchannel.messages.ThriftRequest; -import com.uber.tchannel.messages.ThriftResponse; import io.jaegertracing.Span; import io.jaegertracing.SpanContext; import io.jaegertracing.crossdock.Constants; @@ -27,7 +23,6 @@ import io.jaegertracing.crossdock.api.JoinTraceRequest; import io.jaegertracing.crossdock.api.ObservedSpan; import io.jaegertracing.crossdock.api.TraceResponse; -import io.jaegertracing.crossdock.resources.behavior.tchannel.TChannelServer; import io.jaegertracing.crossdock.thrift.TracedService; import io.opentracing.Tracer; import java.io.IOException; @@ -69,8 +64,6 @@ private TraceResponse callDownstream(Downstream downstream) throws Exception { switch (transport) { case Constants.TRANSPORT_HTTP: return callDownstreamHttp(downstream); - case Constants.TRANSPORT_TCHANNEL: - return callDownstreamTChannel(downstream); default: return new TraceResponse("Unrecognized transport received: %s" + transport); } @@ -95,33 +88,6 @@ private TraceResponse callDownstreamHttp(Downstream downstream) throws IOExcepti return response; } - public TraceResponse callDownstreamTChannel(Downstream downstream) throws Exception { - io.jaegertracing.crossdock.thrift.JoinTraceRequest joinTraceRequest = - new io.jaegertracing.crossdock.thrift.JoinTraceRequest(downstream.getServerRole()); - joinTraceRequest.setDownstream(Downstream.toThrift(downstream.getDownstream())); - - SubChannel subChannel = TChannelServer.server.makeSubChannel(downstream.getServiceName()); - - log.info("Calling downstream tchannel {}", joinTraceRequest); - ThriftRequest thriftRequest = - new ThriftRequest.Builder( - downstream.getServiceName(), "TracedService::joinTrace") - .setTimeout(2000) - .setBody(new TracedService.joinTrace_args(joinTraceRequest)) - .build(); - TFuture> future = - subChannel.send(thriftRequest, host(downstream), port(downstream)); - - try (ThriftResponse thriftResponse = future.get()) { - log.info("Received tchannel response {}", thriftResponse); - if (thriftResponse.isError()) { - throw new Exception(thriftResponse.getError().getMessage()); - } - return TraceResponse.fromThrift( - thriftResponse.getBody(TracedService.joinTrace_result.class).getSuccess()); - } - } - private ObservedSpan observeSpan() { Span span = (Span)tracer.activeSpan(); if (tracer.activeSpan() == null) { @@ -135,16 +101,4 @@ private ObservedSpan observeSpan() { String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY); return new ObservedSpan(traceId, sampled, baggage); } - - private InetAddress host(Downstream downstream) { - try { - return InetAddress.getByName(downstream.getHost()); - } catch (UnknownHostException e) { - throw new RuntimeException("Cannot resolve host address for " + downstream.getHost(), e); - } - } - - private int port(Downstream downstream) { - return Integer.parseInt(downstream.getPort()); - } } diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java deleted file mode 100644 index 34c8e09fa..000000000 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/JoinTraceThriftHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2016, Uber Technologies, Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package io.jaegertracing.crossdock.resources.behavior.tchannel; - -import com.uber.tchannel.api.handlers.ThriftRequestHandler; -import com.uber.tchannel.messages.ThriftRequest; -import com.uber.tchannel.messages.ThriftResponse; -import io.jaegertracing.crossdock.api.Downstream; -import io.jaegertracing.crossdock.api.TraceResponse; -import io.jaegertracing.crossdock.resources.behavior.TraceBehavior; -import io.jaegertracing.crossdock.thrift.JoinTraceRequest; -import io.jaegertracing.crossdock.thrift.TracedService; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -class JoinTraceThriftHandler - extends ThriftRequestHandler { - private final TraceBehavior behavior; - - JoinTraceThriftHandler(TraceBehavior behavior) { - this.behavior = behavior; - } - - @Override - public ThriftResponse handleImpl( - ThriftRequest thriftRequest) { - JoinTraceRequest request = - thriftRequest.getBody(TracedService.joinTrace_args.class).getRequest(); - log.info("thrift:join_trace request: {}", request); - TraceResponse response; - try { - response = behavior.prepareResponse(Downstream.fromThrift(request.getDownstream())); - } catch (Exception e) { - log.error("Failed to call downstream", e); - response = new TraceResponse(e.getMessage()); - } - log.info("thrift:join_trace response: {}", response); - return new ThriftResponse.Builder(thriftRequest) - .setBody(new TracedService.joinTrace_result(TraceResponse.toThrift(response))) - .build(); - } -} diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/TChannelServer.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/TChannelServer.java deleted file mode 100644 index 43c4d0410..000000000 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/tchannel/TChannelServer.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2016, Uber Technologies, Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package io.jaegertracing.crossdock.resources.behavior.tchannel; - -import com.uber.tchannel.api.TChannel; -import com.uber.tchannel.tracing.TracingContext; -import io.jaegertracing.crossdock.resources.behavior.TraceBehavior; -import io.netty.channel.ChannelFuture; -import io.opentracing.Scope; -import io.opentracing.Span; -import io.opentracing.Tracer; -import java.util.EmptyStackException; - -public class TChannelServer { - // TODO should not be static, should be final - public static TChannel server; - - public TChannelServer(TChannel.Builder tchannelBuilder, TraceBehavior behavior, Tracer tracer) { - server = - tchannelBuilder - .setTracer(tracer) - .setTracingContext(new TracingContextAdapter(tracer)) - .build(); - - server - .makeSubChannel(server.getServiceName()) - .registerHealthHandler() - .register("TracedService::joinTrace", new JoinTraceThriftHandler(behavior)); - } - - public TChannel getChannel() { - return server; - } - - public void start() throws InterruptedException { - // listen for incoming connections - ChannelFuture serverFuture = server.listen().awaitUninterruptibly(); - if (!serverFuture.isSuccess()) { - throw new RuntimeException("Server future unsuccessful"); - } - } - - public void shutdown() { - server.shutdown(true); - } - - private static class TracingContextAdapter implements TracingContext { - - private final Tracer tracer; - - public TracingContextAdapter(Tracer tracer) { - this.tracer = tracer; - } - - @Override - public void pushSpan(Span span) { - tracer.scopeManager().activate(span, false); - } - - @Override - public boolean hasSpan() { - return tracer.activeSpan() != null; - } - - @Override - public Span currentSpan() throws EmptyStackException { - return tracer.activeSpan(); - } - - @Override - public Span popSpan() throws EmptyStackException { - Scope scope = tracer.scopeManager().active(); - if (scope != null) { - scope.close(); - return scope.span(); - } else { - return null; - } - } - - @Override - public void clear() {} - } -} diff --git a/jaeger-crossdock/src/test/java/io/jaegertracing/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java b/jaeger-crossdock/src/test/java/io/jaegertracing/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java index 22f3b762c..8250b29e3 100644 --- a/jaeger-crossdock/src/test/java/io/jaegertracing/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java +++ b/jaeger-crossdock/src/test/java/io/jaegertracing/crossdock/resources/behavior/http/TraceBehaviorResourceTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.uber.tchannel.api.TChannel.Builder; import io.jaegertracing.Configuration; import io.jaegertracing.Configuration.ReporterConfiguration; import io.jaegertracing.Configuration.SamplerConfiguration; @@ -31,7 +30,6 @@ import io.jaegertracing.crossdock.api.StartTraceRequest; import io.jaegertracing.crossdock.api.TraceResponse; import io.jaegertracing.crossdock.resources.behavior.TraceBehavior; -import io.jaegertracing.crossdock.resources.behavior.tchannel.TChannelServer; import io.jaegertracing.samplers.ConstSampler; import io.opentracing.Scope; import io.opentracing.noop.NoopTracerFactory; @@ -39,7 +37,6 @@ import io.opentracing.util.GlobalTracer; import java.io.IOException; import java.lang.reflect.Field; -import java.net.InetAddress; import java.net.ServerSocket; import java.util.Arrays; import java.util.Collection; @@ -160,44 +157,6 @@ public void testJoinTraceHttp() throws Exception { scope.close(); } - @Test - public void testJoinTraceTChannel() throws Exception { - Builder tchannelBuilder = new Builder("foo"); - tchannelBuilder.setServerPort(0); - tchannelBuilder.setServerHost(InetAddress.getLoopbackAddress()); - TChannelServer tchannel = new TChannelServer(tchannelBuilder, behavior, server.getTracer()); - tchannel.start(); - - Scope scope = server.getTracer().buildSpan("root").startActive(true); - - String expectedBaggage = "baggage-example"; - scope.span().setBaggageItem(Constants.BAGGAGE_KEY, expectedBaggage); - if (expectedSampled) { - Tags.SAMPLING_PRIORITY.set(scope.span(), 1); - } - - TraceResponse response = - behavior.callDownstreamTChannel( - new Downstream(SERVICE_NAME, - tchannel.getChannel().getListeningHost(), - String.valueOf(tchannel.getChannel().getListeningPort()), - Constants.TRANSPORT_TCHANNEL, - "s2", - new Downstream( - SERVICE_NAME, - tchannel.getChannel().getListeningHost(), - String.valueOf(tchannel.getChannel().getListeningPort()), - Constants.TRANSPORT_TCHANNEL, - "s3", - null))); - assertNotNull(response); - validateTraceResponse(response, String.format("%x", - ((Span)scope.span()).context().getTraceId()), expectedBaggage, 1); - scope.close(); - - tchannel.shutdown(); - } - private void validateTraceResponse( TraceResponse response, String expectedTraceId, From faf417068560862642dd2ed8b969f17809fb78e7 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Wed, 25 Apr 2018 00:52:52 -0400 Subject: [PATCH 2/2] Add blocking call to main Signed-off-by: Yuri Shkuro --- .../src/main/java/io/jaegertracing/crossdock/JerseyServer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java index 439b46833..ff49b73b8 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/JerseyServer.java @@ -128,6 +128,8 @@ public static void main(String[] args) throws Exception { new HealthResource())); server.addNetworkListener(new NetworkListener("health", "0.0.0.0", 8080)); + + Thread.currentThread().join(); } private static String getEvn(String envName, String defaultValue) {