Search in sources :

Example 11 with Span

use of wavefront.report.Span in project java by wavefrontHQ.

the class PreprocessorSpanRulesTest method testSpanExtractAnnotationRule.

@Test
public void testSpanExtractAnnotationRule() {
    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";
    SpanExtractAnnotationTransformer rule;
    Span span;
    // extract annotation for first value
    rule = new SpanExtractAnnotationTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz", "1234567890"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1", "bar2-2345678901", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // extract annotation for first value matching "bar2.*"
    rule = new SpanExtractAnnotationTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", "bar2.*", true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz", "2345678901"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1-1234567890", "bar2", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // extract annotation for all values
    rule = new SpanExtractAnnotationTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz", "1234567890", "2345678901", "3456789012"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1", "bar2", "bar2", "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 12 with Span

use of wavefront.report.Span in project java by wavefrontHQ.

the class PreprocessorSpanRulesTest method testSpanLimitRule.

@Test
public void testSpanLimitRule() {
    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";
    SpanLimitLengthTransformer rule;
    Span span;
    // ** span name
    // no regex, name gets truncated
    rule = new SpanLimitLengthTransformer(SPAN_NAME, 8, LengthLimitActionType.TRUNCATE, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("testSpan", span.getName());
    // span name matches, gets truncated
    rule = new SpanLimitLengthTransformer(SPAN_NAME, 8, LengthLimitActionType.TRUNCATE_WITH_ELLIPSIS, "^test.*", false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(8, span.getName().length());
    assertTrue(span.getName().endsWith("..."));
    // span name does not match, no change
    rule = new SpanLimitLengthTransformer(SPAN_NAME, 8, LengthLimitActionType.TRUNCATE, "nope.*", false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("testSpanName", span.getName());
    // ** source name
    // no regex, source gets truncated
    rule = new SpanLimitLengthTransformer(SOURCE_NAME, 10, LengthLimitActionType.TRUNCATE, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(10, span.getSource().length());
    // source name matches, gets truncated
    rule = new SpanLimitLengthTransformer(SOURCE_NAME, 10, LengthLimitActionType.TRUNCATE_WITH_ELLIPSIS, "^spanS.*", false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(10, span.getSource().length());
    assertTrue(span.getSource().endsWith("..."));
    // source name does not match, no change
    rule = new SpanLimitLengthTransformer(SOURCE_NAME, 10, LengthLimitActionType.TRUNCATE, "nope.*", false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("spanSourceName", span.getSource());
    // ** annotations
    // no regex, annotation gets truncated
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.TRUNCATE, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar1", "bar2", "bar2", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // no regex, annotations exceeding length limit get dropped
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.DROP, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // annotation has matches, which get truncated
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.TRUNCATE_WITH_ELLIPSIS, "bar2-.*", false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar1-1234567890", "b...", "b...", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // annotation has matches, only first one gets truncated
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.TRUNCATE, "bar2-.*", true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar1-1234567890", "bar2", "bar2-2345678901", "baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // annotation has matches, only first one gets dropped
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.DROP, "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()));
    // annotation has no matches, no changes
    rule = new SpanLimitLengthTransformer(FOO, 4, LengthLimitActionType.TRUNCATE, ".*nope.*", false, 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()));
}
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 13 with Span

use of wavefront.report.Span in project java by wavefrontHQ.

the class PreprocessorSpanRulesTest method testSpanExtractAnnotationIfNotExistsRule.

@Test
public void testSpanExtractAnnotationIfNotExistsRule() {
    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";
    SpanExtractAnnotationIfNotExistsTransformer rule;
    Span span;
    // extract annotation for first value
    rule = new SpanExtractAnnotationIfNotExistsTransformer("baz", FOO, "(....)-(.*)$", "$2", "$1", null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("1234567890"), span.getAnnotations().stream().filter(x -> x.getKey().equals("baz")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1", "bar2-2345678901", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // extract annotation for first value matching "bar2.*
    rule = new SpanExtractAnnotationIfNotExistsTransformer("baz", FOO, "(....)-(.*)$", "$2", "$1", "bar2.*", true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("2345678901"), span.getAnnotations().stream().filter(x -> x.getKey().equals("baz")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1-1234567890", "bar2", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // extract annotation for all values
    rule = new SpanExtractAnnotationIfNotExistsTransformer("baz", FOO, "(....)-(.*)$", "$2", "$1", null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("1234567890", "2345678901", "3456789012"), span.getAnnotations().stream().filter(x -> x.getKey().equals("baz")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("bar1", "bar2", "bar2", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    // annotation key already exists, should remain unchanged
    rule = new SpanExtractAnnotationIfNotExistsTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    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()));
    // annotation key already exists, should remain unchanged
    rule = new SpanExtractAnnotationIfNotExistsTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", "bar2.*", true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    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()));
    // annotation key already exists, should remain unchanged
    rule = new SpanExtractAnnotationIfNotExistsTransformer("boo", FOO, "(....)-(.*)$", "$2", "$1", null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("baz"), span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).collect(Collectors.toList()));
    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 14 with Span

use of wavefront.report.Span in project java by wavefrontHQ.

the class PreprocessorSpanRulesTest method testSpanSanitizeTransformer.

@Test
public void testSpanSanitizeTransformer() {
    Span span = Span.newBuilder().setCustomer("dummy").setStartMillis(System.currentTimeMillis()).setDuration(2345).setName(" HTT*P GET\"\n? ").setSource("'customJaegerSource'").setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("service", "frontend"), new Annotation("special|tag:", "''"), new Annotation("specialvalue", " hello \n world "))).build();
    SpanSanitizeTransformer transformer = new SpanSanitizeTransformer(metrics);
    span = transformer.apply(span);
    assertEquals("HTT-P GET\"\\n?", span.getName());
    assertEquals("-customJaegerSource-", span.getSource());
    assertEquals(ImmutableList.of("''"), span.getAnnotations().stream().filter(x -> x.getKey().equals("special-tag-")).map(Annotation::getValue).collect(Collectors.toList()));
    assertEquals(ImmutableList.of("hello \\n world"), span.getAnnotations().stream().filter(x -> x.getKey().equals("specialvalue")).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 15 with Span

use of wavefront.report.Span in project java by wavefrontHQ.

the class PreprocessorSpanRulesTest method testSpanReplaceRegexRule.

@Test
public void testSpanReplaceRegexRule() {
    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";
    SpanReplaceRegexTransformer rule;
    Span span;
    rule = new SpanReplaceRegexTransformer(SPAN_NAME, "test", "", null, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("SpanName", span.getName());
    rule = new SpanReplaceRegexTransformer(SOURCE_NAME, "Name", "Z", null, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("spanSourceZ", span.getSource());
    rule = new SpanReplaceRegexTransformer(SOURCE_NAME, "Name", "Z", "span.*", null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("spanSourceZ", span.getSource());
    rule = new SpanReplaceRegexTransformer(SOURCE_NAME, "Name", "Z", "no_match", null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("spanSourceName", span.getSource());
    rule = new SpanReplaceRegexTransformer(FOO, "234", "zzz", null, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar1-1zzz567890", "bar2-zzz5678901", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    rule = new SpanReplaceRegexTransformer(FOO, "901", "zzz", null, null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar1-1234567890", "bar2-2345678zzz", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    rule = new SpanReplaceRegexTransformer(FOO, "\\d-\\d", "@", null, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar@234567890", "bar@345678901", "bar@456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    rule = new SpanReplaceRegexTransformer(FOO, "\\d-\\d", "@", null, null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("bar@234567890", "bar2-2345678901", "bar2-3456789012", "bar"), span.getAnnotations().stream().filter(x -> x.getKey().equals(FOO)).map(Annotation::getValue).collect(Collectors.toList()));
    rule = new SpanReplaceRegexTransformer(URL, "(https:\\/\\/.+\\/style\\/foo\\/make\\?id=)(.*)", "$1REDACTED", null, null, true, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals(ImmutableList.of("https://localhost:50051/style/foo/make?id=REDACTED"), span.getAnnotations().stream().filter(x -> x.getKey().equals(URL)).map(Annotation::getValue).collect(Collectors.toList()));
    rule = new SpanReplaceRegexTransformer("boo", "^.*$", "{{foo}}-{{spanName}}-{{sourceName}}{{}}", null, null, false, null, metrics);
    span = rule.apply(parseSpan(spanLine));
    assertEquals("bar1-1234567890-testSpanName-spanSourceName{{}}", span.getAnnotations().stream().filter(x -> x.getKey().equals("boo")).map(Annotation::getValue).findFirst().orElse("fail"));
}
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)

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