Skip to content

Commit

Permalink
Changes v2 IP addresses to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Sep 2, 2017
1 parent 5bc51b1 commit f0b7a16
Show file tree
Hide file tree
Showing 48 changed files with 1,379 additions and 497 deletions.
18 changes: 9 additions & 9 deletions benchmarks/src/main/java/zipkin/benchmarks/CodecBenchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import zipkin.Codec;
import zipkin.Endpoint;
import zipkin.internal.v2.Span;
import zipkin.internal.v2.codec.MessageEncoder;
import zipkin.internal.v2.codec.Decoder;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesMessageEncoder;
import zipkin.internal.v2.codec.BytesDecoder;
import zipkin.internal.v2.codec.BytesEncoder;

/**
* This compares the speed of the bundled java codec with the approach used in the scala
Expand Down Expand Up @@ -158,19 +158,19 @@ public byte[] writeClientSpan_thrift_libthrift() throws TException {
return serialize(clientSpanLibThrift);
}

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())
static final Span span2 = BytesDecoder.JSON.decodeList(read("/span2.json")).get(0);
static final byte[] tenClientSpan2sJson = BytesMessageEncoder.JSON_TO_BYTES.encode(
Collections.nCopies(10, span2).stream().map(BytesEncoder.JSON::encode).collect(Collectors.toList())
);

@Benchmark
public List<Span> readTenClientSpans_json_span2() {
return Decoder.JSON.decodeList(tenClientSpan2sJson);
return BytesDecoder.JSON.decodeList(tenClientSpan2sJson);
}

@Benchmark
public byte[] writeClientSpan_json_span2() {
return Encoder.JSON.encode(span2);
return BytesEncoder.JSON.encode(span2);
}

static final byte[] rpcSpanJson = read("/span-rpc.json");
Expand Down Expand Up @@ -246,7 +246,7 @@ public byte[] writeRpcV6Span_thrift_libthrift() throws TException {
// Convenience main entry-point
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include("CodecBenchmarks.readTenClientSpans_json_span2")
.include(".*" + CodecBenchmarks.class.getSimpleName() + ".*ClientSpan.*")
.build();

new Runner(opt).run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import zipkin.internal.V2SpanConverter;
import zipkin.internal.Util;

import static zipkin.internal.V2SpanConverter.convert;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
@Fork(3)
Expand Down Expand Up @@ -88,15 +90,15 @@ public class Span2ConverterBenchmarks {
.addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, frontend))
.build();

Span server2 = Span.builder()
Span server2 = Span.newBuilder()
.traceId("7180c278b62e8f6a216a2aea45d08fc9")
.parentId("6b221d5bc9e6496c")
.id("5b4185666d50f68b")
.name("get")
.kind(Span.Kind.SERVER)
.shared(true)
.localEndpoint(backend)
.remoteEndpoint(frontend)
.localEndpoint(convert(backend))
.remoteEndpoint(convert(frontend))
.timestamp(1472470996250000L)
.duration(100000L)
.putTag(TraceKeys.HTTP_PATH, "/backend")
Expand Down
18 changes: 13 additions & 5 deletions benchmarks/src/main/java/zipkin/benchmarks/SpanBenchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import zipkin.Constants;
import zipkin.Endpoint;
import zipkin.TraceKeys;
import zipkin.internal.v2.Span;
import zipkin.internal.Util;
import zipkin.internal.v2.Span;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
Expand Down Expand Up @@ -79,7 +79,15 @@ public zipkin.Span buildLocalSpan() {
.ipv4(192 << 24 | 168 << 16 | 99 << 8 | 101)
.port(9000)
.build();

static final zipkin.internal.v2.Endpoint frontend2 = zipkin.internal.v2.Endpoint.newBuilder()
.serviceName("frontend")
.ip("127.0.0.1")
.build();
static final zipkin.internal.v2.Endpoint backend2 = zipkin.internal.v2.Endpoint.newBuilder()
.serviceName("backend")
.ip("192.168.99.101")
.port(9000)
.build();
@Benchmark
public zipkin.Span buildClientOnlySpan() {
return buildClientOnlySpan(zipkin.Span.builder());
Expand Down Expand Up @@ -110,7 +118,7 @@ public zipkin.Span buildClientOnlySpan_clear() {

@Benchmark
public Span buildClientOnlySpan2() {
return buildClientOnlySpan2(Span.builder());
return buildClientOnlySpan2(Span.newBuilder());
}

static Span buildClientOnlySpan2(Span.Builder builder) {
Expand All @@ -120,8 +128,8 @@ static Span buildClientOnlySpan2(Span.Builder builder) {
.id(spanIdHex)
.name("get")
.kind(Span.Kind.CLIENT)
.localEndpoint(frontend)
.remoteEndpoint(backend)
.localEndpoint(frontend2)
.remoteEndpoint(backend2)
.timestamp(1472470996199000L)
.duration(207000L)
.addAnnotation(1472470996238000L, Constants.WIRE_SEND)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/main/resources/span-client.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"traceId": "86154a4ba6e91385",
"traceId": "4d1e00c0db9010db86154a4ba6e91385",
"name": "get",
"id": "4d1e00c0db9010db",
"parentId": "86154a4ba6e91385",
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/src/main/resources/span2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{
"traceId": "86154a4ba6e91385",
"traceId": "4d1e00c0db9010db86154a4ba6e91385",
"parentId": "86154a4ba6e91385",
"id": "4d1e00c0db9010db",
"kind": "CLIENT",
Expand All @@ -8,7 +8,7 @@
"duration": 207000,
"localEndpoint": {
"serviceName": "frontend",
"ipv4": "127.0.0.1"
"ipv6": "7::0.128.128.127"
},
"remoteEndpoint": {
"serviceName": "backend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import zipkin.collector.kafka.KafkaCollector.Builder;
import zipkin.internal.ApplyTimestampAndDuration;
import zipkin.internal.V2SpanConverter;
import zipkin.internal.v2.codec.MessageEncoder;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesMessageEncoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.storage.AsyncSpanConsumer;
import zipkin.storage.AsyncSpanStore;
import zipkin.storage.SpanStore;
Expand Down Expand Up @@ -147,9 +147,9 @@ public void messageWithMultipleSpans_json2() throws Exception {
ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1])
);

byte[] message = MessageEncoder.JSON_BYTES.encode(asList(
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
byte[] message = BytesMessageEncoder.JSON_TO_BYTES.encode(asList(
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
));

producer.send(new KeyedMessage<>(builder.topic, message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import zipkin.collector.kafka10.KafkaCollector.Builder;
import zipkin.internal.ApplyTimestampAndDuration;
import zipkin.internal.V2SpanConverter;
import zipkin.internal.v2.codec.MessageEncoder;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesMessageEncoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.storage.AsyncSpanConsumer;
import zipkin.storage.AsyncSpanStore;
import zipkin.storage.SpanStore;
Expand Down Expand Up @@ -201,9 +201,9 @@ public void messageWithMultipleSpans_json2() throws Exception {
ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1])
);

byte[] message = MessageEncoder.JSON_BYTES.encode(asList(
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
byte[] message = BytesMessageEncoder.JSON_TO_BYTES.encode(asList(
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
));

produceSpans(message, builder.topic);
Expand Down
4 changes: 2 additions & 2 deletions zipkin-junit/src/main/java/zipkin/junit/ZipkinDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import zipkin.collector.CollectorMetrics;
import zipkin.internal.V2JsonSpanDecoder;
import zipkin.internal.V2StorageComponent;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.internal.v2.internal.Platform;
import zipkin.storage.Callback;
import zipkin.storage.QueryRequest;
Expand Down Expand Up @@ -157,7 +157,7 @@ static void writeTrace(ByteArrayOutputStream bout, List<zipkin.internal.v2.Span>
throws IOException {
bout.write('[');
for (int i = 0, length = trace.size(); i < length; ) {
bout.write(Encoder.JSON.encode(trace.get(i)));
bout.write(BytesEncoder.JSON.encode(trace.get(i)));
if (++i < length) bout.write(',');
}
bout.write(']');
Expand Down
10 changes: 5 additions & 5 deletions zipkin-junit/src/test/java/zipkin/junit/ZipkinRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import zipkin.Span;
import zipkin.internal.ApplyTimestampAndDuration;
import zipkin.internal.V2SpanConverter;
import zipkin.internal.v2.codec.MessageEncoder;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesMessageEncoder;
import zipkin.internal.v2.codec.BytesEncoder;

import static java.lang.String.format;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -69,9 +69,9 @@ public void getTraces_storedViaPostVersion2() throws IOException {
ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[1])
);

byte[] message = MessageEncoder.JSON_BYTES.encode(asList(
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
Encoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
byte[] message = BytesMessageEncoder.JSON_TO_BYTES.encode(asList(
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(0)).get(0)),
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(spans.get(1)).get(0))
));

// write the span to the zipkin using http api v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import okhttp3.RequestBody;
import okio.Buffer;
import zipkin.internal.v2.Span;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.internal.v2.storage.SpanConsumer;

/** Implements the span consumer interface by forwarding requests over http. */
Expand All @@ -36,7 +36,7 @@ final class HttpV2SpanConsumer implements SpanConsumer {
Buffer json = new Buffer();
json.writeByte('[');
for (int i = 0, length = spans.size(); i < length; ) {
json.write(Encoder.JSON.encode(spans.get(i)));
json.write(BytesEncoder.JSON.encode(spans.get(i)));
if (++i < length) json.writeByte(',');
}
json.writeByte(']');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import zipkin.DependencyLink;
import zipkin.internal.v2.Call;
import zipkin.internal.v2.Span;
import zipkin.internal.v2.codec.Decoder;
import zipkin.internal.v2.codec.BytesDecoder;
import zipkin.internal.v2.storage.QueryRequest;
import zipkin.internal.v2.storage.SpanStore;

Expand All @@ -46,13 +46,13 @@ final class HttpV2SpanStore implements SpanStore {
maybeAddQueryParam(url, "lookback", request.lookback());
maybeAddQueryParam(url, "limit", request.limit());
return factory.newCall(new Request.Builder().url(url.build()).build(),
content -> Decoder.JSON.decodeNestedList(content.readByteArray()));
content -> BytesDecoder.JSON.decodeNestedList(content.readByteArray()));
}

