Search in sources :

Example 41 with Span

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()));
}
Also used : Annotation(wavefront.report.Annotation) BeforeClass(org.junit.BeforeClass) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Span(wavefront.report.Span) Collectors(java.util.stream.Collectors) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Span(wavefront.report.Span) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 42 with Span

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()));
}
Also used : Annotation(wavefront.report.Annotation) BeforeClass(org.junit.BeforeClass) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Span(wavefront.report.Span) Collectors(java.util.stream.Collectors) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Span(wavefront.report.Span) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 43 with Span

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()));
}
Also used : Annotation(wavefront.report.Annotation) BeforeClass(org.junit.BeforeClass) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Span(wavefront.report.Span) Collectors(java.util.stream.Collectors) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Span(wavefront.report.Span) TestUtils.parseSpan(com.wavefront.agent.TestUtils.parseSpan) Annotation(wavefront.report.Annotation) Test(org.junit.Test)

Example 44 with Span

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);
}
Also used : ArrayList(java.util.ArrayList) Span(wavefront.report.Span) SpanSamplingPolicy(com.wavefront.api.agent.SpanSamplingPolicy) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Test(org.junit.Test)

Example 45 with Span

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());
}
Also used : MetricName(com.yammer.metrics.core.MetricName) Counter(com.yammer.metrics.core.Counter) Span(wavefront.report.Span) DurationSampler(com.wavefront.sdk.entities.tracing.sampling.DurationSampler) Test(org.junit.Test)

Aggregations

Span (wavefront.report.Span)49 Test (org.junit.Test)35 Annotation (wavefront.report.Annotation)34 SpanSampler (com.wavefront.agent.sampler.SpanSampler)18 TestUtils.parseSpan (com.wavefront.agent.TestUtils.parseSpan)15 Collectors (java.util.stream.Collectors)13 IOException (java.io.IOException)12 InputStream (java.io.InputStream)12 ReportableEntityPreprocessor (com.wavefront.agent.preprocessor.ReportableEntityPreprocessor)10 Batch (io.jaegertracing.thriftjava.Batch)10 ImmutableList (com.google.common.collect.ImmutableList)9 Tag (io.jaegertracing.thriftjava.Tag)9 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 Assert.assertFalse (org.junit.Assert.assertFalse)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 BeforeClass (org.junit.BeforeClass)9 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)8 List (java.util.List)8 Map (java.util.Map)8