use of com.wavefront.sdk.entities.tracing.sampling.DurationSampler in project java by wavefrontHQ.
the class PushAgentTest method testWavefrontHandlerAsDDIEndpoint.
@Test
public void testWavefrontHandlerAsDDIEndpoint() throws Exception {
port = findAvailablePort(2978);
proxy.proxyConfig.pushListenerPorts = String.valueOf(port);
proxy.proxyConfig.dataBackfillCutoffHours = 8640;
proxy.startGraphiteListener(proxy.proxyConfig.getPushListenerPorts(), mockHandlerFactory, null, new SpanSampler(new DurationSampler(5000), () -> null));
waitUntilListenerIsOnline(port);
String traceId = UUID.randomUUID().toString();
long timestamp1 = startTime * 1000000 + 12345;
long timestamp2 = startTime * 1000000 + 23456;
String payloadStr = "metric4.test 0 " + startTime + " source=test1\n" + "metric4.test 1 " + (startTime + 1) + " source=test2\n" + "metric4.test 2 " + (startTime + 2) + // note the lack of newline at the end!
" source=test3";
String histoData = "!M " + startTime + " #5 10.0 #10 100.0 metric.test.histo source=test1\n" + "!M " + (startTime + 60) + " #5 20.0 #6 30.0 #7 40.0 metric.test.histo source=test2";
String spanData = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + startTime + " " + (startTime + 10);
String spanDataToDiscard = "testSpanName parent=parent1 source=testsource spanId=testspanid " + "traceId=\"" + traceId + "\" parent=parent2 " + startTime + " " + (startTime + 1);
String spanLogData = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\",\"key4\":\"value4\"}}]}\n";
String spanLogDataWithSpanField = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}},{\"timestamp\":" + timestamp2 + ",\"fields\":{\"key3\":\"value3\"}}]," + "\"span\":\"" + escapeSpanData(spanData) + "\"}\n";
String spanLogDataWithSpanFieldToDiscard = "{\"spanId\":\"testspanid\",\"traceId\":\"" + traceId + "\",\"logs\":[{\"timestamp\":" + timestamp1 + ",\"fields\":{\"key\":\"value\",\"key2\":\"value2\"}}]," + "\"span\":\"" + escapeSpanData(spanDataToDiscard) + "\"}\n";
String mixedData = "@SourceTag action=save source=testSource newtag1 newtag2\n" + "@Event " + startTime + " \"Event name for testing\" host=host1 host=host2 tag=tag1 " + "severity=INFO multi=bar multi=baz\n" + "!M " + (startTime + 60) + " #5 20.0 #6 30.0 #7 40.0 metric.test.histo source=test2\n" + "metric4.test 0 " + startTime + " source=test1\n" + spanLogData + spanLogDataWithSpanField;
String invalidData = "{\"spanId\"}\n@SourceTag\n@Event\n!M #5\nmetric.name\n" + "metric5.test 0 1234567890 source=test1\n";
reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
expectLastCall().times(2);
mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test2").setTimestamp((startTime + 1) * 1000).setValue(1.0d).build());
expectLastCall().times(2);
mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test3").setTimestamp((startTime + 2) * 1000).setValue(2.0d).build());
expectLastCall().times(2);
replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", payloadStr));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=wavefront", payloadStr));
verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
mockHistogramHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test.histo").setHost("test1").setTimestamp(startTime * 1000).setValue(Histogram.newBuilder().setType(HistogramType.TDIGEST).setDuration(60000).setBins(ImmutableList.of(10.0d, 100.0d)).setCounts(ImmutableList.of(5, 10)).build()).build());
expectLastCall();
mockHistogramHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric.test.histo").setHost("test2").setTimestamp((startTime + 60) * 1000).setValue(Histogram.newBuilder().setType(HistogramType.TDIGEST).setDuration(60000).setBins(ImmutableList.of(20.0d, 30.0d, 40.0d)).setCounts(ImmutableList.of(5, 6, 7)).build()).build());
expectLastCall();
replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=histogram", histoData));
verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
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")).build())).build());
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime * 1000).setDuration(10000).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("parent", "parent1"), new Annotation("parent", "parent2"))).build());
expectLastCall();
replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanData));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogData));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanField));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanDataToDiscard));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanFieldToDiscard));
verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
mockSourceTagHandler.report(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build());
expectLastCall();
mockEventHandler.report(ReportEvent.newBuilder().setStartTime(startTime * 1000).setEndTime(startTime * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setTags(ImmutableList.of("tag1")).setAnnotations(ImmutableMap.of("severity", "INFO")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).build());
expectLastCall();
mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
expectLastCall();
replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
proxy.entityProps.get(ReportableEntityType.HISTOGRAM).setFeatureDisabled(true);
assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=histogram", histoData));
proxy.entityProps.get(ReportableEntityType.TRACE).setFeatureDisabled(true);
assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=trace", spanData));
proxy.entityProps.get(ReportableEntityType.TRACE_SPAN_LOGS).setFeatureDisabled(true);
assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogData));
assertEquals(403, gzippedHttpPost("http://localhost:" + port + "/report?format=spanLogs", spanLogDataWithSpanField));
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", mixedData));
verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
reset(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
mockSourceTagHandler.report(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build());
expectLastCall();
mockEventHandler.report(ReportEvent.newBuilder().setStartTime(startTime * 1000).setEndTime(startTime * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setTags(ImmutableList.of("tag1")).setAnnotations(ImmutableMap.of("severity", "INFO")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).build());
expectLastCall();
mockPointHandler.report(ReportPoint.newBuilder().setTable("dummy").setMetric("metric4.test").setHost("test1").setTimestamp(startTime * 1000).setValue(0.0d).build());
expectLastCall();
mockSourceTagHandler.reject(eq("@SourceTag"), anyString());
expectLastCall();
mockEventHandler.reject(eq("@Event"), anyString());
expectLastCall();
mockPointHandler.reject(eq("metric.name"), anyString());
expectLastCall();
mockPointHandler.reject(eq(ReportPoint.newBuilder().setTable("dummy").setMetric("metric5.test").setHost("test1").setTimestamp(1234567890000L).setValue(0.0d).build()), startsWith("WF-402: Point outside of reasonable timeframe"));
expectLastCall();
replay(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
assertEquals(202, gzippedHttpPost("http://localhost:" + port + "/report", mixedData + "\n" + invalidData));
verify(mockPointHandler, mockHistogramHandler, mockTraceHandler, mockTraceSpanLogsHandler, mockSourceTagHandler, mockEventHandler);
}
use of com.wavefront.sdk.entities.tracing.sampling.DurationSampler in project java by wavefrontHQ.
the class JaegerGrpcCollectorHandlerTest method testJaegerDurationSampler.
@Test
public void testJaegerDurationSampler() throws Exception {
reset(mockTraceHandler, mockTraceLogsHandler);
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9000).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("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"))).build());
expectLastCall();
replay(mockTraceHandler, mockTraceLogsHandler);
JaegerGrpcCollectorHandler handler = new JaegerGrpcCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new DurationSampler(5 * 1000), () -> 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 span1Id = ByteString.copyFrom(buffer.array());
buffer = ByteBuffer.allocate(Long.BYTES);
buffer.putLong(2345678L);
ByteString span2Id = ByteString.copyFrom(buffer.array());
Model.Span span1 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span1Id).setDuration(Duration.newBuilder().setSeconds(4L).build()).setOperationName("HTTP GET").setStartTime(fromMillis(startTime)).build();
Model.Span span2 = Model.Span.newBuilder().setTraceId(traceId).setSpanId(span2Id).setDuration(Duration.newBuilder().setSeconds(9L).build()).setOperationName("HTTP GET /").setStartTime(fromMillis(startTime)).addReferences(Model.SpanRef.newBuilder().setRefType(Model.SpanRefType.CHILD_OF).setSpanId(span1Id).setTraceId(traceId).build()).build();
Model.Batch testBatch = Model.Batch.newBuilder().setProcess(Model.Process.newBuilder().setServiceName("frontend").addTags(ipTag).build()).addAllSpans(ImmutableList.of(span1, span2)).build();
Collector.PostSpansRequest batches = Collector.PostSpansRequest.newBuilder().setBatch(testBatch).build();
handler.postSpans(batches, emptyStreamObserver);
verify(mockTraceHandler, mockTraceLogsHandler);
}
use of com.wavefront.sdk.entities.tracing.sampling.DurationSampler in project java by wavefrontHQ.
the class SpanSamplerTest method testAlwaysSampleDebug.
@Test
public void testAlwaysSampleDebug() {
long startTime = System.currentTimeMillis();
String traceId = UUID.randomUUID().toString();
Span span = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("debug", "true"))).build();
SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> null);
assertTrue(sampler.sample(span));
}
use of com.wavefront.sdk.entities.tracing.sampling.DurationSampler in project java by wavefrontHQ.
the class SpanSamplerTest method testMultipleSpanSamplingPolicies.
@Test
public void testMultipleSpanSamplingPolicies() {
long startTime = System.currentTimeMillis();
String traceId = UUID.randomUUID().toString();
Span spanToAllow = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).build();
Span spanToAllowWithDebugTag = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).setAnnotations(ImmutableList.of(new Annotation("debug", "true"))).build();
Span spanToDiscard = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("source").setSpanId("testspanid").setTraceId(traceId).build();
List<SpanSamplingPolicy> activeSpanSamplingPolicies = ImmutableList.of(new SpanSamplingPolicy("SpanNamePolicy", "{{spanName}}='testSpanName'", 0), new SpanSamplingPolicy("SpanSourcePolicy", "{{sourceName}}='testsource'", 100));
SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> activeSpanSamplingPolicies);
assertTrue(sampler.sample(spanToAllow));
assertEquals("SpanSourcePolicy", AnnotationUtils.getValue(spanToAllow.getAnnotations(), "_sampledByPolicy"));
assertTrue(sampler.sample(spanToAllowWithDebugTag));
assertNull(AnnotationUtils.getValue(spanToAllowWithDebugTag.getAnnotations(), "_sampledByPolicy"));
assertFalse(sampler.sample(spanToDiscard));
assertTrue(spanToDiscard.getAnnotations().isEmpty());
}
use of com.wavefront.sdk.entities.tracing.sampling.DurationSampler 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);
}
Aggregations