@Override public Call<List<Span>> getTrace(String traceId) {
return factory.newCall(new Request.Builder()
.url(factory.baseUrl.resolve("/api/v2/trace/" + Span.normalizeTraceId(traceId)))
.build(), content -> Decoder.JSON.decodeList(content.readByteArray()))
.build(), content -> BytesDecoder.JSON.decodeList(content.readByteArray()))
.handleError(((error, callback) -> {
if (error instanceof HttpException && ((HttpException) error).code == 404) {
callback.onSuccess(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import zipkin.internal.V2StorageComponent;
import zipkin.internal.v2.Call;
import zipkin.internal.v2.Span;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.internal.v2.storage.QueryRequest;
import zipkin.storage.StorageComponent;

Expand Down Expand Up @@ -132,7 +132,7 @@ public String getTraces(
buffer.writeByte('[');
List<Span> trace = traces.get(i);
for (int j = 0, jLength = trace.size(); j < jLength; ) {
buffer.write(Encoder.JSON.encode(trace.get(j)));
buffer.write(BytesEncoder.JSON.encode(trace.get(j)));
if (++j < jLength) buffer.writeByte(',');
}
buffer.writeByte(']');
Expand All @@ -151,7 +151,7 @@ public String getTrace(@PathVariable String traceIdHex, WebRequest request) thro
Buffer buffer = new Buffer();
buffer.writeByte('[');
for (int i = 0, length = trace.size(); i < length; ) {
buffer.write(Encoder.JSON.encode(trace.get(i)));
buffer.write(BytesEncoder.JSON.encode(trace.get(i)));
if (++i < length) buffer.writeByte(',');
}
buffer.writeByte(']');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import zipkin.internal.ApplyTimestampAndDuration;
import zipkin.internal.V2InMemoryStorage;
import zipkin.internal.V2SpanConverter;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.MessageEncoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.internal.v2.codec.BytesMessageEncoder;

import static java.lang.String.format;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -86,8 +86,8 @@ public void writeSpans_noContentTypeIsJson() throws Exception {
public void writeSpans_version2() throws Exception {
Span span = ApplyTimestampAndDuration.apply(LOTS_OF_SPANS[0]);

byte[] message = MessageEncoder.JSON_BYTES.encode(asList(
Encoder.JSON.encode(V2SpanConverter.fromSpan(span).get(0))
byte[] message = BytesMessageEncoder.JSON_TO_BYTES.encode(asList(
BytesEncoder.JSON.encode(V2SpanConverter.fromSpan(span).get(0))
));

performAsync(post("/api/v2/spans").content(message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import javax.annotation.Nullable;
import okio.Buffer;
import okio.ByteString;
import zipkin.Annotation;
import zipkin.internal.v2.Annotation;
import zipkin.internal.v2.Call;
import zipkin.internal.v2.Span;
import zipkin.internal.v2.codec.Encoder;
import zipkin.internal.v2.codec.BytesEncoder;
import zipkin.internal.v2.storage.SpanConsumer;
import zipkin.storage.elasticsearch.http.internal.client.HttpCall;

Expand Down Expand Up @@ -60,7 +60,7 @@ void indexSpans(BulkSpanIndexer indexer, List<Span> spans) {
// guessTimestamp is made for determining the span's authoritative timestamp. When choosing
// the index bucket, any annotation is better than using current time.
for (int i = 0, length = span.annotations().size(); i < length; i++) {
indexTimestamp = span.annotations().get(i).timestamp / 1000;
indexTimestamp = span.annotations().get(i).timestamp() / 1000;
break;
}
if (indexTimestamp == 0L) indexTimestamp = System.currentTimeMillis();
Expand Down Expand Up @@ -114,8 +114,8 @@ static byte[] prefixWithTimestampMillisAndQuery(Span span, @Nullable Long timest
writer.name("_q");
writer.beginArray();
for (Annotation a : span.annotations()) {
if (a.value.length() > 255) continue;
writer.value(a.value);
if (a.value().length() > 255) continue;
writer.value(a.value());
}
for (Map.Entry<String, String> tag : span.tags().entrySet()) {
if (tag.getKey().length() + tag.getValue().length() + 1 > 255) continue;
Expand All @@ -131,9 +131,9 @@ static byte[] prefixWithTimestampMillisAndQuery(Span span, @Nullable Long timest
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Error indexing query for span: " + span, e);
}
return Encoder.JSON.encode(span);
return BytesEncoder.JSON.encode(span);
}
byte[] document = Encoder.JSON.encode(span);
byte[] document = BytesEncoder.JSON.encode(span);
if (query.rangeEquals(0L, ByteString.of(new byte[] {'{', '}'}))) {
return document;
}
Expand Down
Loading

0 comments on commit f0b7a16

Please sign in to comment.