Search in sources :

Example 26 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler 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 27 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler 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 28 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler 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)

Example 29 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgentTest method testCustomTraceUnifiedPortHandlerDerivedMetrics.

@Test
public void testCustomTraceUnifiedPortHandlerDerivedMetrics() throws Exception {
    customTracePort = findAvailablePort(51233);
    proxy.proxyConfig.customTracingListenerPorts = String.valueOf(customTracePort);
    setUserPreprocessorForTraceDerivedREDMetrics(customTracePort);
    proxy.startCustomTracingListener(proxy.proxyConfig.getCustomTracingListenerPorts(), mockHandlerFactory, mockWavefrontSender, new SpanSampler(new RateSampler(1.0D), () -> null));
    waitUntilListenerIsOnline(customTracePort);
    reset(mockTraceHandler);
    reset(mockWavefrontSender);
    String traceId = UUID.randomUUID().toString();
    String spanData = "testSpanName source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" " + startTime + " " + (startTime + 1) + "\n";
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(1000).setName("testSpanName").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("application", PREPROCESSED_APPLICATION_TAG_VALUE), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("cluster", PREPROCESSED_CLUSTER_TAG_VALUE), new Annotation("shard", PREPROCESSED_SHARD_TAG_VALUE))).build());
    expectLastCall();
    Capture<HashMap<String, String>> tagsCapture = EasyMock.newCapture();
    mockWavefrontSender.sendMetric(eq(HEART_BEAT_METRIC), eq(1.0), anyLong(), eq(PREPROCESSED_SOURCE_VALUE), EasyMock.capture(tagsCapture));
    expectLastCall().anyTimes();
    replay(mockTraceHandler, mockWavefrontSender);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", customTracePort);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    stream.write(spanData.getBytes());
    stream.flush();
    socket.close();
    // sleep to get around "Nothing captured yet" issue with heartbeat metric call.
    Thread.sleep(100);
    verifyWithTimeout(500, mockTraceHandler, mockWavefrontSender);
    HashMap<String, String> tagsReturned = tagsCapture.getValue();
    assertEquals(PREPROCESSED_APPLICATION_TAG_VALUE, tagsReturned.get(APPLICATION_TAG_KEY));
    assertEquals(PREPROCESSED_SERVICE_TAG_VALUE, tagsReturned.get(SERVICE_TAG_KEY));
    assertEquals(PREPROCESSED_CLUSTER_TAG_VALUE, tagsReturned.get(CLUSTER_TAG_KEY));
    assertEquals(PREPROCESSED_SHARD_TAG_VALUE, tagsReturned.get(SHARD_TAG_KEY));
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) HashMap(java.util.HashMap) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) BufferedOutputStream(java.io.BufferedOutputStream) Annotation(wavefront.report.Annotation) Socket(java.net.Socket) Test(org.junit.Test)

Example 30 with SpanSampler

use of com.wavefront.agent.sampler.SpanSampler in project java by wavefrontHQ.

the class PushAgentTest method testSecureAll.

@Test
public void testSecureAll() throws Exception {
    int securePort1 = findAvailablePort(2888);
    int securePort2 = findAvailablePort(2889);
    proxy.proxyConfig.privateCertPath = getClass().getClassLoader().getResource("demo.cert").getPath();
    proxy.proxyConfig.privateKeyPath = getClass().getClassLoader().getResource("demo.key").getPath();
    proxy.proxyConfig.tlsPorts = "*";
    proxy.initSslContext();
    proxy.proxyConfig.pushListenerPorts = securePort1 + "," + securePort2;
    SpanSampler sampler = new SpanSampler(new RateSampler(1.0D), () -> null);
    proxy.startGraphiteListener(String.valueOf(securePort1), mockHandlerFactory, null, sampler);
    proxy.startGraphiteListener(String.valueOf(securePort2), mockHandlerFactory, null, sampler);
    waitUntilListenerIsOnline(securePort1);
    waitUntilListenerIsOnline(securePort2);
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // try plaintext over tcp first
    Socket socket = sslSocketFactory.createSocket("localhost", securePort1);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    String payloadStr = "metric.test 0 " + startTime + " source=test1\n" + "metric.test 1 " + (startTime + 1) + " source=test2\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockPointHandler);
    reset(mockPointHandler);
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test").setHost("test3").setTimestamp(startTime * 1000).setValue(0.0d).build());
    expectLastCall();
    mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test").setHost("test4").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
    expectLastCall();
    replay(mockPointHandler);
    // secure test
    socket = sslSocketFactory.createSocket("localhost", securePort2);
    stream = new BufferedOutputStream(socket.getOutputStream());
    payloadStr = "metric.test 0 " + startTime + " source=test3\n" + "metric.test 1 " + (startTime + 1) + " source=test4\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockPointHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) EasyMock.anyString(org.easymock.EasyMock.anyString) BufferedOutputStream(java.io.BufferedOutputStream) ReportPoint(wavefront.report.ReportPoint) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

SpanSampler (com.wavefront.agent.sampler.SpanSampler)47 Test (org.junit.Test)42 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)38 Annotation (wavefront.report.Annotation)32 Span (wavefront.report.Span)18 EasyMock.anyString (org.easymock.EasyMock.anyString)14 Batch (io.jaegertracing.thriftjava.Batch)12 ByteString (com.google.protobuf.ByteString)11 Process (io.jaegertracing.thriftjava.Process)11 Tag (io.jaegertracing.thriftjava.Tag)11 Model (io.opentelemetry.exporters.jaeger.proto.api_v2.Model)11 ByteBuffer (java.nio.ByteBuffer)11 Collector (io.opentelemetry.exporters.jaeger.proto.api_v2.Collector)10 Socket (java.net.Socket)10 Collector (io.jaegertracing.thriftjava.Collector)9 BufferedOutputStream (java.io.BufferedOutputStream)9 HashMap (java.util.HashMap)9 ReportPoint (wavefront.report.ReportPoint)9 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)7 ByteBuf (io.netty.buffer.ByteBuf)7