use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanForceLowercaseRule.
@Test
public void testSpanForceLowercaseRule() {
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";
SpanForceLowercaseTransformer rule;
Span span;
rule = new SpanForceLowercaseTransformer(SOURCE_NAME, null, false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals("spansourcename", span.getSource());
rule = new SpanForceLowercaseTransformer(SPAN_NAME, null, false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals("testspanname", span.getName());
rule = new SpanForceLowercaseTransformer(SPAN_NAME, "test.*", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals("testspanname", span.getName());
rule = new SpanForceLowercaseTransformer(SPAN_NAME, "nomatch", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals("testSpanName", span.getName());
rule = new SpanForceLowercaseTransformer(FOO, null, false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "bar2-2345678901", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
rule = new SpanForceLowercaseTransformer(FOO, null, true, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "BAR2-2345678901", "bAr2-3456789012", "baR"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
rule = new SpanForceLowercaseTransformer(FOO, "BAR.*", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "bar2-2345678901", "bAr2-3456789012", "baR"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
rule = new SpanForceLowercaseTransformer(FOO, "no_match", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("BAR1-1234567890", "BAR2-2345678901", "bAr2-3456789012", "baR"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanAddAnnotationRule.
@Test
public void testSpanAddAnnotationRule() {
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 SpanAddAnnotationTransformer(FOO, "baz2", null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "bar2-1234567890", "bar2-2345678901", "baz", "baz2"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class PreprocessorSpanRulesTest method testSpanDropAnnotationRule.
@Test
public void testSpanDropAnnotationRule() {
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";
SpanDropAnnotationTransformer rule;
Span span;
// drop first annotation with key = "foo"
rule = new SpanDropAnnotationTransformer(FOO, null, true, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar2-1234567890", "bar2-2345678901", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
// drop all annotations with key = "foo"
rule = new SpanDropAnnotationTransformer(FOO, null, false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of(), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
// drop all annotations with key = "foo" and value matching bar2.*
rule = new SpanDropAnnotationTransformer(FOO, "bar2.*", false, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
// drop first annotation with key = "foo" and value matching bar2.*
rule = new SpanDropAnnotationTransformer(FOO, "bar2.*", true, null, metrics);
span = rule.apply(parseSpan(spanLine));
assertEquals(ImmutableList.of("bar1-1234567890", "bar2-2345678901", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class SpanSamplerTest method testSpanSamplingPolicySamplingPercent.
@Test
public void testSpanSamplingPolicySamplingPercent() {
long startTime = System.currentTimeMillis();
Span span = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(UUID.randomUUID().toString()).build();
List<SpanSamplingPolicy> activeSpanSamplingPolicies = new ArrayList<>();
activeSpanSamplingPolicies.add(new SpanSamplingPolicy("SpanNamePolicy", "{{spanName}}='testSpanName'", 50));
SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> activeSpanSamplingPolicies);
int sampledSpans = 0;
for (int i = 0; i < 1000; i++) {
if (sampler.sample(Span.newBuilder(span).setTraceId(UUID.randomUUID().toString()).build())) {
sampledSpans++;
}
}
assertTrue(sampledSpans < 1000 && sampledSpans > 0);
activeSpanSamplingPolicies.clear();
activeSpanSamplingPolicies.add(new SpanSamplingPolicy("SpanNamePolicy", "{{spanName" + "}}='testSpanName'", 100));
sampledSpans = 0;
for (int i = 0; i < 1000; i++) {
if (sampler.sample(Span.newBuilder(span).setTraceId(UUID.randomUUID().toString()).build())) {
sampledSpans++;
}
}
assertEquals(1000, sampledSpans);
activeSpanSamplingPolicies.clear();
activeSpanSamplingPolicies.add(new SpanSamplingPolicy("SpanNamePolicy", "{{spanName" + "}}='testSpanName'", 0));
sampledSpans = 0;
for (int i = 0; i < 1000; i++) {
if (sampler.sample(Span.newBuilder(span).setTraceId(UUID.randomUUID().toString()).build())) {
sampledSpans++;
}
}
assertEquals(0, sampledSpans);
}
use of wavefront.report.Span in project java by wavefrontHQ.
the class SpanSamplerTest method testSample.
@Test
public void testSample() {
long startTime = System.currentTimeMillis();
String traceId = UUID.randomUUID().toString();
Span spanToAllow = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(6).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).build();
Span spanToDiscard = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("testSpanName").setSource("testsource").setSpanId("testspanid").setTraceId(traceId).build();
SpanSampler sampler = new SpanSampler(new DurationSampler(5), () -> null);
assertTrue(sampler.sample(spanToAllow));
assertFalse(sampler.sample(spanToDiscard));
Counter discarded = Metrics.newCounter(new MetricName("SpanSamplerTest", "testSample", "discarded"));
assertTrue(sampler.sample(spanToAllow, discarded));
assertEquals(0, discarded.count());
assertFalse(sampler.sample(spanToDiscard, discarded));
assertEquals(1, discarded.count());
}
Aggregations