Search in sources :

Example 6 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class PushAgentTest method testTraceUnifiedPortHandlerPlaintext.

@Test
public void testTraceUnifiedPortHandlerPlaintext() throws Exception {
    tracePort = findAvailablePort(3888);
    proxy.proxyConfig.traceListenerPorts = String.valueOf(tracePort);
    proxy.startTraceListener(proxy.proxyConfig.getTraceListenerPorts(), mockHandlerFactory, new SpanSampler(new RateSampler(1.0D), () -> null));
    waitUntilListenerIsOnline(tracePort);
    reset(mockTraceHandler);
    reset(mockTraceSpanLogsHandler);
    String traceId = UUID.randomUUID().toString();
    long timestamp1 = startTime * 1000000 + 12345;
    long timestamp2 = startTime * 1000000 + 23456;
    String spanData = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + startTime + " " + (startTime + 1) + "\n";
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("dummy").setTraceId(traceId).setSpanId("testspanid").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(timestamp1).setFields(ImmutableMap.of("key", "value", "key2", "value2")).build(), SpanLog.newBuilder().setTimestamp(timestamp2).setFields(ImmutableMap.of("key3", "value3", "key4", "value4")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(1000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("parent", "parent1"), new Annotation("parent", "parent2"))).build());
    expectLastCall();
    replay(mockTraceHandler);
    replay(mockTraceSpanLogsHandler);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", tracePort);
    BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream());
    String payloadStr = spanData + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n" + "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
    stream.write(payloadStr.getBytes());
    stream.flush();
    socket.close();
    verifyWithTimeout(500, mockTraceHandler, mockTraceSpanLogsHandler);
}
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) Annotation(wavefront.report.Annotation) Socket(java.net.Socket) Test(org.junit.Test)

Example 7 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class JaegerGrpcCollectorHandlerTest method testJaegerPreprocessedDerivedMetrics.

/**
 * Test for derived metrics emitted from Jaeger trace listeners. Derived metrics should report
 * tag values post applying preprocessing rules to the span.
 */
