use of wavefront.report.Span in project java by wavefrontHQ.
the class JaegerTChannelCollectorHandlerTest 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(1234).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("jaegerSpanId", "12d687"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), 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(2345).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("jaegerSpanId", "23cace"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"), new Annotation("component", "db"), new Annotation("application", "ProcessLevelAppTag"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
expectLastCall();
// Span to verify Proxy level tags precedence
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3456).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("jaegerSpanId", "9a12b85901d53397"), new Annotation("jaegerTraceId", "fea487ee36e58cab"), new Annotation("service", "frontend"), new Annotation("parent", "00000000-0000-0000-fea4-87ee36e58cab"), new Annotation("application", "ProxyLevelAppTag"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
expectLastCall();
replay(mockTraceHandler, mockTraceLogsHandler);
// Verify span level "application" tags precedence
JaegerTChannelCollectorHandler handler = new JaegerTChannelCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), "ProxyLevelAppTag", null);
Tag ipTag = new Tag("ip", TagType.STRING);
ipTag.setVStr("10.0.0.1");
Tag componentTag = new Tag("component", TagType.STRING);
componentTag.setVStr("db");
Tag spanLevelAppTag = new Tag("application", TagType.STRING);
spanLevelAppTag.setVStr("SpanLevelAppTag");
Tag processLevelAppTag = new Tag("application", TagType.STRING);
processLevelAppTag.setVStr("ProcessLevelAppTag");
io.jaegertracing.thriftjava.Span span1 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 1234567L, 0L, "HTTP GET", 1, startTime * 1000, 1234 * 1000);
io.jaegertracing.thriftjava.Span span2 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 2345678L, 1234567L, "HTTP GET /", 1, startTime * 1000, 2345 * 1000);
// check negative span IDs too
io.jaegertracing.thriftjava.Span span3 = new io.jaegertracing.thriftjava.Span(-97803834702328661L, 0L, -7344605349865507945L, -97803834702328661L, "HTTP GET /", 1, startTime * 1000, 3456 * 1000);
// Span1 to verify span level tags precedence
span1.setTags(ImmutableList.of(componentTag, spanLevelAppTag));
span2.setTags(ImmutableList.of(componentTag));
Batch testBatch = new Batch();
testBatch.process = new Process();
testBatch.process.serviceName = "frontend";
// Span2 to verify process level tags precedence
testBatch.process.setTags(ImmutableList.of(ipTag, processLevelAppTag));
testBatch.setSpans(ImmutableList.of(span1, span2));
Collector.submitBatches_args batches = new Collector.submitBatches_args();
batches.addToBatches(testBatch);
ThriftRequest<Collector.submitBatches_args> request = new ThriftRequest.Builder<Collector.submitBatches_args>("jaeger-collector", "Collector::submitBatches").setBody(batches).build();
handler.handleImpl(request);
// Span3 to verify process level tags precedence. So do not set any process level tag.
Batch testBatchForProxyLevel = new Batch();
testBatchForProxyLevel.process = new Process();
testBatchForProxyLevel.process.serviceName = "frontend";
testBatchForProxyLevel.process.setTags(ImmutableList.of(ipTag));
testBatchForProxyLevel.setSpans(ImmutableList.of(span3));
Collector.submitBatches_args batchesForProxyLevel = new Collector.submitBatches_args();
batchesForProxyLevel.addToBatches(testBatchForProxyLevel);
ThriftRequest<Collector.submitBatches_args> requestForProxyLevel = new ThriftRequest.Builder<Collector.submitBatches_args>("jaeger-collector", "Collector::submitBatches").setBody(batchesForProxyLevel).build();
handler.handleImpl(requestForProxyLevel);
verify(mockTraceHandler, mockTraceLogsHandler);
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorRuleV2PredicateTest method testPreprocessorSpanLogicalOps.
@Test
public void testPreprocessorSpanLogicalOps() {
// 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);
List<Map<String, Object>> rules = (List<Map<String, Object>>) rulesByPort.get("logicalop-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);
Span span = null;
// Satisfies all requirements.
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 " + "key1=val1 key2=val2 1532012145123 1532012146234");
Assert.assertTrue("Expected [logicalop-reportpoint] rule to return :: true , Actual :: false", v2Predicate.test(span));
// Tests for "ignore" : by not satisfying "regexMatch"/"equals" comparison
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 " + "key2=val2 1532012145123 1532012146234");
Assert.assertTrue("Expected [logicalop-reportpoint] rule to return :: true , Actual :: " + "false", v2Predicate.test(span));
// Tests for "all" : by not satisfying "equals" comparison
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 " + "key2=val 1532012145123 1532012146234");
Assert.assertFalse("Expected [logicalop-reportpoint] rule to return :: false , Actual :: " + "true", v2Predicate.test(span));
// Tests for "any" : by not satisfying "startsWith"/"endsWith" comparison
span = parseSpan("bootestSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 " + "key2=val2 1532012145123 1532012146234");
Assert.assertFalse("Expected [logicalop-reportpoint] rule to return :: false , Actual :: " + "true", v2Predicate.test(span));
// Tests for "none" : by satisfying "contains" comparison
span = parseSpan("testSpanName.1 " + "source=spanSourceName-prod " + "spanId=4217104a-690d-4927-baff-d9aa779414c2 " + "traceId=d5355bf7-fc8d-48d1-b761-75b170f396e0 " + "key2=val2 debug=debug-istrue 1532012145123 1532012146234");
Assert.assertFalse("Expected [logicalop-reportpoint] rule to return :: false , Actual :: " + "true", v2Predicate.test(span));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanAllowBlockRules.
@Test
public void testSpanAllowBlockRules() {
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 url=\"https://localhost:50051/style/foo/make?id=5145\" " + "1532012145123 1532012146234";
SpanBlockFilter blockRule;
SpanAllowFilter allowRule;
Span span = parseSpan(spanLine);
blockRule = new SpanBlockFilter(SPAN_NAME, "^test.*$", null, metrics);
allowRule = new SpanAllowFilter(SPAN_NAME, "^test.*$", null, metrics);
assertFalse(blockRule.test(span));
assertTrue(allowRule.test(span));
blockRule = new SpanBlockFilter(SPAN_NAME, "^ztest.*$", null, metrics);
allowRule = new SpanAllowFilter(SPAN_NAME, "^ztest.*$", null, metrics);
assertTrue(blockRule.test(span));
assertFalse(allowRule.test(span));
blockRule = new SpanBlockFilter(SOURCE_NAME, ".*ourceN.*", null, metrics);
allowRule = new SpanAllowFilter(SOURCE_NAME, ".*ourceN.*", null, metrics);
assertFalse(blockRule.test(span));
assertTrue(allowRule.test(span));
blockRule = new SpanBlockFilter(SOURCE_NAME, "ourceN.*", null, metrics);
allowRule = new SpanAllowFilter(SOURCE_NAME, "ourceN.*", null, metrics);
assertTrue(blockRule.test(span));
assertFalse(allowRule.test(span));
blockRule = new SpanBlockFilter("foo", "bar", null, metrics);
allowRule = new SpanAllowFilter("foo", "bar", null, metrics);
assertFalse(blockRule.test(span));
assertTrue(allowRule.test(span));
blockRule = new SpanBlockFilter("foo", "baz", null, metrics);
allowRule = new SpanAllowFilter("foo", "baz", null, metrics);
assertTrue(blockRule.test(span));
assertFalse(allowRule.test(span));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanWhitelistAnnotation.
@Test
public void testSpanWhitelistAnnotation() {
String spanLine = "\"testSpanName\" \"source\"=\"spanSourceName\" " + "\"spanId\"=\"4217104a-690d-4927-baff-d9aa779414c2\" " + "\"traceId\"=\"d5355bf7-fc8d-48d1-b761-75b170f396e0\" " + "\"application\"=\"app\" \"foo\"=\"bar1\" \"foo\"=\"bar2\" " + "\"key2\"=\"bar2\" \"bar\"=\"baz\" \"service\"=\"svc\" 1532012145123 1532012146234";
Span span = parseSpan(spanLine);
config.get("30124").get().forSpan().transform(span);
assertEquals(5, span.getAnnotations().size());
assertTrue(span.getAnnotations().contains(new Annotation("application", "app")));
assertTrue(span.getAnnotations().contains(new Annotation("foo", "bar1")));
assertTrue(span.getAnnotations().contains(new Annotation("foo", "bar2")));
assertTrue(span.getAnnotations().contains(new Annotation("key2", "bar2")));
assertTrue(span.getAnnotations().contains(new Annotation("service", "svc")));
span = parseSpan(spanLine);
config.get("30125").get().forSpan().transform(span);
assertEquals(3, span.getAnnotations().size());
assertTrue(span.getAnnotations().contains(new Annotation("application", "app")));
assertTrue(span.getAnnotations().contains(new Annotation("key2", "bar2")));
assertTrue(span.getAnnotations().contains(new Annotation("service", "svc")));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanRenameTagRule.
@Test
public void testSpanRenameTagRule() {
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";
SpanRenameAnnotationTransformer rule;
Span span;
// rename all annotations with key = "foo"
rule = new SpanRenameAnnotationTransformer(FOO, "foo1", null, false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("foo1", "foo1", "foo1", "foo1", "boo"), span.getAnnotations().stream().map(Annotation::getKey).collect(Collectors.toList()));
// rename all annotations with key = "foo" and value matching bar2.*
rule = new SpanRenameAnnotationTransformer(FOO, "foo1", "bar2.*", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of(FOO, "foo1", "foo1", FOO, "boo"), span.getAnnotations().stream().map(Annotation::getKey).collect(Collectors.toList()));
// rename only first annotations with key = "foo" and value matching bar2.*
rule = new SpanRenameAnnotationTransformer(FOO, "foo1", "bar2.*", true, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of(FOO, "foo1", FOO, FOO, "boo"), span.getAnnotations().stream().map(Annotation::getKey).collect(Collectors.toList()));
// try to rename a annotation whose value doesn't match the regex - shouldn't change
rule = new SpanRenameAnnotationTransformer(FOO, "foo1", "bar9.*", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of(FOO, FOO, FOO, FOO, "boo"), span.getAnnotations().stream().map(Annotation::getKey).collect(Collectors.toList()));
}
Aggregations