@Test public void testValidParametersConfig() { // This when the zipkinurl is non-empty AND the sampling rate is > 0.0f subject = new XioTracing(validParametersConfig); assertNotNull(subject.newClientHandler()); assertNotNull(subject.newServerHandler()); }
public HttpClientTracingHandler newClientHandler() { if (!enabled()) { return null; } HttpClientTracingDispatch tracingDispatch = new HttpClientTracingDispatch(name, tracer); return new HttpClientTracingHandler(tracingDispatch); }
val traceHandler = tracing.newClientHandler(); Pipelines.addHandler(channel.pipeline(), "distributed tracing", traceHandler);
public ApplicationBootstrap(ApplicationConfig config) { this(config, new ApplicationState(config, new XioTracing(config.getTracingConfig()))); }
public ChannelHandler tracingHandler(ApplicationState appState) { if (appState.tracing() != null) { return appState.tracing().newServerHandler(); } else { return null; } } }
Tracing buildZipkinTracing(@NonNull String name, @NonNull String zipkinUrl, float samplingRate) { if (zipkinUrl.isEmpty() || !(samplingRate > 0f)) { return null; } return Tracing.newBuilder() .localServiceName(name) // puts trace IDs into logs .currentTraceContext(MDCCurrentTraceContext.create()) .spanReporter(buildReporter(zipkinUrl)) .sampler(Sampler.create(samplingRate)) .build(); } }
public XioTracing(TracingConfig config) { name = config.getApplicationName(); TracingConfig.TracingType type = config.getType(); switch (type) { case ZIPKIN: String zipkinUrl = config.getZipkinUrl(); float samplingRate = config.getZipkinSamplingRate(); Tracing tracing = buildZipkinTracing(this.name, zipkinUrl, samplingRate); if (tracing != null) { tracer = BraveTracer.create(tracing); } break; case DATADOG: if (GlobalTracer.isRegistered()) { tracer = GlobalTracer.get(); } else { tracer = new DDTracer(); GlobalTracer.register(tracer); } break; } log.info("Configured tracer type: {}", type.toString()); }
@Test public void testDisableSsl() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(SslHandler.class); assertNull(result); }
public ApplicationState(ApplicationConfig config) { this(config, new XioTracing(config.getTracingConfig())); }
@Test public void testInvalidParametersConfig() { // This when the zipkinurl is empty OR the sampling rate is <= 0.0f subject = new XioTracing(invalidParametersConfig); assertNull(subject.newClientHandler()); assertNull(subject.newServerHandler()); } }
@Test public void testEnableSsl() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.sslClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(SslHandler.class); assertNotNull(result); }
public static XioServerBootstrap fromConfig(String key, Config config) { XioServerConfig serverConfig = XioServerConfig.fromConfig(key, config); ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.defaultApplication", ConfigFactory.load()); return new XioServerBootstrap( new ApplicationState(appConfig, new XioTracing(appConfig.getTracingConfig())), serverConfig, new XioServerState(serverConfig)); }
public HttpServerTracingHandler newServerHandler() { if (!enabled()) { return null; } HttpServerTracingDispatch state = new HttpServerTracingDispatch(name, tracer); return new HttpServerTracingHandler(state); }
@Test public void testDisableIdleTimeout() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.idleDisabledClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(XioIdleDisconnectHandler.class); assertNull(result); }
@Override public XioTracing tracing() { if (tracing == null) { ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.edgeProxyApplication"); tracing = new XioTracing(appConfig.getTracingConfig()); } return tracing; }
@Test public void testDisabledTracing() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have disabled Tracing the tracing returns null for newClientHandler when(tracing.newClientHandler()).thenReturn(null); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(HttpClientTracingHandler.class); assertEquals(result, null); }
ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.testApplication", root); ClientFactory factory = new ClientFactory(new XioTracing(appConfig.getTracingConfig())) { @Override public Client createClient(ChannelHandlerContext ctx, ClientConfig config) {
@Test public void testEnabledTracing() throws Exception { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.basicClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(HttpClientTracingHandler.class); assertEquals(result, tracingHandler); }
@Test public void testEnableIdleTimeout() { val channelConfig = ChannelConfiguration.clientConfig(1, "worker"); val clientConfig = ClientConfig.from(ConfigFactory.load().getConfig("xio.idleEnabledClient")); val clientState = new ClientState(channelConfig, clientConfig); // when we have enabled Tracing the tracing returns a non-null newClientHandler when(tracing.newClientHandler()).thenReturn(tracingHandler); subject = new ClientChannelInitializer(clientState, () -> appHandler, tracing); // Assert that we did not add a HttpClientTracingHandler to the pipeline val testChannel = new EmbeddedChannel(subject); val result = testChannel.pipeline().get(XioIdleDisconnectHandler.class); assertNotNull(result); } }