Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Changed binary annotations type from binary to string #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions htrace-zipkin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ language governing permissions and limitations under the License. -->
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-collector-scribe</artifactId>
<version>1.19.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.htrace.core.TimelineAnnotation;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -153,13 +154,9 @@ private List<BinaryAnnotation> createZipkinBinaryAnnotations(org.apache.htrace.c
List<BinaryAnnotation> l = new ArrayList<BinaryAnnotation>();
for (Map.Entry<String, String> e : span.getKVAnnotations().entrySet()) {
BinaryAnnotation binaryAnn = new BinaryAnnotation();
binaryAnn.setAnnotation_type(AnnotationType.BYTES);
binaryAnn.setAnnotation_type(AnnotationType.STRING);
binaryAnn.setKey(e.getKey());
try {
binaryAnn.setValue(e.getValue().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
LOG.error("Error encoding string as UTF-8", ex);
}
binaryAnn.setValue(e.getValue().getBytes(StandardCharsets.UTF_8));
binaryAnn.setHost(ep);
l.add(binaryAnn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import scala.collection.JavaConversions;
import scala.collection.mutable.Buffer;

public class ITZipkinReceiver {
public class ITZipkinReceiverTest {

@Test
public void testKafkaTransport() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.htrace.zipkin;

import org.apache.htrace.Transport;
import org.apache.htrace.core.*;
import org.apache.htrace.impl.ScribeTransport;
import org.apache.htrace.impl.ZipkinSpanReceiver;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import zipkin.BinaryAnnotation;
import zipkin.collector.CollectorMetrics;
import zipkin.collector.scribe.ScribeCollector;
import zipkin.storage.InMemoryStorage;
import zipkin.storage.QueryRequest;

import java.util.List;

public class ScribeThriftSenderTest {

InMemoryStorage storage = new InMemoryStorage();
ScribeCollector collector;

@Before
public void start() {
collector = ScribeCollector.builder()
.metrics(CollectorMetrics.NOOP_METRICS)
.storage(storage).build();
collector.start();
}

@After
public void close() {
collector.close();
}

ScribeTransport sender = new ScribeTransport();

private Tracer newTracer(final Transport transport) {
TracerPool pool = new TracerPool("newTracer");
pool.addReceiver(new ZipkinSpanReceiver(HTraceConfiguration.EMPTY) {
@Override
protected Transport createTransport(HTraceConfiguration conf) {
return transport;
}
});
return new Tracer.Builder("ZipkinTracer").
tracerPool(pool).
conf(HTraceConfiguration.fromKeyValuePairs(
"sampler.classes", AlwaysSampler.class.getName()
)).
build();
}

@Test
public void testBinaryAnnotationsType() throws Exception {
Tracer t = newTracer(sender);
TraceScope s = t.newScope("root");
String originalValue = "bar";
s.addKVAnnotation("foo", originalValue);
s.close();
t.close();
List<List<zipkin.Span>> spans = storage.spanStore().getTraces(QueryRequest.builder().build());
Assert.assertEquals(spans.listIterator().next().get(0).binaryAnnotations.get(0).type, BinaryAnnotation.Type.STRING);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

package org.apache.htrace.zipkin;

import com.twitter.zipkin.gen.AnnotationType;
import com.twitter.zipkin.gen.BinaryAnnotation;
import com.twitter.zipkin.gen.zipkinCoreConstants;

import org.apache.htrace.core.HTraceConfiguration;
import org.apache.htrace.core.MilliSpan;
import org.apache.htrace.core.POJOSpanReceiver;
import org.apache.htrace.core.Span;
import org.apache.htrace.core.SpanId;
import org.apache.thrift.TException;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.util.Collection;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -110,6 +110,25 @@ public void testHTraceAnnotationTimestamp() throws IOException, InterruptedExcep
}
}

@Test
public void testKVSerializesAsUTF8String() throws IOException, TException {
Span span = new MilliSpan.Builder().
description("root").
spanId(new SpanId(100, 100)).
tracerId("test").
begin(1).
build();
span.addKVAnnotation("http.path", "/foo/⻩");

com.twitter.zipkin.gen.Span zs =
new HTraceToZipkinConverter(127<<24|1, (short) 80).convert(span);

Assert.assertEquals(1, zs.getBinary_annotations().size());
BinaryAnnotation path = zs.getBinary_annotations().get(0);
Assert.assertEquals(AnnotationType.STRING, path.getAnnotation_type());
Assert.assertEquals("/foo/⻩", new String(path.getValue(), UTF_8));
}

@Test
public void testHTraceDefaultPort() throws IOException {
MilliSpan ms = new MilliSpan.Builder().description("test").
Expand Down