@Test
public void testJaegerPreprocessedDerivedMetrics() throws Exception {
    reset(mockTraceHandler, mockWavefrontSender);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4000).setName("HTTP GET").setSource(PREPROCESSED_SOURCE_VALUE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", PREPROCESSED_SERVICE_TAG_VALUE), new Annotation("application", PREPROCESSED_APPLICATION_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);
    Supplier<ReportableEntityPreprocessor> preprocessorSupplier = () -> {
        ReportableEntityPreprocessor preprocessor = new ReportableEntityPreprocessor();
        PreprocessorRuleMetrics preprocessorRuleMetrics = new PreprocessorRuleMetrics(null, null, null);
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(APPLICATION_TAG_KEY, "^Jaeger.*", PREPROCESSED_APPLICATION_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SERVICE_TAG_KEY, "^test.*", PREPROCESSED_SERVICE_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer("sourceName", "^jaeger.*", PREPROCESSED_SOURCE_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(CLUSTER_TAG_KEY, "^none.*", PREPROCESSED_CLUSTER_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        preprocessor.forSpan().addTransformer(new SpanReplaceRegexTransformer(SHARD_TAG_KEY, "^none.*", PREPROCESSED_SHARD_TAG_VALUE, null, null, false, x -> true, preprocessorRuleMetrics));
        return preprocessor;
    };
    JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, mockWavefrontSender, () -> false, () -> false, preprocessorSupplier, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Model.KeyValue ipTag = Model.KeyValue.newBuilder().setKey("ip").setVStr("10.0.0.1").setVType(Model.ValueType.STRING).build();
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1234567890L);
    buffer.putLong(1234567890123L);
    ByteString traceId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(1234567L);
    ByteString span2Id = ByteString.copyFrom(buffer.array());
    Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(4L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).build();
    Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("testService").addTags(ipTag).build()).addAllSpans(ImmutableList.of(span2)).build();
    Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
    handler.postSpans(batches, emptyStreamObserver);
    handler.run();
    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 : ReportableEntityPreprocessor(com.wavefront.agent.preprocessor.ReportableEntityPreprocessor) HashMap(java.util.HashMap) RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ByteString(com.google.protobuf.ByteString) SpanSampler(com.wavefront.agent.sampler.SpanSampler) ByteString(com.google.protobuf.ByteString) ByteBuffer(java.nio.ByteBuffer) Annotation(wavefront.report.Annotation) PreprocessorRuleMetrics(com.wavefront.agent.preprocessor.PreprocessorRuleMetrics) Model(io.opentelemetry.exporters.jaeger.proto.api_v2.Model) Collector(io.opentelemetry.exporters.jaeger.proto.api_v2.Collector) SpanReplaceRegexTransformer(com.wavefront.agent.preprocessor.SpanReplaceRegexTransformer) Test(org.junit.Test)

Example 8 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class JaegerGrpcCollectorHandlerTest method testIgnoresServiceTags.

@Test
public void testIgnoresServiceTags() throws Exception {
    reset(mockTraceHandler, mockTraceLogsHandler);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9000).setName("HTTP GET /").setSource("source-processtag").setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4000).setName("HTTP GET").setSource("source-processtag").setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3000).setName("HTTP GET /test").setSource("source-processtag").setSpanId("00000000-0000-0000-0000-0051759bfc69").setTraceId("0000011e-ab2a-9944-0000-000049631900").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceLogsHandler);
    JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Model.KeyValue ipTag = Model.KeyValue.newBuilder().setKey("ip").setVStr("10.0.0.1").setVType(Model.ValueType.STRING).build();
    Model.KeyValue sourceProcessTag = Model.KeyValue.newBuilder().setKey("source").setVStr("source-processtag").setVType(Model.ValueType.STRING).build();
    Model.KeyValue customServiceProcessTag = Model.KeyValue.newBuilder().setKey("service").setVStr("service-processtag").setVType(Model.ValueType.STRING).build();
    Model.KeyValue customServiceSpanTag = Model.KeyValue.newBuilder().setKey("service").setVStr("service-spantag").setVType(Model.ValueType.STRING).build();
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1234567890L);
    buffer.putLong(1234567890123L);
    ByteString traceId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1231232342340L);
    buffer.putLong(1231231232L);
    ByteString trace2Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(2345678L);
    ByteString span1Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(1234567L);
    ByteString span2Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(349865507945L);
    ByteString span3Id = ByteString.copyFrom(buffer.array());
    Model.Span span1 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span1Id).setDuration(Duration.newBuilder().setSeconds(9L).build()).setOperationName("HTTP GET /").addTags(customServiceSpanTag).setStartTime(fromMillis(startTime)).build();
    Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(4L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).build();
    Model.Span span3 = Model.Span.newBuilder().setTraceId(trace2Id).setSpanId(span3Id).setDuration(Duration.newBuilder().setSeconds(3L).build()).setOperationName("HTTP GET /test").setStartTime(fromMillis(startTime)).build();
    Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).addTags(sourceProcessTag).addTags(customServiceProcessTag).build()).addAllSpans(ImmutableList.of(span1, span2)).build();
    Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
    handler.postSpans(batches, emptyStreamObserver);
    Model.Batch testBatchForProxyLevel = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).addTags(sourceProcessTag).build()).addAllSpans(ImmutableList.of(span3)).build();
    handler.postSpans(Collector.PostSpansRequest.newBuilder().setBatch(testBatchForProxyLevel).build(), emptyStreamObserver);
    verify(mockTraceHandler, mockTraceLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ByteString(com.google.protobuf.ByteString) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Model(io.opentelemetry.exporters.jaeger.proto.api_v2.Model) Collector(io.opentelemetry.exporters.jaeger.proto.api_v2.Collector) ByteBuffer(java.nio.ByteBuffer) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 9 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class JaegerGrpcCollectorHandlerTest method testJaegerGrpcCollector.

@Test
public void testJaegerGrpcCollector() throws Exception {
    reset(mockTraceHandler, mockTraceLogsHandler);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1000).setName("HTTP GET").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("component", "db"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("_spanLogs", "true"))).build());
    expectLastCall();
    mockTraceLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("event", "error", "exception", "NullPointerException")).build())).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(2000).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("component", "db"), new Annotation("application", "Custom-JaegerApp"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"))).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(2000).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-9a12-b85901d53397").setTraceId("00000000-0000-0000-fea4-87ee36e58cab").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("parent", "00000000-0000-0000-fea4-87ee36e58cab"))).build());
    expectLastCall();
    // Test filtering empty tags
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(2000).setName("HTTP GET /test").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-0051759bfc69").setTraceId("0000011e-ab2a-9944-0000-000049631900").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceLogsHandler);
    JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Model.KeyValue ipTag = Model.KeyValue.newBuilder().setKey("ip").setVStr("10.0.0.1").setVType(Model.ValueType.STRING).build();
    Model.KeyValue componentTag = Model.KeyValue.newBuilder().setKey("component").setVStr("db").setVType(Model.ValueType.STRING).build();
    Model.KeyValue customApplicationTag = Model.KeyValue.newBuilder().setKey("application").setVStr("Custom-JaegerApp").setVType(Model.ValueType.STRING).build();
    Model.KeyValue emptyTag = Model.KeyValue.newBuilder().setKey("empty").setVStr("").setVType(Model.ValueType.STRING).build();
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1234567890L);
    buffer.putLong(1234567890123L);
    ByteString traceId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(0L);
    buffer.putLong(-97803834702328661L);
    ByteString trace3Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1231232342340L);
    buffer.putLong(1231231232L);
    ByteString trace4Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(1234567L);
    ByteString span1Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(2345678L);
    ByteString span2Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(-7344605349865507945L);
    ByteString span3Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(-97803834702328661L);
    ByteString span3ParentId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(349865507945L);
    ByteString span4Id = ByteString.copyFrom(buffer.array());
    Model.Span span1 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span1Id).setDuration(Duration.newBuilder().setSeconds(1L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).addTags(componentTag).addLogs(Model.Log.newBuilder().addFields(Model.KeyValue.newBuilder().setKey("event").setVStr("error").setVType(Model.ValueType.STRING).build()).addFields(Model.KeyValue.newBuilder().setKey("exception").setVStr("NullPointerException").setVType(Model.ValueType.STRING).build()).setTimestamp(fromMillis(startTime))).build();
    Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(2L).build()).setOperationName("HTTP GET /").setStartTime(fromMillis(startTime)).addTags(componentTag).addTags(customApplicationTag).addReferences(Model.SpanRef.newBuilder().setRefType(Model.SpanRefType.CHILD_OF).setSpanId(span1Id).setTraceId(traceId).build()).build();
    // check negative span IDs too
    Model.Span span3 = Model.Span.newBuilder().setTraceId(trace3Id).setSpanId(span3Id).setDuration(Duration.newBuilder().setSeconds(2L).build()).setOperationName("HTTP GET /").setStartTime(fromMillis(startTime)).addReferences(Model.SpanRef.newBuilder().setRefType(Model.SpanRefType.CHILD_OF).setSpanId(span3ParentId).setTraceId(traceId).build()).build();
    Model.Span span4 = Model.Span.newBuilder().setTraceId(trace4Id).setSpanId(span4Id).setDuration(Duration.newBuilder().setSeconds(2L).build()).setOperationName("HTTP GET /test").setStartTime(fromMillis(startTime)).addTags(emptyTag).build();
    Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).build()).addAllSpans(ImmutableList.of(span1, span2, span3, span4)).build();
    Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
    handler.postSpans(batches, emptyStreamObserver);
    verify(mockTraceHandler, mockTraceLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ByteString(com.google.protobuf.ByteString) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Model(io.opentelemetry.exporters.jaeger.proto.api_v2.Model) Collector(io.opentelemetry.exporters.jaeger.proto.api_v2.Collector) ByteBuffer(java.nio.ByteBuffer) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 10 with RateSampler

use of com.wavefront.sdk.entities.tracing.sampling.RateSampler in project java by wavefrontHQ.

the class JaegerGrpcCollectorHandlerTest method testApplicationTagPriority.

@Test
public void testApplicationTagPriority() throws Exception {
    reset(mockTraceHandler, mockTraceLogsHandler);
    // Span to verify span level tags precedence
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(1000).setName("HTTP GET").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("component", "db"), new Annotation("application", "SpanLevelAppTag"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    // Span to verify process level tags precedence
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(2000).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("component", "db"), new Annotation("application", "ProcessLevelAppTag"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"))).build());
    expectLastCall();
    // Span to verify Proxy level tags precedence
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3000).setName("HTTP GET /").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-9a12-b85901d53397").setTraceId("00000000-0000-0000-fea4-87ee36e58cab").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("service", "frontend"), new Annotation("application", "ProxyLevelAppTag"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("parent", "00000000-0000-0000-fea4-87ee36e58cab"))).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceLogsHandler);
    // Verify span level "application" tags precedence
    JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), "ProxyLevelAppTag", null);
    Model.KeyValue ipTag = Model.KeyValue.newBuilder().setKey("ip").setVStr("10.0.0.1").setVType(Model.ValueType.STRING).build();
    Model.KeyValue componentTag = Model.KeyValue.newBuilder().setKey("component").setVStr("db").setVType(Model.ValueType.STRING).build();
    Model.KeyValue spanLevelAppTag = Model.KeyValue.newBuilder().setKey("application").setVStr("SpanLevelAppTag").setVType(Model.ValueType.STRING).build();
    Model.KeyValue processLevelAppTag = Model.KeyValue.newBuilder().setKey("application").setVStr("ProcessLevelAppTag").setVType(Model.ValueType.STRING).build();
    ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(1234567890L);
    buffer.putLong(1234567890123L);
    ByteString traceId = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES * 2);
    buffer.putLong(0L);
    buffer.putLong(-97803834702328661L);
    ByteString trace2Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(1234567L);
    ByteString span1Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(2345678L);
    ByteString span2Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(-7344605349865507945L);
    ByteString span3Id = ByteString.copyFrom(buffer.array());
    buffer = ByteBuffer.allocate(Long.BYTES);
    buffer.putLong(-97803834702328661L);
    ByteString span3ParentId = ByteString.copyFrom(buffer.array());
    // Span1 to verify span level tags precedence
    Model.Span span1 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span1Id).setDuration(Duration.newBuilder().setSeconds(1L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).addTags(componentTag).addTags(spanLevelAppTag).setFlags(1).build();
    Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(2L).build()).setOperationName("HTTP GET /").setStartTime(fromMillis(startTime)).addTags(componentTag).setFlags(1).addReferences(Model.SpanRef.newBuilder().setRefType(Model.SpanRefType.CHILD_OF).setSpanId(span1Id).setTraceId(traceId).build()).build();
    // check negative span IDs too
    Model.Span span3 = Model.Span.newBuilder().setTraceId(trace2Id).setSpanId(span3Id).setDuration(Duration.newBuilder().setSeconds(3L).build()).setOperationName("HTTP GET /").setStartTime(fromMillis(startTime)).setFlags(1).addReferences(Model.SpanRef.newBuilder().setRefType(Model.SpanRefType.CHILD_OF).setSpanId(span3ParentId).setTraceId(traceId).build()).build();
    Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).addTags(processLevelAppTag).build()).addAllSpans(ImmutableList.of(span1, span2)).build();
    Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
    handler.postSpans(batches, emptyStreamObserver);
    Model.Batch testBatchForProxyLevel = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).build()).addAllSpans(ImmutableList.of(span3)).build();
    Collector.PostSpansRequest batchesForProxyLevel = Collector.PostSpansRequest.newBuilder().setBatch(testBatchForProxyLevel).build();
    handler.postSpans(batchesForProxyLevel, emptyStreamObserver);
    verify(mockTraceHandler, mockTraceLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) ByteString(com.google.protobuf.ByteString) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Model(io.opentelemetry.exporters.jaeger.proto.api_v2.Model) Collector(io.opentelemetry.exporters.jaeger.proto.api_v2.Collector) ByteBuffer(java.nio.ByteBuffer) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Aggregations

SpanSampler (com.wavefront.agent.sampler.SpanSampler)36 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)36 Test (org.junit.Test)35 Annotation (wavefront.report.Annotation)23 EasyMock.anyString (org.easymock.EasyMock.anyString)13 Span (wavefront.report.Span)12 Socket (java.net.Socket)10 Batch (io.jaegertracing.thriftjava.Batch)9 Process (io.jaegertracing.thriftjava.Process)9 BufferedOutputStream (java.io.BufferedOutputStream)9 ByteString (com.google.protobuf.ByteString)8 Tag (io.jaegertracing.thriftjava.Tag)8 Collector (io.opentelemetry.exporters.jaeger.proto.api_v2.Collector)8 Model (io.opentelemetry.exporters.jaeger.proto.api_v2.Model)8 ByteBuffer (java.nio.ByteBuffer)8 Collector (io.jaegertracing.thriftjava.Collector)7 ReportPoint (wavefront.report.ReportPoint)7 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)5 ByteBuf (io.netty.buffer.ByteBuf)5 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5