From caf579a301d7d85d510e56cb0be886997d8f71d0 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 23 Aug 2017 15:38:03 +0800 Subject: [PATCH] Organizes v2 classes into corresponding internal packages --- .../zipkin/benchmarks/CodecBenchmarks.java | 49 +++-- .../benchmarks/Span2ConverterBenchmarks.java | 25 ++- .../zipkin/benchmarks/SpanBenchmarks.java | 37 ++-- .../collector/kafka/KafkaCollectorTest.java | 6 +- .../collector/kafka10/KafkaCollectorTest.java | 6 +- .../java/zipkin/junit/ZipkinDispatcher.java | 4 +- .../java/zipkin/junit/ZipkinRuleTest.java | 6 +- .../zipkin/server/ZipkinHttpCollector.java | 4 +- .../server/ZipkinServerIntegrationTest.java | 6 +- .../http/ElasticsearchHttpSpanConsumer.java | 12 +- .../http/ElasticsearchHttpStorage.java | 16 +- .../elasticsearch/http/JsonAdapters.java | 17 +- .../ElasticsearchHttpSpanConsumerTest.java | 34 ++-- .../http/ElasticsearchHttpStorageTest.java | 3 - .../elasticsearch/http/JsonAdaptersTest.java | 17 +- ...java => DependencyLinkV2SpanIterator.java} | 26 +-- .../zipkin/storage/mysql/MySQLSpanStore.java | 39 ++-- ... => DependencyLinkV2SpanIteratorTest.java} | 74 +++---- zipkin/bnd.bnd | 5 +- .../main/java/zipkin/collector/Collector.java | 39 ++-- .../internal/AsyncSpan2ConsumerAdapter.java | 42 ---- .../zipkin/internal/DependencyLinker.java | 60 +++--- .../zipkin/internal/DetectingSpanDecoder.java | 2 +- .../java/zipkin/internal/Span2Component.java | 21 -- .../{Collector2.java => V2Collector.java} | 21 +- ...panDecoder.java => V2JsonSpanDecoder.java} | 14 +- ...an2Converter.java => V2SpanConverter.java} | 74 +++---- .../zipkin/internal/V2StorageComponent.java | 46 +++++ .../internal/{Span2.java => v2/Span.java} | 80 ++++---- .../zipkin/internal/v2/codec/Decoder.java | 9 +- .../zipkin/internal/v2/codec/Encoder.java | 9 +- .../internal/v2/codec/Span2JsonAdapters.java | 24 +-- .../v2/storage/AsyncSpanConsumer.java | 4 +- .../main/java/zipkin/storage/SpanStore.java | 26 +-- .../src/test/java/zipkin/AnnotationTest.java | 2 +- .../collector/CollectorSamplerTest.java | 10 +- .../java/zipkin/collector/CollectorTest.java | 22 +- .../zipkin/internal/DependencyLinkerTest.java | 78 +++---- .../internal/DetectingSpanDecoderTest.java | 12 +- ...erTest.java => V2JsonSpanDecoderTest.java} | 16 +- ...rterTest.java => V2SpanConverterTest.java} | 192 +++++++++--------- .../{Span2Test.java => v2/SpanTest.java} | 31 +-- ...ersTest.java => SpanJsonAdaptersTest.java} | 22 +- 43 files changed, 609 insertions(+), 633 deletions(-) rename zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/{DependencyLinkSpan2Iterator.java => DependencyLinkV2SpanIterator.java} (88%) rename zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/{DependencyLinkSpan2IteratorTest.java => DependencyLinkV2SpanIteratorTest.java} (81%) delete mode 100644 zipkin/src/main/java/zipkin/internal/AsyncSpan2ConsumerAdapter.java delete mode 100644 zipkin/src/main/java/zipkin/internal/Span2Component.java rename zipkin/src/main/java/zipkin/internal/{Collector2.java => V2Collector.java} (64%) rename zipkin/src/main/java/zipkin/internal/{Span2JsonSpanDecoder.java => V2JsonSpanDecoder.java} (74%) rename zipkin/src/main/java/zipkin/internal/{Span2Converter.java => V2SpanConverter.java} (88%) create mode 100644 zipkin/src/main/java/zipkin/internal/V2StorageComponent.java rename zipkin/src/main/java/zipkin/internal/{Span2.java => v2/Span.java} (89%) rename zipkin/src/test/java/zipkin/internal/{Span2JsonSpanDecoderTest.java => V2JsonSpanDecoderTest.java} (77%) rename zipkin/src/test/java/zipkin/internal/{Span2ConverterTest.java => V2SpanConverterTest.java} (86%) rename zipkin/src/test/java/zipkin/internal/{Span2Test.java => v2/SpanTest.java} (86%) rename zipkin/src/test/java/zipkin/internal/v2/codec/{Span2JsonAdaptersTest.java => SpanJsonAdaptersTest.java} (95%) diff --git a/benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java b/benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java index 3c9aea2fb3d..50d8a1e6fdb 100644 --- a/benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java +++ b/benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java @@ -41,8 +41,7 @@ import org.openjdk.jmh.runner.options.OptionsBuilder; import zipkin.Codec; import zipkin.Endpoint; -import zipkin.Span; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.MessageEncoder; import zipkin.internal.v2.codec.Decoder; import zipkin.internal.v2.codec.Encoder; @@ -66,22 +65,22 @@ public class CodecBenchmarks { static final TBinaryProtocol.Factory TBINARY_PROTOCOL_FACTORY = new TBinaryProtocol.Factory(); static final byte[] localSpanJson = read("/span-local.json"); - static final Span localSpan = Codec.JSON.readSpan(localSpanJson); + static final zipkin.Span localSpan = Codec.JSON.readSpan(localSpanJson); static final byte[] localSpanThrift = Codec.THRIFT.writeSpan(localSpan); static final com.twitter.zipkin.thriftjava.Span localSpanLibThrift = deserialize(localSpanThrift); @Benchmark - public Span readLocalSpan_json_zipkin() { + public zipkin.Span readLocalSpan_json_zipkin() { return Codec.JSON.readSpan(localSpanJson); } @Benchmark - public Span readLocalSpan_thrift_zipkin() { + public zipkin.Span readLocalSpan_thrift_zipkin() { return Codec.THRIFT.readSpan(localSpanThrift); } @Benchmark - public Span readLocalSpan_thrift_libthrift() { + public zipkin.Span readLocalSpan_thrift_libthrift() { return toZipkinSpan(deserialize(localSpanThrift)); } @@ -101,36 +100,36 @@ public byte[] writeLocalSpan_thrift_libthrift() throws TException { } static final byte[] clientSpanJson = read("/span-client.json"); - static final Span clientSpan = Codec.JSON.readSpan(clientSpanJson); + static final zipkin.Span clientSpan = Codec.JSON.readSpan(clientSpanJson); static final byte[] clientSpanThrift = Codec.THRIFT.writeSpan(clientSpan); static final com.twitter.zipkin.thriftjava.Span clientSpanLibThrift = deserialize(clientSpanThrift); - static final List tenClientSpans = Collections.nCopies(10, clientSpan); + static final List tenClientSpans = Collections.nCopies(10, clientSpan); static final byte[] tenClientSpansJson = Codec.JSON.writeSpans(tenClientSpans); static final byte[] tenClientSpansThrift = Codec.THRIFT.writeSpans(tenClientSpans); @Benchmark - public Span readClientSpan_json_zipkin() { + public zipkin.Span readClientSpan_json_zipkin() { return Codec.JSON.readSpan(clientSpanJson); } @Benchmark - public List readTenClientSpans_json_zipkin() { + public List readTenClientSpans_json_zipkin() { return Codec.JSON.readSpans(tenClientSpansJson); } @Benchmark - public Span readClientSpan_thrift_zipkin() { + public zipkin.Span readClientSpan_thrift_zipkin() { return Codec.THRIFT.readSpan(clientSpanThrift); } @Benchmark - public List readTenClientSpans_thrift_zipkin() { + public List readTenClientSpans_thrift_zipkin() { return Codec.THRIFT.readSpans(tenClientSpansThrift); } @Benchmark - public Span readClientSpan_thrift_libthrift() { + public zipkin.Span readClientSpan_thrift_libthrift() { return toZipkinSpan(deserialize(clientSpanThrift)); } @@ -159,13 +158,13 @@ public byte[] writeClientSpan_thrift_libthrift() throws TException { return serialize(clientSpanLibThrift); } - static final Span2 span2 = Decoder.JSON.decodeList(read("/span2.json")).get(0); + static final Span span2 = Decoder.JSON.decodeList(read("/span2.json")).get(0); static final byte[] tenClientSpan2sJson = MessageEncoder.JSON_BYTES.encode( Collections.nCopies(10, span2).stream().map(Encoder.JSON::encode).collect(Collectors.toList()) ); @Benchmark - public List readTenClientSpans_json_span2() { + public List readTenClientSpans_json_span2() { return Decoder.JSON.decodeList(tenClientSpan2sJson); } @@ -175,22 +174,22 @@ public byte[] writeClientSpan_json_span2() { } static final byte[] rpcSpanJson = read("/span-rpc.json"); - static final Span rpcSpan = Codec.JSON.readSpan(rpcSpanJson); + static final zipkin.Span rpcSpan = Codec.JSON.readSpan(rpcSpanJson); static final byte[] rpcSpanThrift = Codec.THRIFT.writeSpan(rpcSpan); static final com.twitter.zipkin.thriftjava.Span rpcSpanLibThrift = deserialize(rpcSpanThrift); @Benchmark - public Span readRpcSpan_json_zipkin() { + public zipkin.Span readRpcSpan_json_zipkin() { return Codec.JSON.readSpan(rpcSpanJson); } @Benchmark - public Span readRpcSpan_thrift_zipkin() { + public zipkin.Span readRpcSpan_thrift_zipkin() { return Codec.THRIFT.readSpan(rpcSpanThrift); } @Benchmark - public Span readRpcSpan_thrift_libthrift() { + public zipkin.Span readRpcSpan_thrift_libthrift() { return toZipkinSpan(deserialize(rpcSpanThrift)); } @@ -210,22 +209,22 @@ public byte[] writeRpcSpan_thrift_libthrift() throws TException { } static final byte[] rpcV6SpanJson = read("/span-rpc-ipv6.json"); - static final Span rpcV6Span = Codec.JSON.readSpan(rpcV6SpanJson); + static final zipkin.Span rpcV6Span = Codec.JSON.readSpan(rpcV6SpanJson); static final byte[] rpcV6SpanThrift = Codec.THRIFT.writeSpan(rpcV6Span); static final com.twitter.zipkin.thriftjava.Span rpcV6SpanLibThrift = deserialize(rpcV6SpanThrift); @Benchmark - public Span readRpcV6Span_json_zipkin() { + public zipkin.Span readRpcV6Span_json_zipkin() { return Codec.JSON.readSpan(rpcV6SpanJson); } @Benchmark - public Span readRpcV6Span_thrift_zipkin() { + public zipkin.Span readRpcV6Span_thrift_zipkin() { return Codec.THRIFT.readSpan(rpcV6SpanThrift); } @Benchmark - public Span readRpcV6Span_thrift_libthrift() { + public zipkin.Span readRpcV6Span_thrift_libthrift() { return toZipkinSpan(deserialize(rpcV6SpanThrift)); } @@ -282,8 +281,8 @@ private static com.twitter.zipkin.thriftjava.Span deserialize(byte[] serialized) * uses immutable collections, etc. When comparing codec, make sure you copy-out as structs like * libthrift do no validation, which is cheaper, but not usable in zipkin. */ - private static Span toZipkinSpan(com.twitter.zipkin.thriftjava.Span libthriftSpan) { - Span.Builder builder = Span.builder() + private static zipkin.Span toZipkinSpan(com.twitter.zipkin.thriftjava.Span libthriftSpan) { + zipkin.Span.Builder builder = zipkin.Span.builder() .traceId(libthriftSpan.trace_id) .id(libthriftSpan.id) .parentId(libthriftSpan.isSetParent_id() ? libthriftSpan.parent_id : null) diff --git a/benchmarks/src/main/java/zipkin/benchmarks/Span2ConverterBenchmarks.java b/benchmarks/src/main/java/zipkin/benchmarks/Span2ConverterBenchmarks.java index 4c9655ea960..08894d3ea77 100644 --- a/benchmarks/src/main/java/zipkin/benchmarks/Span2ConverterBenchmarks.java +++ b/benchmarks/src/main/java/zipkin/benchmarks/Span2ConverterBenchmarks.java @@ -33,10 +33,9 @@ import zipkin.BinaryAnnotation; import zipkin.Constants; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TraceKeys; -import zipkin.internal.Span2; -import zipkin.internal.Span2Converter; +import zipkin.internal.v2.Span; +import zipkin.internal.V2SpanConverter; import zipkin.internal.Util; @Measurement(iterations = 5, time = 1) @@ -54,7 +53,7 @@ public class Span2ConverterBenchmarks { .port(9000) .build(); - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -76,7 +75,7 @@ public class Span2ConverterBenchmarks { .addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, backend)) .build(); - Span server = Span.builder() + zipkin.Span server = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -89,12 +88,12 @@ public class Span2ConverterBenchmarks { .addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, frontend)) .build(); - Span2 server2 = Span2.builder() + Span server2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("get") - .kind(Span2.Kind.SERVER) + .kind(Span.Kind.SERVER) .shared(true) .localEndpoint(backend) .remoteEndpoint(frontend) @@ -104,16 +103,16 @@ public class Span2ConverterBenchmarks { .putTag("srv/finagle.version", "6.44.0") .build(); - @Benchmark public List fromSpan_splitShared() { - return Span2Converter.fromSpan(shared); + @Benchmark public List fromSpan_splitShared() { + return V2SpanConverter.fromSpan(shared); } - @Benchmark public List fromSpan() { - return Span2Converter.fromSpan(server); + @Benchmark public List fromSpan() { + return V2SpanConverter.fromSpan(server); } - @Benchmark public Span toSpan() { - return Span2Converter.toSpan(server2); + @Benchmark public zipkin.Span toSpan() { + return V2SpanConverter.toSpan(server2); } // Convenience main entry-point diff --git a/benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java b/benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java index a50b552f4cd..7cb5fd54d5b 100644 --- a/benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java +++ b/benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java @@ -32,9 +32,8 @@ import zipkin.BinaryAnnotation; import zipkin.Constants; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TraceKeys; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.internal.Util; @Measurement(iterations = 5, time = 1) @@ -50,17 +49,17 @@ public class SpanBenchmarks { static final Endpoint app = Endpoint.builder().serviceName("app").ipv4(172 << 24 | 17 << 16 | 2).port(8080).build(); - final Span.Builder sharedBuilder; - final Span2.Builder shared2Builder; + final zipkin.Span.Builder sharedBuilder; + final Span.Builder shared2Builder; public SpanBenchmarks() { - sharedBuilder = buildClientOnlySpan(Span.builder()).toBuilder(); + sharedBuilder = buildClientOnlySpan(zipkin.Span.builder()).toBuilder(); shared2Builder = buildClientOnlySpan2().toBuilder(); } @Benchmark - public Span buildLocalSpan() { - return Span.builder() + public zipkin.Span buildLocalSpan() { + return zipkin.Span.builder() .traceId(1L) .id(1L) .name("work") @@ -80,11 +79,11 @@ public Span buildLocalSpan() { .build(); @Benchmark - public Span buildClientOnlySpan() { - return buildClientOnlySpan(Span.builder()); + public zipkin.Span buildClientOnlySpan() { + return buildClientOnlySpan(zipkin.Span.builder()); } - static Span buildClientOnlySpan(Span.Builder builder) { + static zipkin.Span buildClientOnlySpan(zipkin.Span.Builder builder) { return builder .traceId(traceId) .parentId(traceId) @@ -103,22 +102,22 @@ static Span buildClientOnlySpan(Span.Builder builder) { } @Benchmark - public Span buildClientOnlySpan_clear() { + public zipkin.Span buildClientOnlySpan_clear() { return buildClientOnlySpan(sharedBuilder.clear()); } @Benchmark - public Span2 buildClientOnlySpan2() { - return buildClientOnlySpan2(Span2.builder()); + public Span buildClientOnlySpan2() { + return buildClientOnlySpan2(Span.builder()); } - static Span2 buildClientOnlySpan2(Span2.Builder builder) { + static Span buildClientOnlySpan2(Span.Builder builder) { return builder .traceId(traceId) .parentId(traceId) .id(spanId) .name("get") - .kind(Span2.Kind.CLIENT) + .kind(Span.Kind.CLIENT) .localEndpoint(frontend) .remoteEndpoint(backend) .timestamp(1472470996199000L) @@ -131,18 +130,18 @@ static Span2 buildClientOnlySpan2(Span2.Builder builder) { } @Benchmark - public Span2 buildClientOnlySpan2_clear() { + public Span buildClientOnlySpan2_clear() { return buildClientOnlySpan2(shared2Builder.clear()); } @Benchmark - public Span2 buildClientOnlySpan2_clone() { + public Span buildClientOnlySpan2_clone() { return shared2Builder.clone().build(); } @Benchmark - public Span buildRpcSpan() { - return Span.builder() // web calls app + public zipkin.Span buildRpcSpan() { + return zipkin.Span.builder() // web calls app .traceId(1L) .id(2L) .parentId(1L) diff --git a/zipkin-collector/kafka/src/test/java/zipkin/collector/kafka/KafkaCollectorTest.java b/zipkin-collector/kafka/src/test/java/zipkin/collector/kafka/KafkaCollectorTest.java index 115323754de..6bee5115fd4 100644 --- a/zipkin-collector/kafka/src/test/java/zipkin/collector/kafka/KafkaCollectorTest.java +++ b/zipkin-collector/kafka/src/test/java/zipkin/collector/kafka/KafkaCollectorTest.java @@ -31,7 +31,7 @@ import zipkin.collector.InMemoryCollectorMetrics; import zipkin.collector.kafka.KafkaCollector.Builder; import zipkin.internal.ApplyTimestampAndDuration; -import zipkin.internal.Span2Converter; +import zipkin.internal.V2SpanConverter; import zipkin.internal.v2.codec.MessageEncoder; import zipkin.internal.v2.codec.Encoder; import zipkin.storage.AsyncSpanConsumer; @@ -148,8 +148,8 @@ public void messageWithMultipleSpans_json2() throws Exception { ); byte[] message = MessageEncoder.JSON_BYTES.encode(asList( - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(0)).get(0)), - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(1)).get(0)) + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)), + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0)) )); producer.send(new KeyedMessage<>(builder.topic, message)); diff --git a/zipkin-collector/kafka10/src/test/java/zipkin/collector/kafka10/KafkaCollectorTest.java b/zipkin-collector/kafka10/src/test/java/zipkin/collector/kafka10/KafkaCollectorTest.java index bccd13d213c..d5e8333a871 100644 --- a/zipkin-collector/kafka10/src/test/java/zipkin/collector/kafka10/KafkaCollectorTest.java +++ b/zipkin-collector/kafka10/src/test/java/zipkin/collector/kafka10/KafkaCollectorTest.java @@ -38,7 +38,7 @@ import zipkin.collector.InMemoryCollectorMetrics; import zipkin.collector.kafka10.KafkaCollector.Builder; import zipkin.internal.ApplyTimestampAndDuration; -import zipkin.internal.Span2Converter; +import zipkin.internal.V2SpanConverter; import zipkin.internal.v2.codec.MessageEncoder; import zipkin.internal.v2.codec.Encoder; import zipkin.storage.AsyncSpanConsumer; @@ -202,8 +202,8 @@ public void messageWithMultipleSpans_json2() throws Exception { ); byte[] message = MessageEncoder.JSON_BYTES.encode(asList( - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(0)).get(0)), - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(1)).get(0)) + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)), + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0)) )); produceSpans(message, builder.topic); diff --git a/zipkin-junit/src/main/java/zipkin/junit/ZipkinDispatcher.java b/zipkin-junit/src/main/java/zipkin/junit/ZipkinDispatcher.java index ae2d9904343..680a1e386cb 100644 --- a/zipkin-junit/src/main/java/zipkin/junit/ZipkinDispatcher.java +++ b/zipkin-junit/src/main/java/zipkin/junit/ZipkinDispatcher.java @@ -28,7 +28,7 @@ import zipkin.SpanDecoder; import zipkin.collector.Collector; import zipkin.collector.CollectorMetrics; -import zipkin.internal.Span2JsonSpanDecoder; +import zipkin.internal.V2JsonSpanDecoder; import zipkin.storage.Callback; import zipkin.storage.QueryRequest; import zipkin.storage.SpanStore; @@ -37,7 +37,7 @@ import static zipkin.internal.Util.lowerHexToUnsignedLong; final class ZipkinDispatcher extends Dispatcher { - static final SpanDecoder JSON2_DECODER = new Span2JsonSpanDecoder(); + static final SpanDecoder JSON2_DECODER = new V2JsonSpanDecoder(); private final SpanStore store; private final Collector consumer; diff --git a/zipkin-junit/src/test/java/zipkin/junit/ZipkinRuleTest.java b/zipkin-junit/src/test/java/zipkin/junit/ZipkinRuleTest.java index befe7f1a800..2b36be3008f 100644 --- a/zipkin-junit/src/test/java/zipkin/junit/ZipkinRuleTest.java +++ b/zipkin-junit/src/test/java/zipkin/junit/ZipkinRuleTest.java @@ -31,7 +31,7 @@ import zipkin.Codec; import zipkin.Span; import zipkin.internal.ApplyTimestampAndDuration; -import zipkin.internal.Span2Converter; +import zipkin.internal.V2SpanConverter; import zipkin.internal.v2.codec.MessageEncoder; import zipkin.internal.v2.codec.Encoder; @@ -70,8 +70,8 @@ public void getTraces_storedViaPostVersion2() throws IOException { ); byte[] message = MessageEncoder.JSON_BYTES.encode(asList( - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(0)).get(0)), - Encoder.JSON.encode(Span2Converter.fromSpan(spans.get(1)).get(0)) + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)), + Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0)) )); // write the span to the zipkin using http api v2 diff --git a/zipkin-server/src/main/java/zipkin/server/ZipkinHttpCollector.java b/zipkin-server/src/main/java/zipkin/server/ZipkinHttpCollector.java index be94a0b5d17..440905add90 100644 --- a/zipkin-server/src/main/java/zipkin/server/ZipkinHttpCollector.java +++ b/zipkin-server/src/main/java/zipkin/server/ZipkinHttpCollector.java @@ -32,7 +32,7 @@ import zipkin.collector.CollectorMetrics; import zipkin.collector.CollectorSampler; import zipkin.internal.Nullable; -import zipkin.internal.Span2JsonSpanDecoder; +import zipkin.internal.V2JsonSpanDecoder; import zipkin.storage.Callback; import zipkin.storage.StorageComponent; @@ -47,7 +47,7 @@ public class ZipkinHttpCollector { static final ResponseEntity SUCCESS = ResponseEntity.accepted().build(); static final String APPLICATION_THRIFT = "application/x-thrift"; - static final SpanDecoder JSON2_DECODER = new Span2JsonSpanDecoder(); + static final SpanDecoder JSON2_DECODER = new V2JsonSpanDecoder(); final CollectorMetrics metrics; final Collector collector; diff --git a/zipkin-server/src/test/java/zipkin/server/ZipkinServerIntegrationTest.java b/zipkin-server/src/test/java/zipkin/server/ZipkinServerIntegrationTest.java index 50e82acd276..f5ce83080fd 100644 --- a/zipkin-server/src/test/java/zipkin/server/ZipkinServerIntegrationTest.java +++ b/zipkin-server/src/test/java/zipkin/server/ZipkinServerIntegrationTest.java @@ -32,9 +32,9 @@ import zipkin.Codec; import zipkin.Span; import zipkin.internal.ApplyTimestampAndDuration; -import zipkin.internal.Span2Converter; -import zipkin.internal.v2.codec.MessageEncoder; +import zipkin.internal.V2SpanConverter; import zipkin.internal.v2.codec.Encoder; +import zipkin.internal.v2.codec.MessageEncoder; import zipkin.storage.InMemoryStorage; import static java.lang.String.format; @@ -86,7 +86,7 @@ public void writeSpans_version2() throws Exception { Span span = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); byte[] message = MessageEncoder.JSON_BYTES.encode(asList( - Encoder.JSON.encode(Span2Converter.fromSpan(span).get(0)) + Encoder.JSON.encode(V2SpanConverter.fromSpan(span).get(0)) )); performAsync(post("/api/v2/spans").content(message)) diff --git a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumer.java b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumer.java index 199ac9731bf..2a6fbc8d674 100644 --- a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumer.java +++ b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumer.java @@ -24,7 +24,7 @@ import okio.ByteString; import zipkin.Annotation; import zipkin.internal.Nullable; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Encoder; import zipkin.internal.v2.storage.AsyncSpanConsumer; import zipkin.storage.Callback; @@ -43,7 +43,7 @@ class ElasticsearchHttpSpanConsumer implements AsyncSpanConsumer { // not final this.indexNameFormatter = es.indexNameFormatter(); } - @Override public void accept(List spans, Callback callback) { + @Override public void accept(List spans, Callback callback) { if (spans.isEmpty()) { callback.onSuccess(null); return; @@ -58,8 +58,8 @@ class ElasticsearchHttpSpanConsumer implements AsyncSpanConsumer { // not final } } - void indexSpans(BulkSpanIndexer indexer, List spans) throws IOException { - for (Span2 span : spans) { + void indexSpans(BulkSpanIndexer indexer, List spans) throws IOException { + for (Span span : spans) { Long spanTimestamp = span.timestamp(); long indexTimestamp = 0L; // which index to store this span into if (spanTimestamp != null) { @@ -86,7 +86,7 @@ static class BulkSpanIndexer { this.indexNameFormatter = es.indexNameFormatter(); } - void add(long indexTimestamp, Span2 span, @Nullable Long timestampMillis) { + void add(long indexTimestamp, Span span, @Nullable Long timestampMillis) { String index = indexNameFormatter.formatTypeAndTimestamp(SPAN, indexTimestamp); byte[] document = prefixWithTimestampMillisAndQuery(span, timestampMillis); indexer.add(index, SPAN, document, null /* Allow ES to choose an ID */); @@ -111,7 +111,7 @@ void execute(Callback callback) throws IOException { * *

Ex {@code curl -s localhost:9200/zipkin:span-2017-08-11/_search?q=_q:error=500} */ - static byte[] prefixWithTimestampMillisAndQuery(Span2 span, @Nullable Long timestampMillis) { + static byte[] prefixWithTimestampMillisAndQuery(Span span, @Nullable Long timestampMillis) { Buffer query = new Buffer(); JsonWriter writer = JsonWriter.of(query); try { diff --git a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorage.java b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorage.java index ebd0e9d949d..a51bdce340d 100644 --- a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorage.java +++ b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorage.java @@ -27,14 +27,11 @@ import okhttp3.Request; import okhttp3.RequestBody; import okio.Buffer; -import zipkin.internal.AsyncSpan2ConsumerAdapter; import zipkin.internal.Nullable; -import zipkin.internal.Span2Component; -import zipkin.storage.AsyncSpanConsumer; +import zipkin.internal.V2StorageComponent; import zipkin.storage.AsyncSpanStore; import zipkin.storage.SpanStore; import zipkin.storage.StorageAdapters; -import zipkin.storage.StorageComponent; import zipkin.storage.elasticsearch.http.internal.LenientDoubleCallbackAsyncSpanStore; import zipkin.storage.elasticsearch.http.internal.client.HttpCall; @@ -44,7 +41,8 @@ import static zipkin.storage.elasticsearch.http.ElasticsearchHttpSpanStore.SPAN; @AutoValue -public abstract class ElasticsearchHttpStorage extends Span2Component implements StorageComponent { +public abstract class ElasticsearchHttpStorage extends V2StorageComponent + implements zipkin.storage.StorageComponent { /** * A list of elasticsearch nodes to connect to, in http://host:port or https://host:port * format. Note this value is only read once. @@ -78,7 +76,7 @@ public static Builder builder() { } @AutoValue.Builder - public static abstract class Builder implements StorageComponent.Builder { + public static abstract class Builder implements zipkin.storage.StorageComponent.Builder { abstract Builder client(OkHttpClient client); abstract Builder shutdownClientOnClose(boolean shutdownClientOnClose); @@ -222,11 +220,7 @@ public final Builder dateSeparator(char dateSeparator) { } } - @Override public AsyncSpanConsumer asyncSpanConsumer() { - return AsyncSpan2ConsumerAdapter.create(asyncSpan2Consumer()); - } - - @Override protected zipkin.internal.v2.storage.AsyncSpanConsumer asyncSpan2Consumer() { + @Override protected zipkin.internal.v2.storage.AsyncSpanConsumer v2AsyncSpanConsumer() { ensureIndexTemplates(); return new ElasticsearchHttpSpanConsumer(this); } diff --git a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/JsonAdapters.java b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/JsonAdapters.java index 1f8283ab783..60c34b1e885 100644 --- a/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/JsonAdapters.java +++ b/zipkin-storage/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/JsonAdapters.java @@ -20,19 +20,18 @@ import zipkin.Annotation; import zipkin.DependencyLink; import zipkin.Endpoint; -import zipkin.Span; -import zipkin.internal.Span2; -import zipkin.internal.Span2Converter; +import zipkin.internal.v2.Span; +import zipkin.internal.V2SpanConverter; /** * Read-only json adapters resurrected from before we switched to Java 6 as storage components can * be Java 7+ */ final class JsonAdapters { - static final JsonAdapter SPAN_ADAPTER = new JsonAdapter() { + static final JsonAdapter SPAN_ADAPTER = new JsonAdapter() { @Override - public Span fromJson(JsonReader reader) throws IOException { - Span2.Builder result = Span2.builder(); + public zipkin.Span fromJson(JsonReader reader) throws IOException { + Span.Builder result = Span.builder(); reader.beginObject(); while (reader.hasNext()) { String nextName = reader.nextName(); @@ -51,7 +50,7 @@ public Span fromJson(JsonReader reader) throws IOException { result.id(reader.nextString()); break; case "kind": - result.kind(Span2.Kind.valueOf(reader.nextString())); + result.kind(Span.Kind.valueOf(reader.nextString())); break; case "name": result.name(reader.nextString()); @@ -94,11 +93,11 @@ public Span fromJson(JsonReader reader) throws IOException { } } reader.endObject(); - return Span2Converter.toSpan(result.build()); + return V2SpanConverter.toSpan(result.build()); } @Override - public void toJson(JsonWriter writer, Span value) throws IOException { + public void toJson(JsonWriter writer, zipkin.Span value) throws IOException { throw new UnsupportedOperationException(); } }; diff --git a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumerTest.java b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumerTest.java index b93225af280..661dab0cd42 100644 --- a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumerTest.java +++ b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpSpanConsumerTest.java @@ -24,8 +24,8 @@ import org.junit.Test; import zipkin.TestObjects; import zipkin.internal.CallbackCaptor; -import zipkin.internal.Span2; -import zipkin.internal.Span2.Kind; +import zipkin.internal.v2.Span; +import zipkin.internal.v2.Span.Kind; import zipkin.internal.v2.codec.Decoder; import zipkin.internal.v2.codec.Encoder; import zipkin.internal.v2.codec.MessageEncoder; @@ -63,7 +63,7 @@ public void close() throws IOException { @Test public void addsTimestamp_millisIntoJson() throws Exception { es.enqueue(new MockResponse()); - Span2 span = Span2.builder().traceId(20L).id(20L).name("get") + Span span = Span.builder().traceId(20L).id(20L).name("get") .timestamp(TODAY * 1000).build(); accept(span); @@ -73,7 +73,7 @@ public void close() throws IOException { } @Test public void prefixWithTimestampMillisAndQuery_skipsWhenNoData() throws Exception { - Span2 span = Span2.builder().traceId(20L).id(22L).name("").parentId(21L).timestamp(0L) + Span span = Span.builder().traceId(20L).id(22L).name("").parentId(21L).timestamp(0L) .localEndpoint(TestObjects.WEB_ENDPOINT) .kind(Kind.CLIENT) .build(); @@ -85,7 +85,7 @@ public void close() throws IOException { } @Test public void prefixWithTimestampMillisAndQuery_addsTimestampMillis() throws Exception { - Span2 span = Span2.builder().traceId(20L).id(22L).name("").parentId(21L).timestamp(1L) + Span span = Span.builder().traceId(20L).id(22L).name("").parentId(21L).timestamp(1L) .localEndpoint(TestObjects.WEB_ENDPOINT) .kind(Kind.CLIENT) .build(); @@ -97,7 +97,7 @@ public void close() throws IOException { } @Test public void prefixWithTimestampMillisAndQuery_addsAnnotationQuery() throws Exception { - Span2 span = Span2.builder().traceId(20L).id(22L).name("").parentId(21L) + Span span = Span.builder().traceId(20L).id(22L).name("").parentId(21L) .localEndpoint(TestObjects.WEB_ENDPOINT) .addAnnotation(1L, "\"foo") .build(); @@ -109,7 +109,7 @@ public void close() throws IOException { } @Test public void prefixWithTimestampMillisAndQuery_addsAnnotationQueryTags() throws Exception { - Span2 span = Span2.builder().traceId(20L).id(22L).name("").parentId(21L) + Span span = Span.builder().traceId(20L).id(22L).name("").parentId(21L) .localEndpoint(TestObjects.WEB_ENDPOINT) .putTag("\"foo", "\"bar") .build(); @@ -121,7 +121,7 @@ public void close() throws IOException { } @Test public void prefixWithTimestampMillisAndQuery_readable() throws Exception { - Span2 span = Span2.builder().traceId(20L).id(20L).name("get") + Span span = Span.builder().traceId(20L).id(20L).name("get") .timestamp(TODAY * 1000).build(); byte[] message = MessageEncoder.JSON_BYTES.encode(asList( @@ -135,7 +135,7 @@ public void close() throws IOException { @Test public void doesntWriteDocumentId() throws Exception { es.enqueue(new MockResponse()); - accept(Span2.builder().traceId(1L).id(1L).name("foo").build()); + accept(Span.builder().traceId(1L).id(1L).name("foo").build()); RecordedRequest request = es.takeRequest(); assertThat(request.getBody().readByteString().utf8()) @@ -145,8 +145,8 @@ public void close() throws IOException { @Test public void writesSpanNaturallyWhenNoTimestamp() throws Exception { es.enqueue(new MockResponse()); - Span2 span = Span2.builder().traceId(1L).id(1L).name("foo").build(); - accept(Span2.builder().traceId(1L).id(1L).name("foo").build()); + Span span = Span.builder().traceId(1L).id(1L).name("foo").build(); + accept(Span.builder().traceId(1L).id(1L).name("foo").build()); assertThat(es.takeRequest().getBody().readByteString().utf8()) .contains("\n" + new String(Encoder.JSON.encode(span), UTF_8) + "\n"); @@ -155,13 +155,13 @@ public void close() throws IOException { @Test public void traceIsSearchableByServerServiceName() throws Exception { es.enqueue(new MockResponse()); - Span2 clientSpan = Span2.builder().traceId(20L).id(22L).name("").parentId(21L) + Span clientSpan = Span.builder().traceId(20L).id(22L).name("").parentId(21L) .timestamp(1000L) .kind(Kind.CLIENT) .localEndpoint(TestObjects.WEB_ENDPOINT) .build(); - Span2 serverSpan = Span2.builder().traceId(20L).id(22L).name("get").parentId(21L) + Span serverSpan = Span.builder().traceId(20L).id(22L).name("get").parentId(21L) .timestamp(2000L) .kind(Kind.SERVER) .localEndpoint(TestObjects.APP_ENDPOINT) @@ -186,7 +186,7 @@ public void close() throws IOException { es.enqueue(new MockResponse()); - accept(Span2.builder().traceId(1L).id(1L).name("foo").build()); + accept(Span.builder().traceId(1L).id(1L).name("foo").build()); RecordedRequest request = es.takeRequest(); assertThat(request.getPath()) @@ -196,7 +196,7 @@ public void close() throws IOException { @Test public void choosesTypeSpecificIndex() throws Exception { es.enqueue(new MockResponse()); - Span2 span = Span2.builder().traceId(1L).id(2L).parentId(1L).name("s") + Span span = Span.builder().traceId(1L).id(2L).parentId(1L).name("s") .localEndpoint(TestObjects.APP_ENDPOINT) .addAnnotation(TimeUnit.DAYS.toMicros(365) /* 1971-01-01 */, "foo") .build(); @@ -212,9 +212,9 @@ public void close() throws IOException { ); } - void accept(Span2... spans) throws Exception { + void accept(Span... spans) throws Exception { CallbackCaptor callback = new CallbackCaptor<>(); - storage.asyncSpan2Consumer().accept(asList(spans), callback); + storage.v2AsyncSpanConsumer().accept(asList(spans), callback); callback.get(); } } diff --git a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorageTest.java b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorageTest.java index f28d8609477..f262960fe67 100644 --- a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorageTest.java +++ b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorageTest.java @@ -79,9 +79,6 @@ public class ElasticsearchHttpStorageTest { es.enqueue(new MockResponse()); // get span template es.enqueue(new MockResponse()); // get dependency template - // check this isn't the legacy consumer - assertThat(storage.asyncSpan2Consumer()) - .isInstanceOf(ElasticsearchHttpSpanConsumer.class); // check this isn't the double reading span store assertThat(storage.asyncSpanStore()) .isInstanceOf(ElasticsearchHttpSpanStore.class); diff --git a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/JsonAdaptersTest.java b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/JsonAdaptersTest.java index 4504716a7f8..dfc58aa63c6 100644 --- a/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/JsonAdaptersTest.java +++ b/zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/JsonAdaptersTest.java @@ -21,12 +21,11 @@ import zipkin.Codec; import zipkin.DependencyLink; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TestObjects; import zipkin.internal.ApplyTimestampAndDuration; -import zipkin.internal.Span2; -import zipkin.internal.Span2Converter; import zipkin.internal.Util; +import zipkin.internal.V2SpanConverter; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Encoder; import static org.assertj.core.api.Assertions.assertThat; @@ -111,7 +110,7 @@ public void span_tag_long_read() throws IOException { + " }" + "}"; - List spans = Span2Converter.fromSpan(JsonAdapters.SPAN_ADAPTER.fromJson(json)); + List spans = V2SpanConverter.fromSpan(JsonAdapters.SPAN_ADAPTER.fromJson(json)); assertThat(spans.get(0).tags()) .containsExactly(entry("num", "9223372036854775807")); } @@ -127,15 +126,15 @@ public void span_tag_double_read() throws IOException { + " }" + "}"; - List spans = Span2Converter.fromSpan(JsonAdapters.SPAN_ADAPTER.fromJson(json)); + List spans = V2SpanConverter.fromSpan(JsonAdapters.SPAN_ADAPTER.fromJson(json)); assertThat(spans.get(0).tags()) .containsExactly(entry("num", "1.23456789")); } @Test public void span_roundTrip() throws IOException { - Span span = ApplyTimestampAndDuration.apply(TestObjects.LOTS_OF_SPANS[0]); - Span2 span2 = Span2Converter.fromSpan(span).get(0); + zipkin.Span span = ApplyTimestampAndDuration.apply(TestObjects.LOTS_OF_SPANS[0]); + Span span2 = V2SpanConverter.fromSpan(span).get(0); Buffer bytes = new Buffer(); bytes.write(Encoder.JSON.encode(span2)); assertThat(SPAN_ADAPTER.fromJson(bytes)) @@ -150,7 +149,7 @@ public void span_roundTrip() throws IOException { public void span_specialCharsInJson() throws IOException { // service name is surrounded by control characters Endpoint e = Endpoint.create(new String(new char[] {0, 'a', 1}), 0); - Span2 worstSpanInTheWorld = Span2.builder().traceId(1L).id(1L) + Span worstSpanInTheWorld = Span.builder().traceId(1L).id(1L) // name is terrible .name(new String(new char[] {'"', '\\', '\t', '\b', '\n', '\r', '\f'})) .localEndpoint(e) @@ -164,7 +163,7 @@ public void span_specialCharsInJson() throws IOException { Buffer bytes = new Buffer(); bytes.write(Encoder.JSON.encode(worstSpanInTheWorld)); assertThat(SPAN_ADAPTER.fromJson(bytes)) - .isEqualTo(Span2Converter.toSpan(worstSpanInTheWorld)); + .isEqualTo(V2SpanConverter.toSpan(worstSpanInTheWorld)); } @Test diff --git a/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkSpan2Iterator.java b/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkV2SpanIterator.java similarity index 88% rename from zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkSpan2Iterator.java rename to zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkV2SpanIterator.java index 054de8ff4bd..019e99b1bcf 100644 --- a/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkSpan2Iterator.java +++ b/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/DependencyLinkV2SpanIterator.java @@ -21,7 +21,7 @@ import zipkin.Endpoint; import zipkin.internal.Nullable; import zipkin.internal.PeekingIterator; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.storage.mysql.internal.generated.tables.ZipkinSpans; import static zipkin.Constants.CLIENT_ADDR; @@ -33,18 +33,18 @@ import static zipkin.storage.mysql.internal.generated.tables.ZipkinAnnotations.ZIPKIN_ANNOTATIONS; /** - * Lazy converts rows into {@linkplain Span2} objects suitable for dependency links. This takes + * Lazy converts rows into {@linkplain Span} objects suitable for dependency links. This takes * short-cuts to require less data. For example, it folds shared RPC spans into one, and doesn't * include tags, non-core annotations or time units. * *

Out-of-date schemas may be missing the trace_id_high field. When present, this becomes {@link - * Span2#traceIdHigh()} used as the left-most 16 characters of the traceId in logging + * Span#traceIdHigh()} used as the left-most 16 characters of the traceId in logging * statements. */ -final class DependencyLinkSpan2Iterator implements Iterator { +final class DependencyLinkV2SpanIterator implements Iterator { /** Assumes the input records are sorted by trace id, span id */ - static final class ByTraceId implements Iterator> { + static final class ByTraceId implements Iterator> { final PeekingIterator delegate; final boolean hasTraceIdHigh; @@ -60,10 +60,10 @@ static final class ByTraceId implements Iterator> { return delegate.hasNext(); } - @Override public Iterator next() { + @Override public Iterator next() { currentTraceIdHi = hasTraceIdHigh ? traceIdHigh(delegate) : null; currentTraceIdLo = delegate.peek().getValue(ZipkinSpans.ZIPKIN_SPANS.TRACE_ID); - return new DependencyLinkSpan2Iterator(delegate, currentTraceIdHi, currentTraceIdLo); + return new DependencyLinkV2SpanIterator(delegate, currentTraceIdHi, currentTraceIdLo); } @Override public void remove() { @@ -75,7 +75,7 @@ static final class ByTraceId implements Iterator> { @Nullable final Long traceIdHi; final long traceIdLo; - DependencyLinkSpan2Iterator(PeekingIterator delegate, Long traceIdHi, long traceIdLo) { + DependencyLinkV2SpanIterator(PeekingIterator delegate, Long traceIdHi, long traceIdLo) { this.delegate = delegate; this.traceIdHi = traceIdHi; this.traceIdLo = traceIdLo; @@ -90,7 +90,7 @@ public boolean hasNext() { } @Override - public Span2 next() { + public Span next() { Record row = delegate.peek(); long spanId = row.getValue(ZipkinSpans.ZIPKIN_SPANS.ID); @@ -131,7 +131,7 @@ public Span2 next() { // Skip the client side, so it isn't mistaken for a loopback request if (equal(saService, caService)) caService = null; - Span2.Builder result = Span2.builder() + Span.Builder result = Span.builder() .traceIdHigh(traceIdHi != null ? traceIdHi : 0L) .traceId(traceIdLo) .parentId(row.getValue(ZipkinSpans.ZIPKIN_SPANS.PARENT_ID)) @@ -142,18 +142,18 @@ public Span2 next() { } if (srService != null) { - return result.kind(Span2.Kind.SERVER) + return result.kind(Span.Kind.SERVER) .localEndpoint(ep(srService)) .remoteEndpoint(ep(caService)) .build(); } else if (saService != null) { return result - .kind(csService != null ? Span2.Kind.CLIENT : null) + .kind(csService != null ? Span.Kind.CLIENT : null) .localEndpoint(ep(caService)) .remoteEndpoint(ep(saService)) .build(); } else if (csService != null) { - return result.kind(Span2.Kind.SERVER) + return result.kind(Span.Kind.SERVER) .localEndpoint(ep(caService)) .build(); } diff --git a/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/MySQLSpanStore.java b/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/MySQLSpanStore.java index 7aa6746d60a..eb5bb570034 100644 --- a/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/MySQLSpanStore.java +++ b/zipkin-storage/mysql/src/main/java/zipkin/storage/mysql/MySQLSpanStore.java @@ -39,12 +39,11 @@ import zipkin.BinaryAnnotation.Type; import zipkin.DependencyLink; import zipkin.Endpoint; -import zipkin.Span; import zipkin.internal.DependencyLinker; import zipkin.internal.GroupByTraceId; import zipkin.internal.Nullable; import zipkin.internal.Pair; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.storage.QueryRequest; import zipkin.storage.SpanStore; import zipkin.storage.mysql.internal.generated.tables.ZipkinAnnotations; @@ -142,10 +141,10 @@ static TableOnConditionStep maybeOnService(TableOnConditionStep table return table.and(aTable.ENDPOINT_SERVICE_NAME.eq(serviceName)); } - List> getTraces(@Nullable QueryRequest request, @Nullable Long traceIdHigh, + List> getTraces(@Nullable QueryRequest request, @Nullable Long traceIdHigh, @Nullable Long traceIdLow, boolean raw) { if (traceIdHigh != null && !strictTraceId) traceIdHigh = null; - final Map, List> spansWithoutAnnotations; + final Map, List> spansWithoutAnnotations; final Map, List> dbAnnotations; try (Connection conn = datasource.getConnection()) { Condition traceIdCondition = request != null @@ -156,7 +155,7 @@ List> getTraces(@Nullable QueryRequest request, @Nullable Long traceI .select(schema.spanFields) .from(ZIPKIN_SPANS).where(traceIdCondition) .stream() - .map(r -> Span.builder() + .map(r -> zipkin.Span.builder() .traceIdHigh(maybeGet(r, ZIPKIN_SPANS.TRACE_ID_HIGH, 0L)) .traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)) .name(r.getValue(ZIPKIN_SPANS.NAME)) @@ -167,8 +166,8 @@ List> getTraces(@Nullable QueryRequest request, @Nullable Long traceI .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) .build()) .collect( - groupingBy((Span s) -> Pair.create(s.traceIdHigh, s.traceId), - LinkedHashMap::new, Collectors.toList())); + groupingBy((zipkin.Span s) -> Pair.create(s.traceIdHigh, s.traceId), + LinkedHashMap::new, Collectors.toList())); dbAnnotations = context.get(conn) .select(schema.annotationFields) @@ -186,10 +185,10 @@ List> getTraces(@Nullable QueryRequest request, @Nullable Long traceI throw new RuntimeException("Error querying for " + request + ": " + e.getMessage()); } - List allSpans = new ArrayList<>(spansWithoutAnnotations.size()); - for (List spans : spansWithoutAnnotations.values()) { - for (Span s : spans) { - Span.Builder span = s.toBuilder(); + List allSpans = new ArrayList<>(spansWithoutAnnotations.size()); + for (List spans : spansWithoutAnnotations.values()) { + for (zipkin.Span s : spans) { + zipkin.Span.Builder span = s.toBuilder(); Row3 key = row(s.traceIdHigh, s.traceId, s.id); if (dbAnnotations.containsKey(key)) { @@ -225,27 +224,27 @@ static T maybeGet(Record record, TableField field, T defaultValue } @Override - public List> getTraces(QueryRequest request) { + public List> getTraces(QueryRequest request) { return getTraces(request, null, null, false); } @Override - public List getTrace(long traceId) { + public List getTrace(long traceId) { return getTrace(0L, traceId); } - @Override public List getTrace(long traceIdHigh, long traceIdLow) { - List> result = getTraces(null, traceIdHigh, traceIdLow, false); + @Override public List getTrace(long traceIdHigh, long traceIdLow) { + List> result = getTraces(null, traceIdHigh, traceIdLow, false); return result.isEmpty() ? null : result.get(0); } @Override - public List getRawTrace(long traceId) { + public List getRawTrace(long traceId) { return getRawTrace(0L, traceId); } - @Override public List getRawTrace(long traceIdHigh, long traceIdLow) { - List> result = getTraces(null, traceIdHigh, traceIdLow, true); + @Override public List getRawTrace(long traceIdHigh, long traceIdLow) { + List> result = getTraces(null, traceIdHigh, traceIdLow, true); return result.isEmpty() ? null : result.get(0); } @@ -328,8 +327,8 @@ List aggregateDependencies(long endTs, @Nullable Long lookback, // Grouping so that later code knows when a span or trace is finished. .groupBy(schema.dependencyLinkerGroupByFields).fetchLazy(); - Iterator> traces = - new DependencyLinkSpan2Iterator.ByTraceId(cursor.iterator(), schema.hasTraceIdHigh); + Iterator> traces = + new DependencyLinkV2SpanIterator.ByTraceId(cursor.iterator(), schema.hasTraceIdHigh); if (!traces.hasNext()) return Collections.emptyList(); diff --git a/zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkSpan2IteratorTest.java b/zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkV2SpanIteratorTest.java similarity index 81% rename from zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkSpan2IteratorTest.java rename to zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkV2SpanIteratorTest.java index 97bcc6e33c7..55e7be4159d 100644 --- a/zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkSpan2IteratorTest.java +++ b/zipkin-storage/mysql/src/test/java/zipkin/storage/mysql/DependencyLinkV2SpanIteratorTest.java @@ -21,7 +21,7 @@ import zipkin.BinaryAnnotation.Type; import zipkin.Constants; import zipkin.internal.PeekingIterator; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +29,7 @@ import static zipkin.storage.mysql.internal.generated.tables.ZipkinAnnotations.ZIPKIN_ANNOTATIONS; import static zipkin.storage.mysql.internal.generated.tables.ZipkinSpans.ZIPKIN_SPANS; -public class DependencyLinkSpan2IteratorTest { +public class DependencyLinkV2SpanIteratorTest { Long traceIdHigh = null; long traceId = 1L; Long parentId = null; @@ -37,22 +37,22 @@ public class DependencyLinkSpan2IteratorTest { /** You cannot make a dependency link unless you know the the local or peer endpoint. */ @Test public void whenNoServiceLabelsExist_kindIsUnknown() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, null) ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.kind()).isNull(); assertThat(span.localEndpoint()).isNull(); assertThat(span.remoteEndpoint()).isNull(); } @Test public void whenOnlyAddressLabelsExist_kindIsNull() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service1"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sa", Type.BOOL.value, "service2") ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.kind()).isNull(); assertThat(span.localEndpoint().serviceName).isEqualTo("service1"); @@ -61,10 +61,10 @@ public class DependencyLinkSpan2IteratorTest { /** The linker is biased towards server spans, or client spans that know the peer localEndpoint(). */ @Test public void whenServerLabelsAreMissing_kindIsUnknownAndLabelsAreCleared() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service1") ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.kind()).isNull(); assertThat(span.localEndpoint()).isNull(); @@ -73,31 +73,31 @@ public class DependencyLinkSpan2IteratorTest { /** {@link Constants#SERVER_RECV} is only applied when the local span is acting as a server */ @Test public void whenSrServiceExists_kindIsServer() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service") ); - Span2 span = iterator.next(); + Span span = iterator.next(); - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service"); assertThat(span.remoteEndpoint()).isNull(); } @Test public void errorAnnotationIgnored() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "error", -1, "service") ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.tags()).isEmpty(); assertThat(span.annotations()).isEmpty(); } @Test public void errorTagAdded() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "error", Type.STRING.value, "foo") ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.tags()).containsOnly( entry("error", "") @@ -109,13 +109,13 @@ public class DependencyLinkSpan2IteratorTest { * span */ @Test public void whenSrAndCaServiceExists_caIsThePeer() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service1"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service2") ); - Span2 span = iterator.next(); + Span span = iterator.next(); - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service2"); assertThat(span.remoteEndpoint().serviceName).isEqualTo("service1"); } @@ -125,56 +125,56 @@ public class DependencyLinkSpan2IteratorTest { * span */ @Test public void whenSrAndCsServiceExists_caIsThePeer() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, "service1"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service2") ); - Span2 span = iterator.next(); + Span span = iterator.next(); - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service2"); assertThat(span.remoteEndpoint().serviceName).isEqualTo("service1"); } /** {@link Constants#CLIENT_ADDR} is more authoritative than {@link Constants#CLIENT_SEND} */ @Test public void whenCrAndCaServiceExists_caIsThePeer() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, "foo"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service1"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service2") ); - Span2 span = iterator.next(); + Span span = iterator.next(); - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service2"); assertThat(span.remoteEndpoint().serviceName).isEqualTo("service1"); } /** Finagle labels two sides of the same socket "ca", Type.BOOL.value, "sa" with the local endpoint name */ @Test public void specialCasesFinagleLocalSocketLabeling_client() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, "service"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sa", Type.BOOL.value, "service") ); - Span2 span = iterator.next(); + Span span = iterator.next(); // When there's no "sr" annotation, we assume it is a client. - assertThat(span.kind()).isEqualTo(Span2.Kind.CLIENT); + assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT); assertThat(span.localEndpoint()).isNull(); assertThat(span.remoteEndpoint().serviceName).isEqualTo("service"); } @Test public void specialCasesFinagleLocalSocketLabeling_server() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, "service"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sa", Type.BOOL.value, "service"), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service") ); - Span2 span = iterator.next(); + Span span = iterator.next(); // When there is an "sr" annotation, we know it is a server - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service"); assertThat(span.remoteEndpoint()).isNull(); } @@ -184,33 +184,33 @@ public class DependencyLinkSpan2IteratorTest { * caller, than a client span lacking its receiver. */ @Test public void csWithoutSaIsServer() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, "service1") ); - Span2 span = iterator.next(); + Span span = iterator.next(); - assertThat(span.kind()).isEqualTo(Span2.Kind.SERVER); + assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.localEndpoint().serviceName).isEqualTo("service1"); assertThat(span.remoteEndpoint()).isNull(); } /** Service links to empty string are confusing and offer no value. */ @Test public void emptyToNull() { - DependencyLinkSpan2Iterator iterator = iterator( + DependencyLinkV2SpanIterator iterator = iterator( newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", Type.BOOL.value, ""), newRecord().values(traceIdHigh, traceId, parentId, spanId, "cs", -1, ""), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sa", Type.BOOL.value, ""), newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "") ); - Span2 span = iterator.next(); + Span span = iterator.next(); assertThat(span.kind()).isNull(); assertThat(span.localEndpoint()).isNull(); assertThat(span.remoteEndpoint()).isNull(); } - static DependencyLinkSpan2Iterator iterator(Record... records) { - return new DependencyLinkSpan2Iterator( + static DependencyLinkV2SpanIterator iterator(Record... records) { + return new DependencyLinkV2SpanIterator( new PeekingIterator<>(asList(records).iterator()), records[0].get(ZIPKIN_SPANS.TRACE_ID_HIGH), records[0].get(ZIPKIN_SPANS.TRACE_ID) ); diff --git a/zipkin/bnd.bnd b/zipkin/bnd.bnd index 999daeabc07..5e29d66f8ff 100644 --- a/zipkin/bnd.bnd +++ b/zipkin/bnd.bnd @@ -5,4 +5,7 @@ Export-Package: \ zipkin,\ zipkin.collector,\ zipkin.internal,\ - zipkin.storage \ No newline at end of file + zipkin.internal.v2.storage,\ + zipkin.internal.v2.codec,\ + zipkin.internal.v2,\ + zipkin.storage diff --git a/zipkin/src/main/java/zipkin/collector/Collector.java b/zipkin/src/main/java/zipkin/collector/Collector.java index ef2e691f5d7..4f381f32fe3 100644 --- a/zipkin/src/main/java/zipkin/collector/Collector.java +++ b/zipkin/src/main/java/zipkin/collector/Collector.java @@ -16,14 +16,13 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; -import zipkin.Span; import zipkin.SpanDecoder; -import zipkin.internal.Collector2; import zipkin.internal.DetectingSpanDecoder; -import zipkin.internal.Span2; -import zipkin.internal.Span2Component; -import zipkin.internal.Span2Converter; -import zipkin.internal.Span2JsonSpanDecoder; +import zipkin.internal.V2Collector; +import zipkin.internal.V2JsonSpanDecoder; +import zipkin.internal.V2SpanConverter; +import zipkin.internal.V2StorageComponent; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Decoder; import zipkin.storage.Callback; import zipkin.storage.StorageComponent; @@ -39,7 +38,7 @@ * before storage is attempted. This ensures that calling threads are disconnected from storage * threads. */ -public class Collector extends zipkin.internal.Collector { // not final for mock +public class Collector extends zipkin.internal.Collector { // not final for mock /** Needed to scope this to the correct logging category */ public static Builder builder(Class loggingClass) { @@ -81,18 +80,18 @@ public Collector build() { final CollectorSampler sampler; final StorageComponent storage; - final Collector2 storage2; + final V2Collector storage2; Collector(Builder builder) { super(builder.logger, builder.metrics); this.storage = checkNotNull(builder.storage, "storage"); this.sampler = builder.sampler == null ? CollectorSampler.ALWAYS_SAMPLE : builder.sampler; - if (storage instanceof Span2Component) { - storage2 = new Collector2( + if (storage instanceof V2StorageComponent) { + storage2 = new V2Collector( builder.logger, builder.metrics, builder.sampler, - (Span2Component) storage + (V2StorageComponent) storage ); } else { storage2 = null; @@ -108,7 +107,7 @@ public void acceptSpans(byte[] serializedSpans, SpanDecoder decoder, Callback serializedSpans, SpanDecoder decoder, Callback callback) { - List spans = new ArrayList<>(serializedSpans.size()); + List spans = new ArrayList<>(serializedSpans.size()); try { int bytesRead = 0; for (byte[] serializedSpan : serializedSpans) { @@ -135,12 +134,12 @@ public void acceptSpans(byte[] serializedSpans, SpanDecoder decoder, Callback spans, Callback callback) { + @Override public void accept(List spans, Callback callback) { if (storage2 != null) { int length = spans.size(); - List span2s = new ArrayList<>(length); + List span2s = new ArrayList<>(length); for (int i = 0; i < length; i++) { - span2s.addAll(Span2Converter.fromSpan(spans.get(i))); + span2s.addAll(V2SpanConverter.fromSpan(spans.get(i))); } storage2.accept(span2s, callback); } else { @@ -148,19 +147,19 @@ public void acceptSpans(byte[] serializedSpans, SpanDecoder decoder, Callback decodeList(SpanDecoder decoder, byte[] serialized) { + @Override protected List decodeList(SpanDecoder decoder, byte[] serialized) { return decoder.readSpans(serialized); } - @Override protected boolean isSampled(Span span) { + @Override protected boolean isSampled(zipkin.Span span) { return sampler.isSampled(span.traceId, span.debug); } - @Override protected void record(List sampled, Callback callback) { + @Override protected void record(List sampled, Callback callback) { storage.asyncSpanConsumer().accept(sampled, callback); } - @Override protected String idString(Span span) { + @Override protected String idString(zipkin.Span span) { return span.idString(); } } diff --git a/zipkin/src/main/java/zipkin/internal/AsyncSpan2ConsumerAdapter.java b/zipkin/src/main/java/zipkin/internal/AsyncSpan2ConsumerAdapter.java deleted file mode 100644 index 322e21fa476..00000000000 --- a/zipkin/src/main/java/zipkin/internal/AsyncSpan2ConsumerAdapter.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2015-2017 The OpenZipkin Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package zipkin.internal; - -import java.util.ArrayList; -import java.util.List; -import zipkin.Span; -import zipkin.storage.AsyncSpanConsumer; -import zipkin.storage.Callback; - -public final class AsyncSpan2ConsumerAdapter implements AsyncSpanConsumer { - - public static AsyncSpanConsumer create(zipkin.internal.v2.storage.AsyncSpanConsumer delegate) { - return new AsyncSpan2ConsumerAdapter(delegate); - } - - final zipkin.internal.v2.storage.AsyncSpanConsumer delegate; - - AsyncSpan2ConsumerAdapter(zipkin.internal.v2.storage.AsyncSpanConsumer delegate) { - this.delegate = delegate; - } - - @Override public void accept(List spans, Callback callback) { - int length = spans.size(); - List linkSpans = new ArrayList<>(length); - for (int i = 0; i < length; i++) { - linkSpans.addAll(Span2Converter.fromSpan(spans.get(i))); - } - delegate.accept(linkSpans, callback); - } -} diff --git a/zipkin/src/main/java/zipkin/internal/DependencyLinker.java b/zipkin/src/main/java/zipkin/internal/DependencyLinker.java index ce8cdea270e..bcfdf046741 100644 --- a/zipkin/src/main/java/zipkin/internal/DependencyLinker.java +++ b/zipkin/src/main/java/zipkin/internal/DependencyLinker.java @@ -22,8 +22,8 @@ import java.util.Map; import java.util.logging.Logger; import zipkin.DependencyLink; -import zipkin.Span; -import zipkin.internal.Span2.Kind; +import zipkin.internal.v2.Span; +import zipkin.internal.v2.Span.Kind; import static java.util.logging.Level.FINE; import static zipkin.Constants.ERROR; @@ -33,9 +33,9 @@ * *

This implementation traverses the tree, and only creates links between {@link Kind#SERVER * server} spans. One exception is at the bottom of the trace tree. {@link Kind#CLIENT client} spans - * that record their {@link Span2#remoteEndpoint()} are included, as this accounts for - * uninstrumented services. Spans with {@link Span2#kind()} unset, but {@link - * Span2#remoteEndpoint()} set are treated the same as client spans. + * that record their {@link Span#remoteEndpoint()} are included, as this accounts for uninstrumented + * services. Spans with {@link Span#kind()} unset, but {@link Span#remoteEndpoint()} set are treated + * the same as client spans. */ public final class DependencyLinker { private final Logger logger; @@ -53,20 +53,20 @@ public DependencyLinker() { /** * @param spans spans where all spans have the same trace id */ - public DependencyLinker putTrace(Collection spans) { + public DependencyLinker putTrace(Collection spans) { if (spans.isEmpty()) return this; - List linkSpans = new LinkedList<>(); - for (Span s : MergeById.apply(spans)) { - linkSpans.addAll(Span2Converter.fromSpan(s)); + List linkSpans = new LinkedList<>(); + for (zipkin.Span s : MergeById.apply(spans)) { + linkSpans.addAll(V2SpanConverter.fromSpan(s)); } return putTrace(linkSpans.iterator()); } - static final Node.MergeFunction MERGE_RPC = new MergeRpc(); + static final Node.MergeFunction MERGE_RPC = new MergeRpc(); - static final class MergeRpc implements Node.MergeFunction { - @Override public Span2 merge(Span2 left, Span2 right) { + static final class MergeRpc implements Node.MergeFunction { + @Override public Span merge(Span left, Span right) { if (left == null) return right; if (right == null) return left; if (left.kind() == null) { @@ -75,15 +75,15 @@ static final class MergeRpc implements Node.MergeFunction { if (right.kind() == null) { return copyError(right, left); } - Span2 server = left.kind() == Kind.SERVER ? left : right; - Span2 client = left == server ? right : left; + Span server = left.kind() == Kind.SERVER ? left : right; + Span client = left == server ? right : left; if (server.remoteEndpoint() != null && !"".equals(server.remoteEndpoint().serviceName)) { return copyError(client, server); } return copyError(client, server).toBuilder().remoteEndpoint(client.localEndpoint()).build(); } - static Span2 copyError(Span2 maybeError, Span2 result) { + static Span copyError(Span maybeError, Span result) { if (maybeError.tags().containsKey(ERROR)) { return result.toBuilder().putTag(ERROR, maybeError.tags().get(ERROR)).build(); } @@ -94,23 +94,23 @@ static Span2 copyError(Span2 maybeError, Span2 result) { /** * @param spans spans where all spans have the same trace id */ - public DependencyLinker putTrace(Iterator spans) { + public DependencyLinker putTrace(Iterator spans) { if (!spans.hasNext()) return this; - Span2 first = spans.next(); - Node.TreeBuilder builder = + Span first = spans.next(); + Node.TreeBuilder builder = new Node.TreeBuilder<>(logger, MERGE_RPC, first.traceIdString()); builder.addNode(first.parentId(), first.id(), first); while (spans.hasNext()) { - Span2 next = spans.next(); + Span next = spans.next(); builder.addNode(next.parentId(), next.id(), next); } - Node tree = builder.build(); + Node tree = builder.build(); if (logger.isLoggable(FINE)) logger.fine("traversing trace tree, breadth-first"); - for (Iterator> i = tree.traverse(); i.hasNext(); ) { - Node current = i.next(); - Span2 currentSpan = current.value(); + for (Iterator> i = tree.traverse(); i.hasNext(); ) { + Node current = i.next(); + Span currentSpan = current.value(); if (logger.isLoggable(FINE)) { logger.fine("processing " + currentSpan); } @@ -175,7 +175,7 @@ public DependencyLinker putTrace(Iterator spans) { logger.fine("cannot determine parent, looking for first server ancestor"); } - Span2 rpcAncestor = findRpcAncestor(current); + Span rpcAncestor = findRpcAncestor(current); String rpcAncestorName; if (rpcAncestor != null && (rpcAncestorName = serviceName(rpcAncestor)) != null) { // Some users accidentally put the remote service name on client annotations. @@ -186,7 +186,7 @@ public DependencyLinker putTrace(Iterator spans) { } // Local spans may be between the current node and its remote parent - if (parent == null) parent = rpcAncestorName; + if (parent == null) parent = rpcAncestorName; // When an RPC is split between spans, we skip the child (server side). If our parent is a // client, we need to check it for errors. @@ -206,14 +206,14 @@ public DependencyLinker putTrace(Iterator spans) { return this; } - Span2 findRpcAncestor(Node current) { - Node ancestor = current.parent(); + Span findRpcAncestor(Node current) { + Node ancestor = current.parent(); while (ancestor != null) { if (logger.isLoggable(FINE)) { logger.fine("processing ancestor " + ancestor.value()); } if (!ancestor.isSyntheticRootForPartialTree()) { - Span2 maybeRemote = ancestor.value(); + Span maybeRemote = ancestor.value(); if (maybeRemote.kind() != null) return maybeRemote; } ancestor = ancestor.parent(); @@ -276,13 +276,13 @@ static List link(Map, Long> callCounts, return result; } - static String serviceName(Span2 span) { + static String serviceName(Span span) { return span.localEndpoint() != null && !"".equals(span.localEndpoint().serviceName) ? span.localEndpoint().serviceName : null; } - static String remoteServiceName(Span2 span) { + static String remoteServiceName(Span span) { return span.remoteEndpoint() != null && !"".equals(span.remoteEndpoint().serviceName) ? span.remoteEndpoint().serviceName : null; diff --git a/zipkin/src/main/java/zipkin/internal/DetectingSpanDecoder.java b/zipkin/src/main/java/zipkin/internal/DetectingSpanDecoder.java index 91fccccfad0..de87e14124b 100644 --- a/zipkin/src/main/java/zipkin/internal/DetectingSpanDecoder.java +++ b/zipkin/src/main/java/zipkin/internal/DetectingSpanDecoder.java @@ -29,7 +29,7 @@ public final class DetectingSpanDecoder implements SpanDecoder { /** zipkin v2 will have this tag, and others won't. */ static final byte[] LOCAL_ENDPOINT_TAG = "\"localEndpoint\"".getBytes(Util.UTF_8); - static final SpanDecoder JSON2_DECODER = new Span2JsonSpanDecoder(); + static final SpanDecoder JSON2_DECODER = new V2JsonSpanDecoder(); @Override public Span readSpan(byte[] span) { SpanDecoder decoder = detectFormat(span); diff --git a/zipkin/src/main/java/zipkin/internal/Span2Component.java b/zipkin/src/main/java/zipkin/internal/Span2Component.java deleted file mode 100644 index 6ab12d958a6..00000000000 --- a/zipkin/src/main/java/zipkin/internal/Span2Component.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2015-2017 The OpenZipkin Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package zipkin.internal; - -import zipkin.internal.v2.storage.AsyncSpanConsumer; - -// temporary type until other classes around this complete -public abstract class Span2Component { - protected abstract AsyncSpanConsumer asyncSpan2Consumer(); -} diff --git a/zipkin/src/main/java/zipkin/internal/Collector2.java b/zipkin/src/main/java/zipkin/internal/V2Collector.java similarity index 64% rename from zipkin/src/main/java/zipkin/internal/Collector2.java rename to zipkin/src/main/java/zipkin/internal/V2Collector.java index 31244b93320..fbc59a252bc 100644 --- a/zipkin/src/main/java/zipkin/internal/Collector2.java +++ b/zipkin/src/main/java/zipkin/internal/V2Collector.java @@ -17,40 +17,41 @@ import java.util.logging.Logger; import zipkin.collector.CollectorMetrics; import zipkin.collector.CollectorSampler; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Decoder; import zipkin.storage.Callback; import static zipkin.internal.Util.checkNotNull; -public final class Collector2 extends Collector, Span2> { - final Span2Component storage; +public final class V2Collector extends Collector, Span> { + final V2StorageComponent storage; final CollectorSampler sampler; - public Collector2(Logger logger, @Nullable CollectorMetrics metrics, - @Nullable CollectorSampler sampler, Span2Component storage) { + public V2Collector(Logger logger, @Nullable CollectorMetrics metrics, + @Nullable CollectorSampler sampler, V2StorageComponent storage) { super(logger, metrics); this.storage = checkNotNull(storage, "storage"); this.sampler = sampler == null ? CollectorSampler.ALWAYS_SAMPLE : sampler; } @Override - public void acceptSpans(byte[] serializedSpans, Decoder decoder, Callback callback) { + public void acceptSpans(byte[] serializedSpans, Decoder decoder, Callback callback) { super.acceptSpans(serializedSpans, decoder, callback); } - @Override protected List decodeList(Decoder decoder, byte[] serialized) { + @Override protected List decodeList(Decoder decoder, byte[] serialized) { return decoder.decodeList(serialized); } - @Override protected boolean isSampled(Span2 span) { + @Override protected boolean isSampled(Span span) { return sampler.isSampled(span.traceId(), span.debug()); } - @Override protected void record(List sampled, Callback callback) { - storage.asyncSpan2Consumer().accept(sampled, callback); + @Override protected void record(List sampled, Callback callback) { + storage.v2AsyncSpanConsumer().accept(sampled, callback); } - @Override protected String idString(Span2 span) { + @Override protected String idString(Span span) { return span.idString(); } } diff --git a/zipkin/src/main/java/zipkin/internal/Span2JsonSpanDecoder.java b/zipkin/src/main/java/zipkin/internal/V2JsonSpanDecoder.java similarity index 74% rename from zipkin/src/main/java/zipkin/internal/Span2JsonSpanDecoder.java rename to zipkin/src/main/java/zipkin/internal/V2JsonSpanDecoder.java index 9bafc3b8381..60cc693514f 100644 --- a/zipkin/src/main/java/zipkin/internal/Span2JsonSpanDecoder.java +++ b/zipkin/src/main/java/zipkin/internal/V2JsonSpanDecoder.java @@ -16,23 +16,23 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import zipkin.Span; import zipkin.SpanDecoder; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Decoder; /** Decodes a span from zipkin v2 encoding */ -public final class Span2JsonSpanDecoder implements SpanDecoder { - @Override public Span readSpan(byte[] span) { +public final class V2JsonSpanDecoder implements SpanDecoder { + @Override public zipkin.Span readSpan(byte[] span) { throw new UnsupportedOperationException("current transports only accept list messages"); } - @Override public List readSpans(byte[] span) { - List span2s = Decoder.JSON.decodeList(span); + @Override public List readSpans(byte[] span) { + List span2s = Decoder.JSON.decodeList(span); if (span2s.isEmpty()) return Collections.emptyList(); int length = span2s.size(); - List result = new ArrayList<>(length); + List result = new ArrayList<>(length); for (int i = 0; i < length; i++) { - result.add(Span2Converter.toSpan(span2s.get(i))); + result.add(V2SpanConverter.toSpan(span2s.get(i))); } return result; } diff --git a/zipkin/src/main/java/zipkin/internal/Span2Converter.java b/zipkin/src/main/java/zipkin/internal/V2SpanConverter.java similarity index 88% rename from zipkin/src/main/java/zipkin/internal/Span2Converter.java rename to zipkin/src/main/java/zipkin/internal/V2SpanConverter.java index 7cd20886c16..56f86b29a80 100644 --- a/zipkin/src/main/java/zipkin/internal/Span2Converter.java +++ b/zipkin/src/main/java/zipkin/internal/V2SpanConverter.java @@ -22,8 +22,8 @@ import zipkin.BinaryAnnotation; import zipkin.Constants; import zipkin.Endpoint; -import zipkin.Span; -import zipkin.internal.Span2.Kind; +import zipkin.internal.v2.Span; +import zipkin.internal.v2.Span.Kind; import static zipkin.BinaryAnnotation.Type.BOOL; import static zipkin.Constants.CLIENT_ADDR; @@ -32,16 +32,16 @@ import static zipkin.internal.Util.writeBase64Url; /** - * This converts {@link zipkin.Span} instances to {@link Span2} and visa versa. + * This converts {@link zipkin.Span} instances to {@link Span} and visa versa. */ -public final class Span2Converter { +public final class V2SpanConverter { /** - * Converts the input, parsing RPC annotations into {@link Span2#kind()}. + * Converts the input, parsing RPC annotations into {@link Span#kind()}. * * @return a span for each unique {@link Annotation#endpoint annotation endpoint} service name. */ - public static List fromSpan(Span source) { + public static List fromSpan(zipkin.Span source) { Builders builders = new Builders(source); // add annotations unless they are "core" builders.processAnnotations(source); @@ -51,18 +51,18 @@ public static List fromSpan(Span source) { } static final class Builders { - final List spans = new ArrayList<>(); + final List spans = new ArrayList<>(); Annotation cs = null, sr = null, ss = null, cr = null, ms = null, mr = null, ws = null, wr = null; - Builders(Span source) { + Builders(zipkin.Span source) { this.spans.add(newBuilder(source)); } - void processAnnotations(Span source) { + void processAnnotations(zipkin.Span source) { for (int i = 0, length = source.annotations.size(); i < length; i++) { Annotation a = source.annotations.get(i); - Span2.Builder currentSpan = forEndpoint(source, a.endpoint); + Span.Builder currentSpan = forEndpoint(source, a.endpoint); // core annotations require an endpoint. Don't give special treatment when that's missing if (a.value.length() == 2 && a.endpoint != null) { if (a.value.equals(Constants.CLIENT_SEND)) { @@ -100,8 +100,8 @@ void processAnnotations(Span source) { maybeTimestampDuration(source, cs, cr); // special-case loopback: We need to make sure on loopback there are two span2s - Span2.Builder client = forEndpoint(source, cs.endpoint); - Span2.Builder server; + Span.Builder client = forEndpoint(source, cs.endpoint); + Span.Builder server; if (closeEnough(cs.endpoint, sr.endpoint)) { client.kind(Kind.CLIENT); // fork a new span for the server side @@ -119,10 +119,10 @@ void processAnnotations(Span source) { } else if (sr != null && ss != null) { maybeTimestampDuration(source, sr, ss); } else { // otherwise, the span is incomplete. revert special-casing - for (Span2.Builder next : spans) { - if (Kind.CLIENT.equals(next.kind)) { + for (Span.Builder next : spans) { + if (Kind.CLIENT.equals(next.kind())) { if (cs != null) next.timestamp(cs.timestamp); - } else if (Kind.SERVER.equals(next.kind)) { + } else if (Kind.SERVER.equals(next.kind())) { if (sr != null) next.timestamp(sr.timestamp); } } @@ -141,8 +141,8 @@ void processAnnotations(Span source) { // ms and mr are not supposed to be in the same span, but in case they are.. if (ms != null && mr != null) { // special-case loopback: We need to make sure on loopback there are two span2s - Span2.Builder producer = forEndpoint(source, ms.endpoint); - Span2.Builder consumer; + Span.Builder producer = forEndpoint(source, ms.endpoint); + Span.Builder consumer; if (closeEnough(ms.endpoint, mr.endpoint)) { producer.kind(Kind.PRODUCER); // fork a new span for the consumer side @@ -173,8 +173,8 @@ void processAnnotations(Span source) { } } - void maybeTimestampDuration(Span source, Annotation begin, @Nullable Annotation end) { - Span2.Builder span2 = forEndpoint(source, begin.endpoint); + void maybeTimestampDuration(zipkin.Span source, Annotation begin, @Nullable Annotation end) { + Span.Builder span2 = forEndpoint(source, begin.endpoint); if (source.timestamp != null && source.duration != null) { span2.timestamp(source.timestamp).duration(source.duration); } else { @@ -183,7 +183,7 @@ void maybeTimestampDuration(Span source, Annotation begin, @Nullable Annotation } } - void processBinaryAnnotations(Span source) { + void processBinaryAnnotations(zipkin.Span source) { Endpoint ca = null, sa = null, ma = null; for (int i = 0, length = source.binaryAnnotations.size(); i < length; i++) { BinaryAnnotation b = source.binaryAnnotations.get(i); @@ -200,7 +200,7 @@ void processBinaryAnnotations(Span source) { continue; } - Span2.Builder currentSpan = forEndpoint(source, b.endpoint); + Span.Builder currentSpan = forEndpoint(source, b.endpoint); switch (b.type) { case BOOL: break; // already handled @@ -250,30 +250,31 @@ void processBinaryAnnotations(Span source) { } } - Span2.Builder forEndpoint(Span source, @Nullable Endpoint e) { + Span.Builder forEndpoint(zipkin.Span source, @Nullable Endpoint e) { if (e == null) return spans.get(0); // allocate missing endpoint data to first span for (int i = 0, length = spans.size(); i < length; i++) { - Span2.Builder next = spans.get(i); - if (next.localEndpoint == null) { - next.localEndpoint = e; + Span.Builder next = spans.get(i); + Endpoint nextLocalEndpoint = next.localEndpoint(); + if (nextLocalEndpoint == null) { + next.localEndpoint(e); return next; - } else if (closeEnough(next.localEndpoint, e)) { + } else if (closeEnough(nextLocalEndpoint, e)) { return next; } } return newSpanBuilder(source, e); } - Span2.Builder newSpanBuilder(Span source, Endpoint e) { - Span2.Builder result = newBuilder(source).localEndpoint(e); + Span.Builder newSpanBuilder(zipkin.Span source, Endpoint e) { + Span.Builder result = newBuilder(source).localEndpoint(e); spans.add(result); return result; } - List build() { + List build() { int length = spans.size(); if (length == 1) return Collections.singletonList(spans.get(0).build()); - List result = new ArrayList<>(length); + List result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(spans.get(i).build()); } @@ -285,8 +286,8 @@ static boolean closeEnough(Endpoint left, Endpoint right) { return left.serviceName.equals(right.serviceName); } - static Span2.Builder newBuilder(Span source) { - return Span2.builder() + static Span.Builder newBuilder(zipkin.Span source) { + return Span.builder() .traceIdHigh(source.traceIdHigh) .traceId(source.traceId) .parentId(source.parentId) @@ -295,9 +296,9 @@ static Span2.Builder newBuilder(Span source) { .debug(source.debug); } - /** Converts the input, parsing {@link Span2#kind()} into RPC annotations. */ - public static Span toSpan(Span2 in) { - Span.Builder result = Span.builder() + /** Converts the input, parsing {@link Span#kind()} into RPC annotations. */ + public static zipkin.Span toSpan(Span in) { + zipkin.Span.Builder result = zipkin.Span.builder() .traceIdHigh(in.traceIdHigh()) .traceId(in.traceId()) .parentId(in.parentId()) @@ -392,7 +393,8 @@ public static Span toSpan(Span2 in) { remoteEndpointType = Constants.MESSAGE_ADDR; if (timestamp != 0L && duration != 0L) { wr = Annotation.create(timestamp, Constants.WIRE_RECV, in.localEndpoint()); - mr = Annotation.create(timestamp + duration, Constants.MESSAGE_RECV, in.localEndpoint()); + mr = + Annotation.create(timestamp + duration, Constants.MESSAGE_RECV, in.localEndpoint()); } else if (timestamp != 0L) { mr = Annotation.create(timestamp, Constants.MESSAGE_RECV, in.localEndpoint()); } diff --git a/zipkin/src/main/java/zipkin/internal/V2StorageComponent.java b/zipkin/src/main/java/zipkin/internal/V2StorageComponent.java new file mode 100644 index 00000000000..950d1b3c185 --- /dev/null +++ b/zipkin/src/main/java/zipkin/internal/V2StorageComponent.java @@ -0,0 +1,46 @@ +/** + * Copyright 2015-2017 The OpenZipkin Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package zipkin.internal; + +import java.util.ArrayList; +import java.util.List; +import zipkin.internal.v2.Span; +import zipkin.storage.AsyncSpanConsumer; +import zipkin.storage.Callback; +import zipkin.storage.StorageComponent; + +public abstract class V2StorageComponent implements StorageComponent { + @Override public final AsyncSpanConsumer asyncSpanConsumer() { + return new V2AsyncSpanConsumerAdapter(v2AsyncSpanConsumer()); + } + + protected abstract zipkin.internal.v2.storage.AsyncSpanConsumer v2AsyncSpanConsumer(); + + static class V2AsyncSpanConsumerAdapter implements AsyncSpanConsumer { + final zipkin.internal.v2.storage.AsyncSpanConsumer delegate; + + V2AsyncSpanConsumerAdapter(zipkin.internal.v2.storage.AsyncSpanConsumer delegate) { + this.delegate = delegate; + } + + @Override public void accept(List spans, Callback callback) { + int length = spans.size(); + List linkSpans = new ArrayList<>(length); + for (int i = 0; i < length; i++) { + linkSpans.addAll(V2SpanConverter.fromSpan(spans.get(i))); + } + delegate.accept(linkSpans, callback); + } + } +} diff --git a/zipkin/src/main/java/zipkin/internal/Span2.java b/zipkin/src/main/java/zipkin/internal/v2/Span.java similarity index 89% rename from zipkin/src/main/java/zipkin/internal/Span2.java rename to zipkin/src/main/java/zipkin/internal/v2/Span.java index 26b7a64d753..733d6013b82 100644 --- a/zipkin/src/main/java/zipkin/internal/Span2.java +++ b/zipkin/src/main/java/zipkin/internal/v2/Span.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package zipkin.internal; +package zipkin.internal.v2; import com.google.auto.value.AutoValue; import java.io.Serializable; @@ -25,8 +25,8 @@ import zipkin.Annotation; import zipkin.Constants; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TraceKeys; +import zipkin.internal.Nullable; import zipkin.internal.v2.codec.Encoder; import static zipkin.internal.Util.UTF_8; @@ -36,28 +36,26 @@ import static zipkin.internal.Util.writeHexLong; /** - * * A trace is a series of spans (often RPC calls) which form a latency tree. * - *

Spans are usually created by instrumentation in RPC clients or servers, but can also - * represent in-process activity. Annotations in spans are similar to log statements, and are - * sometimes created directly by application developers to indicate events of interest, such as a - * cache miss. + *

Spans are usually created by instrumentation in RPC clients or servers, but can also represent + * in-process activity. Annotations in spans are similar to log statements, and are sometimes + * created directly by application developers to indicate events of interest, such as a cache miss. * - *

The root span is where {@link #parentId} is null; it usually has the longest {@link #duration} in the - * trace. + *

The root span is where {@link #parentId} is null; it usually has the longest {@link #duration} + * in the trace. * - *

Span identifiers are packed into longs, but should be treated opaquely. ID encoding is - * 16 or 32 character lower-hex, to avoid signed interpretation. * This is a single-host view of a {@link Span}: the primary way tracers record data. + *

Span identifiers are packed into longs, but should be treated opaquely. ID encoding is 16 or + * 32 character lower-hex, to avoid signed interpretation. * This is a single-host view of a {@link + * zipkin.Span}: the primary way tracers record data. * - *

Relationship to {@link zipkin.Span}

- *

This type is intended to replace use of {@link zipkin.Span}. Particularly, tracers represent a - * single-host view of an operation. By making one endpoint implicit for all data, this type does not - * need to repeat endpoints on each data like {@link zipkin.Span span} does. This results in simpler - * and smaller data. + *

Relationship to {@link zipkin.Span}

This type is intended to replace use of {@link + * zipkin.Span}. Particularly, tracers represent a single-host view of an operation. By making one + * endpoint implicit for all data, this type does not need to repeat endpoints on each data like + * {@link zipkin.Span span} does. This results in simpler and smaller data. */ @AutoValue -public abstract class Span2 implements Serializable { // for Spark jobs +public abstract class Span implements Serializable { // for Spark jobs private static final long serialVersionUID = 0L; /** When non-zero, the trace containing this span uses 128-bit trace identifiers. */ @@ -245,9 +243,6 @@ public static final class Builder { Boolean debug; Boolean shared; - Builder() { - } - public Builder clear() { traceIdHigh = 0L; traceId = null; @@ -289,7 +284,7 @@ public Builder clear() { return result; } - Builder(Span2 source) { + Builder(Span source) { traceId = source.traceId(); parentId = source.parentId(); id = source.id(); @@ -311,6 +306,14 @@ public Builder clear() { shared = source.shared(); } + @Nullable public Kind kind() { + return kind; + } + + @Nullable public Endpoint localEndpoint() { + return localEndpoint; + } + /** * Decodes the trace ID from its lower-hex representation. * @@ -325,13 +328,13 @@ public Builder traceId(String traceId) { return traceId(lowerHexToUnsignedLong(traceId)); } - /** @see Span2#traceIdHigh */ + /** @see Span#traceIdHigh */ public Builder traceIdHigh(long traceIdHigh) { this.traceIdHigh = traceIdHigh; return this; } - /** @see Span2#traceId */ + /** @see Span#traceId */ public Builder traceId(long traceId) { this.traceId = traceId; return this; @@ -347,7 +350,7 @@ public Builder parentId(@Nullable String parentId) { return this; } - /** @see Span2#parentId */ + /** @see Span#parentId */ public Builder parentId(@Nullable Long parentId) { this.parentId = parentId; return this; @@ -363,78 +366,78 @@ public Builder id(String id) { return this; } - /** @see Span2#id */ + /** @see Span#id */ public Builder id(long id) { this.id = id; return this; } - /** @see Span2#kind */ + /** @see Span#kind */ public Builder kind(@Nullable Kind kind) { this.kind = kind; return this; } - /** @see Span2#name */ + /** @see Span#name */ public Builder name(@Nullable String name) { this.name = name == null || name.isEmpty() ? null : name.toLowerCase(Locale.ROOT); return this; } - /** @see Span2#timestamp */ + /** @see Span#timestamp */ public Builder timestamp(@Nullable Long timestamp) { if (timestamp != null && timestamp == 0L) timestamp = null; this.timestamp = timestamp; return this; } - /** @see Span2#duration */ + /** @see Span#duration */ public Builder duration(@Nullable Long duration) { if (duration != null && duration == 0L) duration = null; this.duration = duration; return this; } - /** @see Span2#localEndpoint */ + /** @see Span#localEndpoint */ public Builder localEndpoint(@Nullable Endpoint localEndpoint) { this.localEndpoint = localEndpoint; return this; } - /** @see Span2#remoteEndpoint */ + /** @see Span#remoteEndpoint */ public Builder remoteEndpoint(@Nullable Endpoint remoteEndpoint) { this.remoteEndpoint = remoteEndpoint; return this; } - /** @see Span2#annotations */ + /** @see Span#annotations */ public Builder addAnnotation(long timestamp, String value) { if (annotations == null) annotations = new ArrayList<>(2); annotations.add(Annotation.create(timestamp, value, null)); return this; } - /** @see Span2#tags */ + /** @see Span#tags */ public Builder putTag(String key, String value) { if (tags == null) tags = new TreeMap<>(); this.tags.put(checkNotNull(key, "key"), checkNotNull(value, "value")); return this; } - /** @see Span2#debug */ + /** @see Span#debug */ public Builder debug(@Nullable Boolean debug) { this.debug = debug; return this; } - /** @see Span2#shared */ + /** @see Span#shared */ public Builder shared(@Nullable Boolean shared) { this.shared = shared; return this; } - public Span2 build() { - return new AutoValue_Span2( + public Span build() { + return new AutoValue_Span( traceIdHigh, traceId, parentId, @@ -451,6 +454,9 @@ public Span2 build() { shared ); } + + Builder() { + } } @Override public String toString() { diff --git a/zipkin/src/main/java/zipkin/internal/v2/codec/Decoder.java b/zipkin/src/main/java/zipkin/internal/v2/codec/Decoder.java index 28dc8f3e63f..45e64b3adcc 100644 --- a/zipkin/src/main/java/zipkin/internal/v2/codec/Decoder.java +++ b/zipkin/src/main/java/zipkin/internal/v2/codec/Decoder.java @@ -14,20 +14,19 @@ package zipkin.internal.v2.codec; import java.util.List; -import zipkin.Span; import zipkin.internal.JsonCodec; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; /** - * @param type of the span, usually {@link Span} + * @param type of the span, usually {@link zipkin.Span} */ public interface Decoder { - Decoder JSON = new Decoder() { + Decoder JSON = new Decoder() { @Override public Encoding encoding() { return Encoding.JSON; } - @Override public List decodeList(byte[] span) { + @Override public List decodeList(byte[] span) { return JsonCodec.readList(new Span2JsonAdapters.Span2Reader(), span); } }; diff --git a/zipkin/src/main/java/zipkin/internal/v2/codec/Encoder.java b/zipkin/src/main/java/zipkin/internal/v2/codec/Encoder.java index 28982949f2f..5f0d9c53f2c 100644 --- a/zipkin/src/main/java/zipkin/internal/v2/codec/Encoder.java +++ b/zipkin/src/main/java/zipkin/internal/v2/codec/Encoder.java @@ -13,22 +13,21 @@ */ package zipkin.internal.v2.codec; -import zipkin.Span; import zipkin.internal.JsonCodec; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import static zipkin.internal.v2.codec.Span2JsonAdapters.SPAN_WRITER; /** - * @param type of the span, usually {@link Span} + * @param type of the span, usually {@link zipkin.Span} */ public interface Encoder { - Encoder JSON = new Encoder() { + Encoder JSON = new Encoder() { @Override public Encoding encoding() { return Encoding.JSON; } - @Override public byte[] encode(Span2 span) { + @Override public byte[] encode(Span span) { return JsonCodec.write(SPAN_WRITER, span); } }; diff --git a/zipkin/src/main/java/zipkin/internal/v2/codec/Span2JsonAdapters.java b/zipkin/src/main/java/zipkin/internal/v2/codec/Span2JsonAdapters.java index 77a85f1b0a0..9779e9813f2 100644 --- a/zipkin/src/main/java/zipkin/internal/v2/codec/Span2JsonAdapters.java +++ b/zipkin/src/main/java/zipkin/internal/v2/codec/Span2JsonAdapters.java @@ -24,24 +24,24 @@ import zipkin.internal.Buffer; import zipkin.internal.JsonCodec; import zipkin.internal.JsonCodec.JsonReaderAdapter; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import static zipkin.internal.Buffer.asciiSizeInBytes; import static zipkin.internal.Buffer.ipv6SizeInBytes; import static zipkin.internal.Buffer.jsonEscapedSizeInBytes; /** - * Internal type supporting codec operations in {@link Span2}. Design rationale is the same as + * Internal type supporting codec operations in {@link Span}. Design rationale is the same as * {@link JsonCodec}. */ final class Span2JsonAdapters { - static final class Span2Reader implements JsonReaderAdapter { - Span2.Builder builder; + static final class Span2Reader implements JsonReaderAdapter { + Span.Builder builder; - @Override public Span2 fromJson(JsonReader reader) throws IOException { + @Override public Span fromJson(JsonReader reader) throws IOException { if (builder == null) { - builder = Span2.builder(); + builder = Span.builder(); } else { builder.clear(); } @@ -63,7 +63,7 @@ static final class Span2Reader implements JsonReaderAdapter { if (nextName.equals("parentId")) { builder.parentId(reader.nextString()); } else if (nextName.equals("kind")) { - builder.kind(Span2.Kind.valueOf(reader.nextString())); + builder.kind(Span.Kind.valueOf(reader.nextString())); } else if (nextName.equals("name")) { builder.name(reader.nextString()); } else if (nextName.equals("timestamp")) { @@ -120,7 +120,7 @@ static final class Span2Reader implements JsonReaderAdapter { } @Override public String toString() { - return "Span2"; + return "Span"; } } @@ -208,8 +208,8 @@ static final class Span2Reader implements JsonReaderAdapter { } }; - static final Buffer.Writer SPAN_WRITER = new Buffer.Writer() { - @Override public int sizeInBytes(Span2 value) { + static final Buffer.Writer SPAN_WRITER = new Buffer.Writer() { + @Override public int sizeInBytes(Span value) { int sizeInBytes = 0; if (value.traceIdHigh() != 0) sizeInBytes += 16; sizeInBytes += "{\"traceId\":\"".length() + 16 + 1; @@ -270,7 +270,7 @@ static final class Span2Reader implements JsonReaderAdapter { return ++sizeInBytes;// end curly-brace } - @Override public void write(Span2 value, Buffer b) { + @Override public void write(Span value, Buffer b) { b.writeAscii("{\"traceId\":\""); if (value.traceIdHigh() != 0) { b.writeLowerHex(value.traceIdHigh()); @@ -325,7 +325,7 @@ static final class Span2Reader implements JsonReaderAdapter { } @Override public String toString() { - return "Span2"; + return "Span"; } }; diff --git a/zipkin/src/main/java/zipkin/internal/v2/storage/AsyncSpanConsumer.java b/zipkin/src/main/java/zipkin/internal/v2/storage/AsyncSpanConsumer.java index 31bfe2616a8..a443a88d0f1 100644 --- a/zipkin/src/main/java/zipkin/internal/v2/storage/AsyncSpanConsumer.java +++ b/zipkin/src/main/java/zipkin/internal/v2/storage/AsyncSpanConsumer.java @@ -14,11 +14,11 @@ package zipkin.internal.v2.storage; import java.util.List; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.storage.Callback; // @FunctionalInterface public interface AsyncSpanConsumer { - void accept(List spans, Callback callback); + void accept(List spans, Callback callback); } diff --git a/zipkin/src/main/java/zipkin/storage/SpanStore.java b/zipkin/src/main/java/zipkin/storage/SpanStore.java index 2cb10a2e033..c2c8308dde4 100644 --- a/zipkin/src/main/java/zipkin/storage/SpanStore.java +++ b/zipkin/src/main/java/zipkin/storage/SpanStore.java @@ -16,8 +16,8 @@ import java.util.List; import zipkin.DependencyLink; import zipkin.Endpoint; -import zipkin.Span; import zipkin.internal.Nullable; +import zipkin.internal.v2.Span; public interface SpanStore { @@ -31,7 +31,7 @@ public interface SpanStore { *

If {@link StorageComponent.Builder#strictTraceId(boolean)} is enabled, spans with the * same 64-bit trace ID will be grouped together. */ - List> getTraces(QueryRequest request); + List> getTraces(QueryRequest request); /** * Get the available trace information from the storage system. Spans in trace are sorted by the @@ -40,13 +40,13 @@ public interface SpanStore { *

When {@link StorageComponent.Builder#strictTraceId(boolean)} is true, spans with the * same {@code traceIdLow} are returned even if the {@code traceIdHigh is different}. * - * @param traceIdHigh The upper 64-bits of the trace ID. See {@link Span#traceIdHigh} - * @param traceIdLow The lower 64-bits of the trace ID. See {@link Span#traceId} + * @param traceIdHigh The upper 64-bits of the trace ID. See {@link zipkin.Span#traceIdHigh} + * @param traceIdLow The lower 64-bits of the trace ID. See {@link zipkin.Span#traceId} * @return a list of spans with the same 128-bit trace ID, or null if not present. * @since 1.15 */ @Nullable - List getTrace(long traceIdHigh, long traceIdLow); + List getTrace(long traceIdHigh, long traceIdLow); /** * Retrieves spans that share a 128-bit trace id, as returned from backend data store queries, @@ -59,13 +59,13 @@ public interface SpanStore { *

When {@link StorageComponent.Builder#strictTraceId(boolean)} is true, spans with the * same {@code traceIdLow} are returned even if the {@code traceIdHigh is different}. * - * @param traceIdHigh The upper 64-bits of the trace ID. See {@link Span#traceIdHigh} - * @param traceIdLow The lower 64-bits of the trace ID. See {@link Span#traceId} + * @param traceIdHigh The upper 64-bits of the trace ID. See {@link zipkin.Span#traceIdHigh} + * @param traceIdLow The lower 64-bits of the trace ID. See {@link zipkin.Span#traceId} * @return a list of spans with the same 128-bit trace ID, or null if not present. * @since 1.15 */ @Nullable - List getRawTrace(long traceIdHigh, long traceIdLow); + List getRawTrace(long traceIdHigh, long traceIdLow); /** * This calls {@link #getTrace(long, long)} with {@code traceIdHigh} set to zero. @@ -74,7 +74,7 @@ public interface SpanStore { */ @Deprecated @Nullable - List getTrace(long traceId); + List getTrace(long traceId); /** * This calls {@link #getRawTrace(long, long)} with {@code traceIdHigh} set to zero. @@ -83,7 +83,7 @@ public interface SpanStore { */ @Deprecated @Nullable - List getRawTrace(long traceId); + List getRawTrace(long traceId); /** * Get all the {@link Endpoint#serviceName service names}. @@ -107,7 +107,7 @@ public interface SpanStore { * the original endTs, even when bucketed. Using the daily example, if endTs was 11pm and lookback * was 25 hours, the implementation would query against 2 buckets. * - *

Some implementations parse {@link zipkin.internal.DependencyLinkSpan} from storage and call + *

Some implementations parse {@link Span} from storage and call * {@link zipkin.internal.DependencyLinker} to aggregate links. The reason is certain graph logic, * such as skipping up the tree is difficult to implement as a storage query. * @@ -115,9 +115,9 @@ public interface SpanStore { * {@link StorageComponent.Builder#strictTraceId(boolean)} was set to false. This ensures call * counts are not incremented twice due to one hop downgrading from 128 to 64-bit trace IDs. * - * @param endTs only return links from spans where {@link Span#timestamp} are at or before this + * @param endTs only return links from spans where {@link zipkin.Span#timestamp} are at or before this * time in epoch milliseconds. - * @param lookback only return links from spans where {@link Span#timestamp} are at or after + * @param lookback only return links from spans where {@link zipkin.Span#timestamp} are at or after * (endTs - lookback) in milliseconds. Defaults to endTs. * @return dependency links in an interval contained by (endTs - lookback) or empty if none are * found diff --git a/zipkin/src/test/java/zipkin/AnnotationTest.java b/zipkin/src/test/java/zipkin/AnnotationTest.java index a83d0c0b7cd..7d6b8d4a41f 100644 --- a/zipkin/src/test/java/zipkin/AnnotationTest.java +++ b/zipkin/src/test/java/zipkin/AnnotationTest.java @@ -36,7 +36,7 @@ public class AnnotationTest { "{\"timestamp\":1,\"value\":\"foo\",\"endpoint\":{\"serviceName\":\"app\",\"ipv4\":\"172.17.0.2\",\"port\":8080}}"); } - // simple spans will not have endpoint defined eventhough normal ones will + // v2 spans will not have endpoint defined eventhough normal ones will @Test public void toStringIsJson_withoutEndpoint() { assertThat(Annotation.create(1L, "foo", null)) .hasToString("{\"timestamp\":1,\"value\":\"foo\"}"); diff --git a/zipkin/src/test/java/zipkin/collector/CollectorSamplerTest.java b/zipkin/src/test/java/zipkin/collector/CollectorSamplerTest.java index 536e7b0a72d..d5ddff4b7fd 100644 --- a/zipkin/src/test/java/zipkin/collector/CollectorSamplerTest.java +++ b/zipkin/src/test/java/zipkin/collector/CollectorSamplerTest.java @@ -37,7 +37,7 @@ public void mostNegativeNumberDefence() { CollectorSampler sampler = CollectorSampler.create(0.1f); assertThat(sampler.isSampled(Long.MIN_VALUE, null)) - .isEqualTo(sampler.isSampled(Long.MAX_VALUE, null)); + .isEqualTo(sampler.isSampled(Long.MAX_VALUE, null)); } @Test @@ -45,7 +45,7 @@ public void debugWins() { CollectorSampler sampler = CollectorSampler.create(0.0f); assertThat(sampler.isSampled(Long.MIN_VALUE, true)) - .isTrue(); + .isTrue(); } @Test @@ -54,7 +54,7 @@ public void retain10Percent() { CollectorSampler sampler = CollectorSampler.create(sampleRate); assertThat(lotsOfSpans().filter(s -> sampler.isSampled(s.traceId, null)).count()) - .isCloseTo((long) (LOTS_OF_SPANS.length * sampleRate), withPercentage(3)); + .isCloseTo((long) (LOTS_OF_SPANS.length * sampleRate), withPercentage(3)); } /** @@ -74,7 +74,7 @@ public void zeroMeansDropAllTraces() { CollectorSampler sampler = CollectorSampler.create(0.0f); assertThat(lotsOfSpans().filter(s -> sampler.isSampled(s.traceId, null))) - .isEmpty(); + .isEmpty(); } @Test @@ -82,7 +82,7 @@ public void oneMeansKeepAllTraces() { CollectorSampler sampler = CollectorSampler.create(1.0f); assertThat(lotsOfSpans().filter(s -> sampler.isSampled(s.traceId, null))) - .hasSize(LOTS_OF_SPANS.length); + .hasSize(LOTS_OF_SPANS.length); } @Test diff --git a/zipkin/src/test/java/zipkin/collector/CollectorTest.java b/zipkin/src/test/java/zipkin/collector/CollectorTest.java index cacd0e7da6c..2121cccd482 100644 --- a/zipkin/src/test/java/zipkin/collector/CollectorTest.java +++ b/zipkin/src/test/java/zipkin/collector/CollectorTest.java @@ -15,19 +15,17 @@ import org.junit.Before; import org.junit.Test; -import zipkin.Span; import zipkin.SpanDecoder; import zipkin.internal.ApplyTimestampAndDuration; import zipkin.internal.DetectingSpanDecoder; -import zipkin.internal.Span2; -import zipkin.internal.Span2Component; -import zipkin.internal.Span2Converter; import zipkin.internal.Util; +import zipkin.internal.V2SpanConverter; +import zipkin.internal.V2StorageComponent; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Encoder; import zipkin.internal.v2.codec.MessageEncoder; import zipkin.internal.v2.storage.AsyncSpanConsumer; import zipkin.storage.Callback; -import zipkin.storage.StorageComponent; import static java.util.Arrays.asList; import static org.mockito.ArgumentMatchers.any; @@ -41,10 +39,10 @@ import static zipkin.storage.Callback.NOOP; public class CollectorTest { - StorageComponent storage = mock(StorageComponent.class); + zipkin.storage.StorageComponent storage = mock(zipkin.storage.StorageComponent.class); Collector collector; - Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); - Span2 span2_1 = Span2Converter.fromSpan(span1).get(0); + zipkin.Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); + Span span2_1 = V2SpanConverter.fromSpan(span1).get(0); @Before public void setup() throws Exception { collector = spy(Collector.builder(Collector.class) @@ -100,12 +98,12 @@ public class CollectorTest { * double-conversion. */ @Test public void routesToSpan2Collector() { - abstract class WithSpan2 extends Span2Component implements StorageComponent { - @Override public abstract AsyncSpanConsumer asyncSpan2Consumer(); + abstract class WithSpan2 extends V2StorageComponent implements zipkin.storage.StorageComponent { + @Override public abstract zipkin.internal.v2.storage.AsyncSpanConsumer v2AsyncSpanConsumer(); } WithSpan2 storage = mock(WithSpan2.class); AsyncSpanConsumer span2Consumer = mock(AsyncSpanConsumer.class); - when(storage.asyncSpan2Consumer()).thenReturn(span2Consumer); + when(storage.v2AsyncSpanConsumer()).thenReturn(span2Consumer); collector = spy(Collector.builder(Collector.class) .storage(storage).build()); @@ -113,7 +111,7 @@ abstract class WithSpan2 extends Span2Component implements StorageComponent { byte[] bytes = MessageEncoder.JSON_BYTES.encode(asList(Encoder.JSON.encode(span2_1))); collector.acceptSpans(bytes, SpanDecoder.DETECTING_DECODER, NOOP); - verify(collector, never()).isSampled(any(Span.class)); // skips v1 processing + verify(collector, never()).isSampled(any(zipkin.Span.class)); // skips v1 processing verify(span2Consumer).accept(eq(asList(span2_1)), any(Callback.class)); // goes to v2 instead } } diff --git a/zipkin/src/test/java/zipkin/internal/DependencyLinkerTest.java b/zipkin/src/test/java/zipkin/internal/DependencyLinkerTest.java index 6f87b8921a8..5d054be5706 100644 --- a/zipkin/src/test/java/zipkin/internal/DependencyLinkerTest.java +++ b/zipkin/src/test/java/zipkin/internal/DependencyLinkerTest.java @@ -21,9 +21,9 @@ import org.junit.Test; import zipkin.DependencyLink; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TestObjects; -import zipkin.internal.Span2.Kind; +import zipkin.internal.v2.Span; +import zipkin.internal.v2.Span.Kind; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -58,7 +58,7 @@ public void linksSpans() { @Test public void dropsSelfReferencingSpans() { - List trace = TestObjects.TRACE.stream() + List trace = TestObjects.TRACE.stream() .map(s -> s.toBuilder().parentId(s.parentId != null ? s.id : null).build()) .collect(Collectors.toList()); @@ -72,7 +72,7 @@ public void dropsSelfReferencingSpans() { @Test public void messagingSpansDontLinkWithoutBroker_consumer() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", null, false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", "kafka", false) ); @@ -84,7 +84,7 @@ public void messagingSpansDontLinkWithoutBroker_consumer() { @Test public void messagingSpansDontLinkWithoutBroker_producer() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", "kafka", false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", null, false) ); @@ -96,7 +96,7 @@ public void messagingSpansDontLinkWithoutBroker_producer() { @Test public void messagingWithBroker_both_sides_same() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", "kafka", false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", "kafka", false) ); @@ -109,7 +109,7 @@ public void messagingWithBroker_both_sides_same() { @Test public void messagingWithBroker_different() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", "kafka1", false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", "kafka2", false) ); @@ -123,7 +123,7 @@ public void messagingWithBroker_different() { /** Shows we don't assume there's a direct link between producer and consumer. */ @Test public void messagingWithoutBroker_noLinks() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", null, false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", null, false) ); @@ -135,7 +135,7 @@ public void messagingWithoutBroker_noLinks() { /** When a server is the child of a producer span, make a link as it is really an RPC */ @Test public void producerLinksToServer_childSpan() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", null, false), span2(1L, 1L, 2L, Kind.SERVER, "server", null, false) ); @@ -151,7 +151,7 @@ public void producerLinksToServer_childSpan() { */ @Test public void producerLinksToServer_sameSpan() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.PRODUCER, "producer", null, false), span2(1L, null, 1L, Kind.SERVER, "server", null, false) .toBuilder().shared(true).build() @@ -168,7 +168,7 @@ public void producerLinksToServer_sameSpan() { */ @Test public void clientDoesntLinkToConsumer_child() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.CLIENT, "client", null, false), span2(1L, 1L, 2L, Kind.CONSUMER, "consumer", null, false) ); @@ -183,13 +183,13 @@ public void clientDoesntLinkToConsumer_child() { */ @Test public void linksSpansDirectedByKind() { - List validRootSpans = asList( + List validRootSpans = asList( span2(1L, null, 1L, Kind.SERVER, "server", "client", false), span2(1L, null, 1L, Kind.CLIENT, "client", "server", false) .toBuilder().shared(true).build() ); - for (Span2 span : validRootSpans) { + for (Span span : validRootSpans) { assertThat(new DependencyLinker() .putTrace(asList(span).iterator()).link()) .containsOnly(DependencyLink.create("client", "server", 1L)); @@ -198,7 +198,7 @@ public void linksSpansDirectedByKind() { @Test public void callsAgainstTheSameLinkIncreasesCallCount_span() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.SERVER, "client", null, false), span2(1L, 1L, 2L, Kind.CLIENT, null, "server", false), span2(1L, 1L, 3L, Kind.CLIENT, null, "server", false) @@ -211,7 +211,7 @@ public void callsAgainstTheSameLinkIncreasesCallCount_span() { @Test public void callsAgainstTheSameLinkIncreasesCallCount_trace() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.SERVER, "client", null, false), span2(1L, 1L, 2L, Kind.CLIENT, null, "server", false) ); @@ -228,7 +228,7 @@ public void callsAgainstTheSameLinkIncreasesCallCount_trace() { */ @Test public void singleHostSpansResultInASingleCallCount() { - List trace = asList( + List trace = asList( span2(3L, null, 3L, Kind.CLIENT, "client", null, false), span2(3L, 3L, 4L, Kind.SERVER, "server", null, false) ); @@ -240,7 +240,7 @@ public void singleHostSpansResultInASingleCallCount() { @Test public void singleHostSpansResultInASingleErrorCount() { - List trace = asList( + List trace = asList( span2(3L, null, 3L, Kind.CLIENT, "client", null, true), span2(3L, 3L, 4L, Kind.SERVER, "server", null, true) ); @@ -252,7 +252,7 @@ public void singleHostSpansResultInASingleErrorCount() { @Test public void singleHostSpansResultInASingleErrorCount_sameId() { - List trace = asList( + List trace = asList( span2(3L, null, 3L, Kind.CLIENT, "client", null, true), span2(3L, null, 3L, Kind.SERVER, "server", null, true) .toBuilder().shared(true).build() @@ -265,7 +265,7 @@ public void singleHostSpansResultInASingleErrorCount_sameId() { @Test public void singleHostSpansResultInASingleCallCount_defersNameToServer() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.CLIENT, "client", "server", false), span2(1L, 1L, 2L, Kind.SERVER, "server", null, false) ); @@ -280,7 +280,7 @@ public void singleHostSpansResultInASingleCallCount_defersNameToServer() { @Test public void singleHostSpans_multipleChildren() { - List trace = asList( + List trace = asList( span2(4L, null, 4L, Kind.CLIENT, "client", null, false), span2(4L, 4L, 5L, Kind.SERVER, "server", "client", true), span2(4L, 4L, 6L, Kind.SERVER, "server", "client", false) @@ -293,7 +293,7 @@ public void singleHostSpans_multipleChildren() { @Test public void singleHostSpans_multipleChildren_defersNameToServer() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.CLIENT, "client", "server", false), span2(1L, 1L, 2L, Kind.SERVER, "server", null, false), span2(1L, 1L, 3L, Kind.SERVER, "server", null, false) @@ -312,7 +312,7 @@ public void singleHostSpans_multipleChildren_defersNameToServer() { */ @Test public void intermediatedClientSpansMissingLocalServiceNameLinkToNearestServer() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.SERVER, "client", null, false), span2(1L, 1L, 2L, null, null, null, false), // possibly a local fan-out span @@ -327,7 +327,7 @@ public void intermediatedClientSpansMissingLocalServiceNameLinkToNearestServer() @Test public void errorsOnUninstrumentedLinks() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.SERVER, "client", null, false), span2(1L, 1L, 2L, null, null, null, false), // there's no remote here, so we shouldn't see any error count @@ -342,7 +342,7 @@ public void errorsOnUninstrumentedLinks() { @Test public void errorsOnInstrumentedLinks() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.SERVER, "foo", null, false), span2(1L, 1L, 2L, null, null, null, false), span2(1L, 2L, 3L, Kind.CLIENT, "bar", "baz", true), @@ -357,7 +357,7 @@ public void errorsOnInstrumentedLinks() { @Test public void linkWithErrorIsLogged() { - List trace = asList( + List trace = asList( span2(1L, 2L, 3L, Kind.CLIENT, "foo", "bar", true) ); new DependencyLinker(logger).putTrace(trace.iterator()).link(); @@ -370,7 +370,7 @@ public void linkWithErrorIsLogged() { /** Tag indicates a failed span, not an annotation */ @Test public void annotationNamedErrorDoesntIncrementErrorCount() { - List trace = asList( + List trace = asList( span2(1L, 2L, 3L, Kind.CLIENT, "foo", "bar", false) .toBuilder().addAnnotation(1L, ERROR).build() ); @@ -383,12 +383,12 @@ public void annotationNamedErrorDoesntIncrementErrorCount() { /** A loopback span is direction-agnostic, so can be linked properly regardless of kind. */ @Test public void linksLoopbackSpans() { - List validRootSpans = asList( + List validRootSpans = asList( span2(1L, null, 1L, Kind.SERVER, "service", "service", false), span2(2L, null, 2L, Kind.CLIENT, "service", "service", false) ); - for (Span2 span : validRootSpans) { + for (Span span : validRootSpans) { assertThat(new DependencyLinker() .putTrace(asList(span).iterator()).link()) .containsOnly(DependencyLink.create("service", "service", 1L)); @@ -397,7 +397,7 @@ public void linksLoopbackSpans() { @Test public void noSpanKindTreatedSameAsClient() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, null, "some-client", "web", false), span2(1L, 1L, 2L, null, "web", "app", false), span2(1L, 2L, 3L, null, "app", "db", false) @@ -412,7 +412,7 @@ public void noSpanKindTreatedSameAsClient() { @Test public void noSpanKindWithError() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, null, "some-client", "web", false), span2(1L, 1L, 2L, null, "web", "app", true), span2(1L, 2L, 3L, null, "app", "db", false) @@ -431,7 +431,7 @@ public void noSpanKindWithError() { */ @Test public void cannotLinkSingleSpanWithoutBothServiceNames() { - List incompleteRootSpans = asList( + List incompleteRootSpans = asList( span2(1L, null, 1L, Kind.SERVER, null, null, false), span2(1L, null, 1L, Kind.SERVER, "server", null, false), span2(1L, null, 1L, Kind.SERVER, null, "client", false), @@ -440,7 +440,7 @@ public void cannotLinkSingleSpanWithoutBothServiceNames() { span2(1L, null, 1L, Kind.CLIENT, null, "server", false) ); - for (Span2 span : incompleteRootSpans) { + for (Span span : incompleteRootSpans) { assertThat(new DependencyLinker(logger) .putTrace(asList(span).iterator()).link()) .isEmpty(); @@ -450,7 +450,7 @@ public void cannotLinkSingleSpanWithoutBothServiceNames() { @Test public void doesntLinkUnrelatedSpansWhenMissingRootSpan() { long missingParentId = 1; - List trace = asList( + List trace = asList( span2(1L, missingParentId, 2L, Kind.SERVER, "service1", null, false), span2(1L, missingParentId, 3L, Kind.SERVER, "service2", null, false) ); @@ -467,7 +467,7 @@ public void doesntLinkUnrelatedSpansWhenMissingRootSpan() { @Test public void linksRelatedSpansWhenMissingRootSpan() { long missingParentId = 1; - List trace = asList( + List trace = asList( span2(1L, missingParentId, 2L, Kind.SERVER, "service1", null, false), span2(1L, 2L, 3L, Kind.SERVER, "service2", null, false) ); @@ -484,7 +484,7 @@ public void linksRelatedSpansWhenMissingRootSpan() { /** Client+Server spans that don't share IDs are treated as server spans missing their peer */ @Test public void linksSingleHostSpans() { - List singleHostSpans = asList( + List singleHostSpans = asList( span2(1L, null, 1L, Kind.CLIENT, "web", null, false), span2(1L, 1L, 2L, Kind.SERVER, "app", null, false) ); @@ -496,7 +496,7 @@ public void linksSingleHostSpans() { @Test public void linksSingleHostSpans_errorOnClient() { - List trace = asList( + List trace = asList( span2(1L, null, 1L, Kind.CLIENT, "web", null, true), span2(1L, 1L, 2L, Kind.SERVER, "app", null, false) ); @@ -509,7 +509,7 @@ public void linksSingleHostSpans_errorOnClient() { /** Creates a link when there's a span missing, in this case 2L which is an RPC from web to app */ @Test public void missingSpan() { - List singleHostSpans = asList( + List singleHostSpans = asList( span2(1L, null, 1L, Kind.SERVER, "web", null, false), span2(1L, 1L, 2L, Kind.CLIENT, "app", null, false) ); @@ -551,9 +551,9 @@ public void merge_error() { ); } - static Span2 span2(long traceId, @Nullable Long parentId, long id, @Nullable Kind kind, + static Span span2(long traceId, @Nullable Long parentId, long id, @Nullable Kind kind, @Nullable String local, @Nullable String remote, boolean isError) { - Span2.Builder result = Span2.builder(); + Span.Builder result = Span.builder(); result.traceId(traceId).parentId(parentId).id(id).kind(kind); if (local != null) result.localEndpoint(Endpoint.builder().serviceName(local).build()); if (remote != null) result.remoteEndpoint(Endpoint.builder().serviceName(remote).build()); diff --git a/zipkin/src/test/java/zipkin/internal/DetectingSpanDecoderTest.java b/zipkin/src/test/java/zipkin/internal/DetectingSpanDecoderTest.java index 64538e5e4c3..6b402d4fcb3 100644 --- a/zipkin/src/test/java/zipkin/internal/DetectingSpanDecoderTest.java +++ b/zipkin/src/test/java/zipkin/internal/DetectingSpanDecoderTest.java @@ -17,20 +17,20 @@ import java.util.stream.Stream; import org.junit.Test; import zipkin.Codec; -import zipkin.Span; import zipkin.SpanDecoder; -import zipkin.internal.v2.codec.MessageEncoder; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Encoder; +import zipkin.internal.v2.codec.MessageEncoder; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static zipkin.TestObjects.LOTS_OF_SPANS; public class DetectingSpanDecoderTest { - Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); - Span span2 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1]); - Span2 span2_1 = Span2Converter.fromSpan(span1).get(0); - Span2 span2_2 = Span2Converter.fromSpan(span2).get(0); + zipkin.Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); + zipkin.Span span2 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1]); + Span span2_1 = V2SpanConverter.fromSpan(span1).get(0); + Span span2_2 = V2SpanConverter.fromSpan(span2).get(0); SpanDecoder decoder = new DetectingSpanDecoder(); diff --git a/zipkin/src/test/java/zipkin/internal/Span2JsonSpanDecoderTest.java b/zipkin/src/test/java/zipkin/internal/V2JsonSpanDecoderTest.java similarity index 77% rename from zipkin/src/test/java/zipkin/internal/Span2JsonSpanDecoderTest.java rename to zipkin/src/test/java/zipkin/internal/V2JsonSpanDecoderTest.java index c5d853beb01..af7114fcfc5 100644 --- a/zipkin/src/test/java/zipkin/internal/Span2JsonSpanDecoderTest.java +++ b/zipkin/src/test/java/zipkin/internal/V2JsonSpanDecoderTest.java @@ -14,22 +14,22 @@ package zipkin.internal; import org.junit.Test; -import zipkin.Span; import zipkin.SpanDecoder; -import zipkin.internal.v2.codec.MessageEncoder; +import zipkin.internal.v2.Span; import zipkin.internal.v2.codec.Encoder; +import zipkin.internal.v2.codec.MessageEncoder; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static zipkin.TestObjects.LOTS_OF_SPANS; -public class Span2JsonSpanDecoderTest { - Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); - Span span2 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1]); - Span2 span2_1 = Span2Converter.fromSpan(span1).get(0); - Span2 span2_2 = Span2Converter.fromSpan(span2).get(0); +public class V2JsonSpanDecoderTest { + zipkin.Span span1 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]); + zipkin.Span span2 = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1]); + Span span2_1 = V2SpanConverter.fromSpan(span1).get(0); + Span span2_2 = V2SpanConverter.fromSpan(span2).get(0); - SpanDecoder decoder = new Span2JsonSpanDecoder(); + SpanDecoder decoder = new V2JsonSpanDecoder(); @Test(expected = UnsupportedOperationException.class) public void readSpan() { decoder.readSpan(Encoder.JSON.encode(span2_1)); diff --git a/zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java b/zipkin/src/test/java/zipkin/internal/V2SpanConverterTest.java similarity index 86% rename from zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java rename to zipkin/src/test/java/zipkin/internal/V2SpanConverterTest.java index 34833a122ed..c84fb6e8e7e 100644 --- a/zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java +++ b/zipkin/src/test/java/zipkin/internal/V2SpanConverterTest.java @@ -20,14 +20,14 @@ import zipkin.BinaryAnnotation.Type; import zipkin.Constants; import zipkin.Endpoint; -import zipkin.Span; import zipkin.TraceKeys; -import zipkin.internal.Span2.Kind; +import zipkin.internal.v2.Span; +import zipkin.internal.v2.Span.Kind; import static org.assertj.core.api.Assertions.assertThat; import static zipkin.Constants.LOCAL_COMPONENT; -public class Span2ConverterTest { +public class V2SpanConverterTest { Endpoint frontend = Endpoint.create("frontend", 127 << 24 | 1); Endpoint backend = Endpoint.builder() .serviceName("backend") @@ -37,7 +37,7 @@ public class Span2ConverterTest { Endpoint kafka = Endpoint.create("kafka", 0); @Test public void client() { - Span2 simpleClient = Span2.builder() + Span simpleClient = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -53,7 +53,7 @@ public class Span2ConverterTest { .putTag("clnt/finagle.version", "6.45.0") .build(); - Span client = Span.builder() + zipkin.Span client = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -70,14 +70,14 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, backend)) .build(); - assertThat(Span2Converter.toSpan(simpleClient)) + assertThat(V2SpanConverter.toSpan(simpleClient)) .isEqualTo(client); - assertThat(Span2Converter.fromSpan(client)) + assertThat(V2SpanConverter.fromSpan(client)) .containsExactly(simpleClient); } @Test public void client_unfinished() { - Span2 simpleClient = Span2.builder() + Span simpleClient = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -88,7 +88,7 @@ public class Span2ConverterTest { .addAnnotation(1472470996238000L, Constants.WIRE_SEND) .build(); - Span client = Span.builder() + zipkin.Span client = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -99,14 +99,14 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996238000L, Constants.WIRE_SEND, frontend)) .build(); - assertThat(Span2Converter.toSpan(simpleClient)) + assertThat(V2SpanConverter.toSpan(simpleClient)) .isEqualTo(client); - assertThat(Span2Converter.fromSpan(client)) + assertThat(V2SpanConverter.fromSpan(client)) .containsExactly(simpleClient); } @Test public void client_kindInferredFromAnnotation() { - Span2 simpleClient = Span2.builder() + Span simpleClient = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -117,7 +117,7 @@ public class Span2ConverterTest { .addAnnotation(1472470996199000L, Constants.CLIENT_SEND) .build(); - Span client = Span.builder() + zipkin.Span client = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -129,12 +129,12 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996238000L, Constants.CLIENT_RECV, frontend)) .build(); - assertThat(Span2Converter.toSpan(simpleClient)) + assertThat(V2SpanConverter.toSpan(simpleClient)) .isEqualTo(client); } @Test public void noAnnotationsExceptAddresses() { - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -145,7 +145,7 @@ public class Span2ConverterTest { .duration(207000L) .build(); - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -157,14 +157,14 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, backend)) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void fromSpan_redundantAddressAnnotations() { - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -175,7 +175,7 @@ public class Span2ConverterTest { .duration(207000L) .build(); - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -189,12 +189,12 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, frontend)) .build(); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void server() { - Span2 simpleServer = Span2.builder() + Span simpleServer = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .id("216a2aea45d08fc9") .name("get") @@ -207,7 +207,7 @@ public class Span2ConverterTest { .putTag("clnt/finagle.version", "6.45.0") .build(); - Span server = Span.builder() + zipkin.Span server = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .id(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) @@ -221,15 +221,15 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, frontend)) .build(); - assertThat(Span2Converter.toSpan(simpleServer)) + assertThat(V2SpanConverter.toSpan(simpleServer)) .isEqualTo(server); - assertThat(Span2Converter.fromSpan(server)) + assertThat(V2SpanConverter.fromSpan(server)) .containsExactly(simpleServer); } /** Buggy instrumentation can send data with missing endpoints. Make sure we can record it. */ @Test public void missingEndpoints() { - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -238,7 +238,7 @@ public class Span2ConverterTest { .duration(207000L) .build(); - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -246,15 +246,15 @@ public class Span2ConverterTest { .timestamp(1472470996199000L).duration(207000L) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } /** No special treatment for invalid core annotations: missing endpoint */ @Test public void missingEndpoints_coreAnnotation() { - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -263,7 +263,7 @@ public class Span2ConverterTest { .addAnnotation(1472470996199000L, "sr") .build(); - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -272,14 +272,14 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996199000L, "sr", null)) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void localSpan_emptyComponent() { - Span2 simpleLocal = Span2.builder() + Span simpleLocal = Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -289,7 +289,7 @@ public class Span2ConverterTest { .duration(207000L) .build(); - Span local = Span.builder() + zipkin.Span local = zipkin.Span.builder() .traceId(1L) .parentId(1L) .id(2L) @@ -297,14 +297,14 @@ public class Span2ConverterTest { .timestamp(1472470996199000L).duration(207000L) .addBinaryAnnotation(BinaryAnnotation.create(LOCAL_COMPONENT, "", frontend)).build(); - assertThat(Span2Converter.toSpan(simpleLocal)) + assertThat(V2SpanConverter.toSpan(simpleLocal)) .isEqualTo(local); - assertThat(Span2Converter.fromSpan(local)) + assertThat(V2SpanConverter.fromSpan(local)) .containsExactly(simpleLocal); } @Test public void clientAndServer() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -326,14 +326,14 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, backend)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("get"); // the client side owns timestamp and duration - Span2 client = builder.clone() + Span client = builder.clone() .kind(Kind.CLIENT) .localEndpoint(frontend) .remoteEndpoint(backend) @@ -346,7 +346,7 @@ public class Span2ConverterTest { .build(); // notice server tags are different than the client, and the client's annotations aren't here - Span2 server = builder.clone() + Span server = builder.clone() .kind(Kind.SERVER) .shared(true) .localEndpoint(backend) @@ -357,7 +357,7 @@ public class Span2ConverterTest { .putTag("srv/finagle.version", "6.44.0") .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(client, server); } @@ -366,7 +366,7 @@ public class Span2ConverterTest { * a signal */ @Test public void assumesServerWithoutTimestampIsShared() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -376,7 +376,7 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996350000L, Constants.SERVER_SEND, backend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -388,12 +388,12 @@ public class Span2ConverterTest { .duration(100000L) .build(); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void clientAndServer_loopback() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -407,20 +407,20 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996406000L, Constants.CLIENT_RECV, frontend)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("get"); - Span2 client = builder.clone() + Span client = builder.clone() .kind(Kind.CLIENT) .localEndpoint(frontend) .timestamp(1472470996199000L) .duration(207000L) .build(); - Span2 server = builder.clone() + Span server = builder.clone() .kind(Kind.SERVER) .shared(true) .localEndpoint(frontend) @@ -428,12 +428,12 @@ public class Span2ConverterTest { .duration(100000L) .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(client, server); } @Test public void oneway_loopback() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -443,31 +443,31 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996250000L, Constants.SERVER_RECV, frontend)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("get"); - Span2 client = builder.clone() + Span client = builder.clone() .kind(Kind.CLIENT) .localEndpoint(frontend) .timestamp(1472470996199000L) .build(); - Span2 server = builder.clone() + Span server = builder.clone() .kind(Kind.SERVER) .shared(true) .localEndpoint(frontend) .timestamp(1472470996250000L) .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(client, server); } @Test public void producer() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -476,7 +476,7 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996199000L, Constants.MESSAGE_SEND, frontend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -486,12 +486,12 @@ public class Span2ConverterTest { .timestamp(1472470996199000L) .build(); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void producer_remote() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -502,7 +502,7 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.MESSAGE_ADDR, kafka)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -513,14 +513,14 @@ public class Span2ConverterTest { .remoteEndpoint(kafka) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void producer_duration() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -532,7 +532,7 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996250000L, Constants.WIRE_SEND, frontend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -543,14 +543,14 @@ public class Span2ConverterTest { .duration(51000L) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void consumer() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -560,7 +560,7 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996199000L, Constants.MESSAGE_RECV, frontend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -570,14 +570,14 @@ public class Span2ConverterTest { .timestamp(1472470996199000L) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void consumer_remote() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -588,7 +588,7 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.MESSAGE_ADDR, kafka)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -599,14 +599,14 @@ public class Span2ConverterTest { .timestamp(1472470996199000L) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } @Test public void consumer_duration() { - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -618,7 +618,7 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996250000L, Constants.MESSAGE_RECV, frontend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") @@ -629,15 +629,15 @@ public class Span2ConverterTest { .duration(51000L) .build(); - assertThat(Span2Converter.toSpan(span2)) + assertThat(V2SpanConverter.toSpan(span2)) .isEqualTo(span); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } /** shared span IDs for messaging spans isn't supported, but shouldn't break */ @Test public void producerAndConsumer() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -650,13 +650,13 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.address(Constants.MESSAGE_ADDR, kafka)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("whatev"); - Span2 producer = builder.clone() + Span producer = builder.clone() .kind(Kind.PRODUCER) .localEndpoint(frontend) .remoteEndpoint(kafka) @@ -664,7 +664,7 @@ public class Span2ConverterTest { .duration(1472470996238000L - 1472470996199000L) .build(); - Span2 consumer = builder.clone() + Span consumer = builder.clone() .kind(Kind.CONSUMER) .shared(true) .localEndpoint(backend) @@ -673,13 +673,13 @@ public class Span2ConverterTest { .duration(1472470996406000L - 1472470996403000L) .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(producer, consumer); } /** shared span IDs for messaging spans isn't supported, but shouldn't break */ @Test public void producerAndConsumer_loopback_shared() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a")) .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) @@ -691,20 +691,20 @@ public class Span2ConverterTest { .addAnnotation(Annotation.create(1472470996406000L, Constants.MESSAGE_RECV, frontend)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("message"); - Span2 producer = builder.clone() + Span producer = builder.clone() .kind(Kind.PRODUCER) .localEndpoint(frontend) .timestamp(1472470996199000L) .duration(1472470996238000L - 1472470996199000L) .build(); - Span2 consumer = builder.clone() + Span consumer = builder.clone() .kind(Kind.CONSUMER) .shared(true) .localEndpoint(frontend) @@ -712,12 +712,12 @@ public class Span2ConverterTest { .duration(1472470996406000L - 1472470996403000L) .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(producer, consumer); } @Test public void dataMissingEndpointGoesOnFirstSpan() { - Span shared = Span.builder() + zipkin.Span shared = zipkin.Span.builder() .traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9")) .id(Util.lowerHexToUnsignedLong("5b4185666d50f68b")) .name("missing") @@ -731,12 +731,12 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.create("missing", "", null)) .build(); - Span2.Builder builder = Span2.builder() + Span.Builder builder = Span.builder() .traceId("216a2aea45d08fc9") .id("5b4185666d50f68b") .name("missing"); - Span2 first = builder.clone() + Span first = builder.clone() .localEndpoint(frontend) .addAnnotation(1472470996199000L, "foo") .addAnnotation(1472470996238000L, "bar") @@ -745,14 +745,14 @@ public class Span2ConverterTest { .putTag("missing", "") .build(); - Span2 second = builder.clone() + Span second = builder.clone() .localEndpoint(backend) .addAnnotation(1472470996250000L, "baz") .addAnnotation(1472470996350000L, "qux") .putTag("baz", "qux") .build(); - assertThat(Span2Converter.fromSpan(shared)) + assertThat(V2SpanConverter.fromSpan(shared)) .containsExactly(first, second); } @@ -764,7 +764,7 @@ public class Span2ConverterTest { byte[] longBuffer = ByteBuffer.allocate(8).putLong(2147483700L).array(); byte[] doubleBuffer = ByteBuffer.allocate(8).putDouble(3.1415).array(); byte[] bytesBuffer = "any carnal pleasure".getBytes(Util.UTF_8); - Span span = Span.builder() + zipkin.Span span = zipkin.Span.builder() .traceId(1) .name("test") .id(2) @@ -776,7 +776,7 @@ public class Span2ConverterTest { .addBinaryAnnotation(BinaryAnnotation.create("bytes", bytesBuffer, Type.BYTES, frontend)) .build(); - Span2 span2 = Span2.builder() + Span span2 = Span.builder() .traceId(1) .name("test") .id(2) @@ -789,7 +789,7 @@ public class Span2ConverterTest { .putTag("bytes", "YW55IGNhcm5hbCBwbGVhc3VyZQ==") // from https://en.wikipedia.org/wiki/Base64 .build(); - assertThat(Span2Converter.fromSpan(span)) + assertThat(V2SpanConverter.fromSpan(span)) .containsExactly(span2); } } diff --git a/zipkin/src/test/java/zipkin/internal/Span2Test.java b/zipkin/src/test/java/zipkin/internal/v2/SpanTest.java similarity index 86% rename from zipkin/src/test/java/zipkin/internal/Span2Test.java rename to zipkin/src/test/java/zipkin/internal/v2/SpanTest.java index d5f844225af..af6e6187843 100644 --- a/zipkin/src/test/java/zipkin/internal/Span2Test.java +++ b/zipkin/src/test/java/zipkin/internal/v2/SpanTest.java @@ -11,23 +11,24 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package zipkin.internal; +package zipkin.internal.v2; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import okio.Buffer; import org.junit.Test; import zipkin.Annotation; +import zipkin.internal.Util; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.MapEntry.entry; import static zipkin.TestObjects.APP_ENDPOINT; -public class Span2Test { - Span2 base = Span2.builder().traceId(1L).id(1L).localEndpoint(APP_ENDPOINT).build(); +public class SpanTest { + Span base = Span.builder().traceId(1L).id(1L).localEndpoint(APP_ENDPOINT).build(); @Test public void traceIdString() { - Span2 with128BitId = Span2.builder() + Span with128BitId = Span.builder() .traceId(Util.lowerHexToUnsignedLong("48485a3953bb6124")) .id(1) .name("foo").build(); @@ -37,7 +38,7 @@ public class Span2Test { } @Test public void traceIdString_high() { - Span2 with128BitId = Span2.builder() + Span with128BitId = Span.builder() .traceId(Util.lowerHexToUnsignedLong("48485a3953bb6124")) .traceIdHigh(Util.lowerHexToUnsignedLong("463ac35c9f6413ad")) .id(1) @@ -49,7 +50,7 @@ public class Span2Test { @Test public void idString_traceIdHigh() { - Span2 with128BitId = Span2.builder() + Span with128BitId = Span.builder() .traceId(Util.lowerHexToUnsignedLong("48485a3953bb6124")) .traceIdHigh(Util.lowerHexToUnsignedLong("463ac35c9f6413ad")) .id(1) @@ -61,7 +62,7 @@ public void idString_traceIdHigh() { @Test public void idString_withParent() { - Span2 withParent = Span2.builder().name("foo").traceId(1).id(3).parentId(2L).build(); + Span withParent = Span.builder().name("foo").traceId(1).id(3).parentId(2L).build(); assertThat(withParent.idString()) .isEqualTo("0000000000000001.0000000000000003<:0000000000000002"); @@ -69,7 +70,7 @@ public void idString_withParent() { @Test public void idString_noParent() { - Span2 noParent = Span2.builder().name("foo").traceId(1).id(1).build(); + Span noParent = Span.builder().name("foo").traceId(1).id(1).build(); assertThat(noParent.idString()) .isEqualTo("0000000000000001.0000000000000001<:0000000000000001"); @@ -81,12 +82,12 @@ public void idString_noParent() { } @Test public void annotationsSortByTimestamp() { - Span2 span = base.toBuilder() + Span span = base.toBuilder() .addAnnotation(2L, "foo") .addAnnotation(1L, "foo") .build(); - // note: annotations don't also have endpoints, as it is implicit to Span2.localEndpoint + // note: annotations don't also have endpoints, as it is implicit to Span.localEndpoint assertThat(span.annotations()).containsExactly( Annotation.create(1L, "foo", null), Annotation.create(2L, "foo", null) @@ -94,7 +95,7 @@ public void idString_noParent() { } @Test public void putTagOverwritesValue() { - Span2 span = base.toBuilder() + Span span = base.toBuilder() .putTag("foo", "bar") .putTag("foo", "qux") .build(); @@ -105,11 +106,11 @@ public void idString_noParent() { } @Test public void clone_differentCollections() { - Span2.Builder builder = base.toBuilder() + Span.Builder builder = base.toBuilder() .addAnnotation(1L, "foo") .putTag("foo", "qux"); - Span2.Builder builder2 = builder.clone() + Span.Builder builder2 = builder.clone() .addAnnotation(2L, "foo") .putTag("foo", "bar"); @@ -129,7 +130,7 @@ public void idString_noParent() { /** Catches common error when zero is passed instead of null for a timestamp */ @Test public void coercesZeroTimestampsToNull() { - Span2 span = base.toBuilder() + Span span = base.toBuilder() .timestamp(0L) .duration(0L) .build(); @@ -150,7 +151,7 @@ public void idString_noParent() { @Test public void serialization() throws Exception { Buffer buffer = new Buffer(); - Span2 span = base.toBuilder() + Span span = base.toBuilder() .addAnnotation(1L, "foo") .build(); diff --git a/zipkin/src/test/java/zipkin/internal/v2/codec/Span2JsonAdaptersTest.java b/zipkin/src/test/java/zipkin/internal/v2/codec/SpanJsonAdaptersTest.java similarity index 95% rename from zipkin/src/test/java/zipkin/internal/v2/codec/Span2JsonAdaptersTest.java rename to zipkin/src/test/java/zipkin/internal/v2/codec/SpanJsonAdaptersTest.java index 40b3a7f4f21..8e54cfe38a2 100644 --- a/zipkin/src/test/java/zipkin/internal/v2/codec/Span2JsonAdaptersTest.java +++ b/zipkin/src/test/java/zipkin/internal/v2/codec/SpanJsonAdaptersTest.java @@ -24,13 +24,13 @@ import zipkin.Constants; import zipkin.Endpoint; import zipkin.TraceKeys; -import zipkin.internal.Span2; +import zipkin.internal.v2.Span; import zipkin.internal.Util; import static org.assertj.core.api.Assertions.assertThat; import static zipkin.internal.Util.UTF_8; -public class Span2JsonAdaptersTest { +public class SpanJsonAdaptersTest { Endpoint frontend = Endpoint.create("frontend", 127 << 24 | 1); Endpoint backend = Endpoint.builder() .serviceName("backend") @@ -38,12 +38,12 @@ public class Span2JsonAdaptersTest { .port(9000) .build(); - Span2 span = Span2.builder() + Span span = Span.builder() .traceId("7180c278b62e8f6a216a2aea45d08fc9") .parentId("6b221d5bc9e6496c") .id("5b4185666d50f68b") .name("get") - .kind(Span2.Kind.CLIENT) + .kind(Span.Kind.CLIENT) .localEndpoint(frontend) .remoteEndpoint(backend) .timestamp(1472470996199000L) @@ -93,7 +93,7 @@ public class Span2JsonAdaptersTest { */ @Test public void specialCharsInJson() throws IOException { // service name is surrounded by control characters - Span2 worstSpanInTheWorld = Span2.builder().traceId(1L).id(1L) + Span worstSpanInTheWorld = Span.builder().traceId(1L).id(1L) // name is terrible .name(new String(new char[] {'"', '\\', '\t', '\b', '\n', '\r', '\f'})) .localEndpoint(Endpoint.create(new String(new char[] {0, 'a', 1}), 0)) @@ -123,7 +123,7 @@ public class Span2JsonAdaptersTest { @Test public void niceErrorOnEmpty_inputSpans() throws IOException { thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Empty input reading List"); + thrown.expectMessage("Empty input reading List"); Decoder.JSON.decodeList(new byte[0]); } @@ -133,13 +133,13 @@ public class Span2JsonAdaptersTest { */ @Test public void niceErrorOnMalformed_inputSpans() throws IOException { thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Malformed reading List from "); + thrown.expectMessage("Malformed reading List from "); Decoder.JSON.decodeList(new byte[] {'h', 'e', 'l', 'l', 'o'}); } @Test public void spansRoundTrip() throws IOException { - List tenClientSpans = Collections.nCopies(10, span); + List tenClientSpans = Collections.nCopies(10, span); byte[] message = MessageEncoder.JSON_BYTES.encode( tenClientSpans.stream().map(Encoder.JSON::encode).collect(Collectors.toList()) @@ -150,7 +150,7 @@ public class Span2JsonAdaptersTest { } @Test public void writesTraceIdHighIntoTraceIdField() { - Span2 with128BitTraceId = Span2.builder() + Span with128BitTraceId = Span.builder() .traceIdHigh(Util.lowerHexToUnsignedLong("48485a3953bb6124")) .traceId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c")) .localEndpoint(frontend) @@ -215,7 +215,7 @@ public class Span2JsonAdaptersTest { @Test public void niceErrorOnIncomplete_endpoint() { thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Empty endpoint at $[0].localEndpoint reading List from json"); + thrown.expectMessage("Empty endpoint at $[0].localEndpoint reading List from json"); String json = "[{\n" + " \"traceId\": \"6b221d5bc9e6496c\",\n" @@ -365,7 +365,7 @@ public class Span2JsonAdaptersTest { .contains("{\"ipv4\":\"127.0.0.1\"}"); } - static byte[] encodeList(Span2 ... spans) { + static byte[] encodeList(Span... spans) { return MessageEncoder.JSON_BYTES.encode( Arrays.stream(spans).map(Encoder.JSON::encode).collect(Collectors.toList()) );