use of wavefront.report.Annotation 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()));
}
use of wavefront.report.Annotation 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()));
}
use of wavefront.report.Annotation 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()));
}
use of wavefront.report.Annotation 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()));
}
use of wavefront.report.Annotation 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()));
}
Aggregations