use of wavefront.report.Span 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);
}
use of wavefront.report.Span 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);
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorRuleV2PredicateTest method testSpanPreprocessorComparisonOps.
@Test
public void testSpanPreprocessorComparisonOps() {
// test that preprocessor rules kick in before user rules
InputStream stream = PreprocessorRulesTest.class.getResourceAsStream("preprocessor_rules_predicates.yaml");
PreprocessorConfigManager config = new PreprocessorConfigManager();
Yaml yaml = new Yaml();
Map<String, Object> rulesByPort = (Map<String, Object>) yaml.load(stream);
String spanLine = "testSpanName source=spanSourceName spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 foo=BAR1-1234567890 foo=BAR2-2345678901 foo=bAr2-3456789012 " + "foo=baR boo=baz 1532012145123 1532012146234";
Span span = null;
for (String comparisonOp : COMPARISON_OPS) {
List<Map<String, Object>> rules = (List<Map<String, Object>>) rulesByPort.get(comparisonOp + "-span");
Assert.assertEquals("Expected rule size :: ", 1, rules.size());
Map<String, Object> v2PredicateMap = (Map<String, Object>) rules.get(0).get("if");
Predicate<Span> v2Predicate = Predicates.parsePredicate(v2PredicateMap);
Map<String, String> pointTags = new HashMap<>();
switch(comparisonOp) {
case "equals":
span = parseSpan("testSpanName.1 " + "source=spanSourceName " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [equals-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
case "startsWith":
span = parseSpan("testSpanName.2 " + "source=spanSourceName " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [startsWith-span] rule to return :: true , " + "Actual :: false", v2Predicate.test(span));
break;
case "endsWith":
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [endsWith-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
case "regexMatch":
span = parseSpan("testSpanName.1 " + "source=host " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [regexMatch-span] rule to return :: true , Actual ::" + " false", v2Predicate.test(span));
break;
case "contains":
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod-3 " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [contains-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
}
}
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorRuleV2PredicateTest method testSpanPreprocessorComparisonOpsList.
@Test
public void testSpanPreprocessorComparisonOpsList() {
// test that preprocessor rules kick in before user rules
InputStream stream = PreprocessorRulesTest.class.getResourceAsStream("preprocessor_rules_predicates.yaml");
PreprocessorConfigManager config = new PreprocessorConfigManager();
Yaml yaml = new Yaml();
Map<String, Object> rulesByPort = (Map<String, Object>) yaml.load(stream);
String spanLine = "testSpanName source=spanSourceName spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 foo=BAR1-1234567890 foo=BAR2-2345678901 foo=bAr2-3456789012 " + "foo=baR boo=baz 1532012145123 1532012146234";
Span span = null;
for (String comparisonOp : COMPARISON_OPS) {
List<Map<String, Object>> rules = (List<Map<String, Object>>) rulesByPort.get(comparisonOp + "-list-span");
Assert.assertEquals("Expected rule size :: ", 1, rules.size());
Map<String, Object> v2PredicateMap = (Map<String, Object>) rules.get(0).get("if");
Predicate<Span> v2Predicate = Predicates.parsePredicate(v2PredicateMap);
Map<String, String> pointTags = new HashMap<>();
switch(comparisonOp) {
case "equals":
span = parseSpan("testSpanName.1 " + "source=spanSourceName " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [equals-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
case "startsWith":
span = parseSpan("testSpanName.2 " + "source=spanSourceName " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [startsWith-span] rule to return :: true , " + "Actual :: false", v2Predicate.test(span));
break;
case "endsWith":
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [endsWith-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
case "regexMatch":
span = parseSpan("testSpanName.1 " + "source=host " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [regexMatch-span] rule to return :: true , Actual ::" + " false", v2Predicate.test(span));
break;
case "contains":
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod-3 " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 1532012145123 1532012146234");
Assert.assertTrue("Expected [contains-span] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
break;
}
}
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanAddAnnotationIfNotExistsRule.
@Test
public void testSpanAddAnnotationIfNotExistsRule() {
String spanLine = "\"testSpanName\" \"source\"=\"spanSourceName\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" \"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"foo\"=\"bar1-1234567890\" \"foo\"=\"bar2-1234567890\" \"foo\"=\"bar2-2345678901\" \"foo\"=\"baz\" " + "1532012145123 1532012146234";
SpanAddAnnotationTransformer rule;
Span span;
rule = new SpanAddAnnotationIfNotExistsTransformer(FOO, "baz2", null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "bar2-1234567890", "bar2-2345678901", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
rule = new SpanAddAnnotationIfNotExistsTransformer("foo2", "bar2", null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(5, span.getAnnotations().size());
assertEquals(new Annotation("foo2", "bar2"), span.getAnnotations().get(4));
}
Aggregations