Search in sources :

Example 1 with SpanBytesEncoder

use of zipkin2.codec.SpanBytesEncoder in project java by wavefrontHQ.

the class ZipkinPortUnificationHandlerTest method testZipkinHandler.

@Test
public void testZipkinHandler() throws Exception {
    ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), "ProxyLevelAppTag", null);
    Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
    zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(1234 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").build();
    Endpoint localEndpoint2 = Endpoint.newBuilder().serviceName("backend").ip("10.0.0.1").build();
    zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("d6ab73f8a3930ae8").parentId("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getbackendservice").timestamp(startTime * 1000).duration(2234 * 1000).localEndpoint(localEndpoint2).putTag("http.method", "GET").putTag("http.url", "none+h2c://localhost:9000/api").putTag("http.status_code", "200").putTag("component", "jersey-server").putTag("application", "SpanLevelAppTag").addAnnotation(startTime * 1000, "start processing").build();
    zipkin2.Span spanServer3 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("d6ab73f8a3930ae8").kind(zipkin2.Span.Kind.CLIENT).name("getbackendservice2").timestamp(startTime * 1000).duration(2234 * 1000).localEndpoint(localEndpoint2).putTag("http.method", "GET").putTag("http.url", "none+h2c://localhost:9000/api").putTag("http.status_code", "200").putTag("component", "jersey-server").putTag("application", "SpanLevelAppTag").putTag("emptry.tag", "").addAnnotation(startTime * 1000, "start processing").build();
    List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2, spanServer3);
    // Validate all codecs i.e. JSON_V1, JSON_V2, THRIFT and PROTO3.
    for (SpanBytesEncoder encoder : SpanBytesEncoder.values()) {
        ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
        // take care of mocks.
        doMockLifecycle(mockTraceHandler, mockTraceSpanLogsHandler);
        ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
        doMockLifecycle(mockCtx);
        FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
        handler.handleHttpMessage(mockCtx, httpRequest);
        verify(mockTraceHandler, mockTraceSpanLogsHandler);
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Endpoint(zipkin2.Endpoint) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) Test(org.junit.Test)

Example 2 with SpanBytesEncoder

use of zipkin2.codec.SpanBytesEncoder in project zipkin by openzipkin.

the class ITZipkinSelfTracing method postSpan.

/**
 * This POSTs a single span. Afterwards, we expect this trace in storage, and also the self-trace
 * of POSTing it.
 */
void postSpan(String version) throws IOException {
    SpanBytesEncoder encoder = "v1".equals(version) ? SpanBytesEncoder.JSON_V1 : SpanBytesEncoder.JSON_V2;
    List<Span> testTrace = Collections.singletonList(Span.newBuilder().timestamp(TODAY).traceId("1").id("2").name("test-trace").build());
    Response response = client.newCall(new Request.Builder().url(url(server, "/api/" + version + "/spans")).post(RequestBody.create(encoder.encodeList(testTrace))).build()).execute();
    assertSuccessful(response);
}
Also used : Response(okhttp3.Response) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) QueryRequest(zipkin2.storage.QueryRequest) Request(okhttp3.Request) Span(zipkin2.Span)

Example 3 with SpanBytesEncoder

use of zipkin2.codec.SpanBytesEncoder in project java by wavefrontHQ.

the class ZipkinPortUnificationHandlerTest method testZipkinDurationSampler.

@Test
public void testZipkinDurationSampler() throws Exception {
    ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new DurationSampler(5), () -> null), null, null);
    Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
    zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(4 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
    zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("3822889fe47043bd").id("3822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(9 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
    List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2);
    SpanBytesEncoder encoder = SpanBytesEncoder.values()[1];
    ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
    // take care of mocks.
    // Reset mock
    reset(mockTraceHandler, mockTraceSpanLogsHandler);
    // Set Expectation
    Span expectedSpan2 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-3822-889fe47043bd").setTraceId("00000000-0000-0000-3822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "3822889fe47043bd"), new Annotation("zipkinTraceId", "3822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("_spanSecondaryId", "server"), new Annotation("service", "frontend"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("ipv4", "10.0.0.1"), new Annotation("_spanLogs", "true"))).build();
    mockTraceHandler.report(expectedSpan2);
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setTraceId("00000000-0000-0000-3822-889fe47043bd").setSpanId("00000000-0000-0000-3822-889fe47043bd").setSpanSecondaryId("server").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("annotation", "start processing")).build())).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
    doMockLifecycle(mockCtx);
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
    handler.handleHttpMessage(mockCtx, httpRequest);
    verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Endpoint(zipkin2.Endpoint) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) Test(org.junit.Test)

Example 4 with SpanBytesEncoder

use of zipkin2.codec.SpanBytesEncoder in project java by wavefrontHQ.

the class ZipkinPortUnificationHandlerTest method testZipkinDebugOverride.

@Test
public void testZipkinDebugOverride() throws Exception {
    ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new DurationSampler(10), () -> null), null, null);
    // take care of mocks.
    // Reset mock
    reset(mockTraceHandler, mockTraceSpanLogsHandler);
    // Set Expectation
    Span expectedSpan2 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-3822-889fe47043bd").setTraceId("00000000-0000-0000-3822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "3822889fe47043bd"), new Annotation("zipkinTraceId", "3822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("_spanSecondaryId", "server"), new Annotation("service", "frontend"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("debug", "true"), new Annotation("ipv4", "10.0.0.1"), new Annotation("_spanLogs", "true"))).build();
    mockTraceHandler.report(expectedSpan2);
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setTraceId("00000000-0000-0000-3822-889fe47043bd").setSpanId("00000000-0000-0000-3822-889fe47043bd").setSpanSecondaryId("server").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("annotation", "start processing")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(6).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-5822-889fe47043bd").setTraceId("00000000-0000-0000-5822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "5822889fe47043bd"), new Annotation("zipkinTraceId", "5822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("service", "frontend"), new Annotation("debug", "debug-id-4"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("debug", "true"), new Annotation("ipv4", "10.0.0.1"))).build());
    expectLastCall();
    Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
    zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(8 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
    zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("3822889fe47043bd").id("3822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(9 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").debug(true).addAnnotation(startTime * 1000, "start processing").build();
    zipkin2.Span spanServer3 = zipkin2.Span.newBuilder().traceId("4822889fe47043bd").id("4822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(7 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").putTag("debug", "debug-id-1").addAnnotation(startTime * 1000, "start processing").build();
    zipkin2.Span spanServer4 = zipkin2.Span.newBuilder().traceId("5822889fe47043bd").id("5822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(6 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").putTag("debug", "debug-id-4").debug(true).build();
    List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2, spanServer3, spanServer4);
    SpanBytesEncoder encoder = SpanBytesEncoder.values()[1];
    ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
    doMockLifecycle(mockCtx);
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
    handler.handleHttpMessage(mockCtx, httpRequest);
    verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Endpoint(zipkin2.Endpoint) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) Test(org.junit.Test)

Example 5 with SpanBytesEncoder

use of zipkin2.codec.SpanBytesEncoder in project java by wavefrontHQ.

the class ZipkinPortUnificationHandlerTest method testZipkinCustomSource.

@Test
public void testZipkinCustomSource() throws Exception {
    ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    // take care of mocks.
    // Reset mock
    reset(mockTraceHandler, mockTraceSpanLogsHandler);
    // Set Expectation
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("getservice").setSource("customZipkinSource").setSpanId("00000000-0000-0000-2822-889fe47043bd").setTraceId("00000000-0000-0000-2822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "2822889fe47043bd"), new Annotation("zipkinTraceId", "2822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("service", "frontend"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("ipv4", "10.0.0.1"))).build());
    expectLastCall();
    Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
    zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(9 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").putTag("source", "customZipkinSource").build();
    List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1);
    SpanBytesEncoder encoder = SpanBytesEncoder.values()[1];
    ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
    replay(mockTraceHandler, mockTraceSpanLogsHandler);
    ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
    doMockLifecycle(mockCtx);
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
    handler.handleHttpMessage(mockCtx, httpRequest);
    verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) Endpoint(zipkin2.Endpoint) NoopHealthCheckManager(com.wavefront.agent.channel.NoopHealthCheckManager) Test(org.junit.Test)

Aggregations

SpanBytesEncoder (zipkin2.codec.SpanBytesEncoder)5 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)4 SpanSampler (com.wavefront.agent.sampler.SpanSampler)4 ByteBuf (io.netty.buffer.ByteBuf)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)4 Test (org.junit.Test)4 Span (wavefront.report.Span)4 Endpoint (zipkin2.Endpoint)4 Annotation (wavefront.report.Annotation)3 DurationSampler (com.wavefront.sdk.entities.tracing.sampling.DurationSampler)2 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)2 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Span (zipkin2.Span)1 QueryRequest (zipkin2.storage.QueryRequest)1