Merge pull request #220 from spring-cloud/zipkin-0.9
Updates to zipkin 0.9
This commit is contained in:
@@ -14,10 +14,9 @@
|
||||
<name>spring-cloud-sleuth-dependencies</name>
|
||||
<description>Spring Cloud Sleuth Dependencies</description>
|
||||
<properties>
|
||||
<brave.version>3.4.0</brave.version>
|
||||
<spring-cloud-netflix.version>1.1.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<aspectj.version>1.8.4</aspectj.version>
|
||||
<zipkin-java.version>0.7.0</zipkin-java.version>
|
||||
<zipkin-java.version>0.9.1</zipkin-java.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -58,11 +57,6 @@
|
||||
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kristofa</groupId>
|
||||
<artifactId>brave-core</artifactId>
|
||||
<version>${brave.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
|
||||
@@ -62,12 +62,12 @@
|
||||
<dependency>
|
||||
<groupId>io.zipkin.java</groupId>
|
||||
<artifactId>zipkin</artifactId>
|
||||
<version>0.7.0</version>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.zipkin.java</groupId>
|
||||
<artifactId>zipkin-server</artifactId>
|
||||
<version>0.7.0</version>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
mysql:
|
||||
image: openzipkin/zipkin-mysql:1.36.0
|
||||
image: openzipkin/zipkin-mysql:1.38.0
|
||||
ports:
|
||||
- 3306:3306
|
||||
query:
|
||||
image: openzipkin/zipkin-java:0.7.0
|
||||
image: openzipkin/zipkin-java:0.9.1
|
||||
environment:
|
||||
# Remove TRANSPORT_TYPE to disable tracing
|
||||
- TRANSPORT_TYPE=http
|
||||
- STORAGE_TYPE=mysql
|
||||
# - JAVA_OPTS=your jvm params here
|
||||
expose:
|
||||
- 9411
|
||||
ports:
|
||||
# Historical port used for the Zipkin HTTP Api
|
||||
- 9411:9411
|
||||
# Zipkin UI used to be on a separate process listening on port 8080
|
||||
- 8080:9411
|
||||
links:
|
||||
- mysql:storage
|
||||
web:
|
||||
image: openzipkin/zipkin-web:1.36.0
|
||||
environment:
|
||||
# Remove TRANSPORT_TYPE to disable tracing
|
||||
- TRANSPORT_TYPE=http
|
||||
ports:
|
||||
- 8080:8080
|
||||
- 9990:9990
|
||||
links:
|
||||
- query
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.util.StringUtils;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Constants;
|
||||
import zipkin.Endpoint;
|
||||
import zipkin.Sampler;
|
||||
import zipkin.Span.Builder;
|
||||
|
||||
/**
|
||||
@@ -40,62 +38,26 @@ import zipkin.Span.Builder;
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
final class ConvertToZipkinSpanList {
|
||||
private static final List<String> ZIPKIN_START_EVENTS = Arrays.asList(
|
||||
Constants.CLIENT_RECV, Constants.SERVER_RECV
|
||||
);
|
||||
|
||||
private static final Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(SamplingZipkinSpanIterator.class);
|
||||
.getLog(ConvertToZipkinSpanList.class);
|
||||
|
||||
private final Sampler sampler;
|
||||
private final Iterator<Span> delegate;
|
||||
private final Host host;
|
||||
private zipkin.Span peeked;
|
||||
|
||||
SamplingZipkinSpanIterator(Sampler sampler, Spans input) {
|
||||
this.sampler = sampler;
|
||||
this.delegate = input.getSpans().iterator();
|
||||
this.host = input.getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (this.peeked == null && this.delegate.hasNext()) {
|
||||
this.peeked = convertAndSample(this.delegate.next(), this.host);
|
||||
}
|
||||
return this.peeked != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public zipkin.Span next() {
|
||||
// implicitly peeks
|
||||
if (!hasNext())
|
||||
throw new NoSuchElementException();
|
||||
zipkin.Span result = this.peeked;
|
||||
this.peeked = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("remove");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a converted span or null if it is invalid or unsampled.
|
||||
*/
|
||||
zipkin.Span convertAndSample(Span input, Host host) {
|
||||
if (!input.getName().equals("message:" + SleuthSink.INPUT)) {
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(input, host);
|
||||
if (this.sampler.isSampled(result.traceId)) {
|
||||
return result;
|
||||
static List<zipkin.Span> convert(Spans input) {
|
||||
Host host = input.getHost();
|
||||
List<zipkin.Span> result = new ArrayList<>(input.getSpans().size());
|
||||
for (Span span : input.getSpans()) {
|
||||
if (!span.getName().equals("message:" + SleuthSink.INPUT)) {
|
||||
result.add(convert(span, host));
|
||||
}
|
||||
else {
|
||||
log.warn("Message tracing cycle detected for: " + input);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.warn("Message tracing cycle detected for: " + input);
|
||||
}
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,8 +94,7 @@ final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
zipkinSpan.traceId(span.getTraceId());
|
||||
if (span.getParents().size() > 0) {
|
||||
if (span.getParents().size() > 1) {
|
||||
SamplingZipkinSpanIterator.log
|
||||
.debug("zipkin doesn't support spans with multiple parents. Omitting "
|
||||
log.debug("zipkin doesn't support spans with multiple parents. Omitting "
|
||||
+ "other parents for " + span);
|
||||
}
|
||||
zipkinSpan.parentId(span.getParents().get(0));
|
||||
@@ -2,7 +2,7 @@ package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -37,7 +37,9 @@ import zipkin.BinaryAnnotation;
|
||||
import zipkin.BinaryAnnotation.Type;
|
||||
import zipkin.Endpoint;
|
||||
import zipkin.Sampler;
|
||||
import zipkin.SamplingSpanStoreConsumer;
|
||||
import zipkin.Span.Builder;
|
||||
import zipkin.SpanConsumer;
|
||||
import zipkin.SpanStore;
|
||||
|
||||
/**
|
||||
@@ -57,19 +59,17 @@ public class ZipkinMessageListener {
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(ZipkinMessageListener.class);
|
||||
static final String UNKNOWN_PROCESS_ID = "unknown";
|
||||
final SpanConsumer consumer;
|
||||
|
||||
@Autowired
|
||||
SpanStore spanStore;
|
||||
|
||||
@Autowired
|
||||
Sampler sampler;
|
||||
ZipkinMessageListener(SpanStore spanStore, Sampler sampler) {
|
||||
this.consumer = SamplingSpanStoreConsumer.create(sampler, spanStore);
|
||||
}
|
||||
|
||||
@ServiceActivator(inputChannel = SleuthSink.INPUT)
|
||||
public void sink(Spans input) {
|
||||
Iterator<zipkin.Span> sampled = new SamplingZipkinSpanIterator(this.sampler, input);
|
||||
if (sampled.hasNext()) {
|
||||
this.spanStore.accept(sampled);
|
||||
}
|
||||
List<zipkin.Span> converted = ConvertToZipkinSpanList.convert(input);
|
||||
this.consumer.accept(converted);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,9 +17,8 @@ package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -27,11 +26,10 @@ import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
|
||||
import zipkin.Constants;
|
||||
import zipkin.Sampler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SamplingZipkinSpanIteratorTests {
|
||||
public class ConvertToZipkinSpanListTests {
|
||||
|
||||
Host host = new Host("myservice", "1.2.3.4", 8080);
|
||||
|
||||
@@ -40,8 +38,7 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
Spans spans = new Spans(this.host,
|
||||
Collections.singletonList(span("sleuth")));
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(
|
||||
Sampler.create(1.0f), spans);
|
||||
List<zipkin.Span> result = ConvertToZipkinSpanList.convert(spans);
|
||||
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
@@ -51,39 +48,17 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
Spans spans = new Spans(this.host,
|
||||
Arrays.asList(span("foo"), span("bar"), span("baz")));
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(
|
||||
Sampler.create(1.0f), spans);
|
||||
List<zipkin.Span> result = ConvertToZipkinSpanList.convert(spans);
|
||||
|
||||
assertThat(result).extracting(s -> s.name).containsExactly(
|
||||
"message:foo", "message:bar", "message:baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainsOnlySampledSpans() {
|
||||
Spans spans = new Spans(this.host,
|
||||
Arrays.asList(span("foo"), span("bar"), span("baz")));
|
||||
|
||||
Sampler everyOtherSampler = new Sampler() {
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
public boolean isSampled(long l) {
|
||||
return counter.getAndIncrement() % 2 == 0;
|
||||
}
|
||||
};
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(everyOtherSampler,
|
||||
spans);
|
||||
|
||||
assertThat(result).extracting(s -> s.name).containsExactly(
|
||||
"message:foo", "message:baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendsLocalComponentTagIfNoZipkinLogIsPresent() {
|
||||
Spans spans = new Spans(this.host, Collections.singletonList(span("foo")));
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(
|
||||
Sampler.create(1.0f), spans);
|
||||
List<zipkin.Span> result = ConvertToZipkinSpanList.convert(spans);
|
||||
|
||||
assertThat(result)
|
||||
.flatExtracting(s -> s.binaryAnnotations)
|
||||
@@ -97,8 +72,7 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
span.logEvent(Constants.CLIENT_SEND);
|
||||
Spans spans = new Spans(this.host, Collections.singletonList(span));
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(
|
||||
Sampler.create(1.0f), spans);
|
||||
List<zipkin.Span> result = ConvertToZipkinSpanList.convert(spans);
|
||||
|
||||
assertThat(result)
|
||||
.hasSize(1)
|
||||
@@ -115,8 +89,7 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
span.tag(Span.SPAN_PEER_SERVICE_TAG_NAME, "barservice");
|
||||
Spans spans = new Spans(this.host, Collections.singletonList(span));
|
||||
|
||||
Iterator<zipkin.Span> result = new SamplingZipkinSpanIterator(
|
||||
Sampler.create(1.0f), spans);
|
||||
List<zipkin.Span> result = ConvertToZipkinSpanList.convert(spans);
|
||||
|
||||
assertThat(result)
|
||||
.hasSize(1)
|
||||
@@ -38,7 +38,7 @@ public class ZipkinMessageListenerTests {
|
||||
long start = System.currentTimeMillis();
|
||||
this.span.logEvent("hystrix/retry"); // System.currentTimeMillis
|
||||
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(this.span, this.host);
|
||||
zipkin.Span result = ConvertToZipkinSpanList.convert(this.span, this.host);
|
||||
|
||||
assertThat(result.timestamp)
|
||||
.isEqualTo(this.span.getBegin() * 1000);
|
||||
@@ -55,7 +55,7 @@ public class ZipkinMessageListenerTests {
|
||||
this.span.logEvent("hystrix/retry");
|
||||
this.span.tag("spring-boot/version", "1.3.1.RELEASE");
|
||||
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(this.span, this.host);
|
||||
zipkin.Span result = ConvertToZipkinSpanList.convert(this.span, this.host);
|
||||
|
||||
assertThat(result.annotations.get(0).endpoint)
|
||||
.isEqualTo(this.endpoint);
|
||||
@@ -70,7 +70,7 @@ public class ZipkinMessageListenerTests {
|
||||
*/
|
||||
@Test
|
||||
public void spanWithoutAnnotationsLogsComponent() {
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(this.span, this.host);
|
||||
zipkin.Span result = ConvertToZipkinSpanList.convert(this.span, this.host);
|
||||
|
||||
assertThat(result.binaryAnnotations).hasSize(1);
|
||||
assertThat(result.binaryAnnotations.get(0)).isEqualToComparingFieldByField(
|
||||
@@ -82,7 +82,7 @@ public class ZipkinMessageListenerTests {
|
||||
public void nullProcessIdCoercesToUnknownServiceName() {
|
||||
Span noProcessId = Span.builder().traceId(1L).name("http:parent").remote(true).build();
|
||||
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(noProcessId, this.host);
|
||||
zipkin.Span result = ConvertToZipkinSpanList.convert(noProcessId, this.host);
|
||||
|
||||
assertThat(result.binaryAnnotations)
|
||||
.containsOnly(BinaryAnnotation.create("lc", "unknown", this.endpoint));
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
mysql:
|
||||
image: openzipkin/zipkin-mysql:1.36.0
|
||||
image: openzipkin/zipkin-mysql:1.38.0
|
||||
ports:
|
||||
- 3306:3306
|
||||
query:
|
||||
image: openzipkin/zipkin-java:0.7.0
|
||||
image: openzipkin/zipkin-java:0.9.1
|
||||
environment:
|
||||
# Remove TRANSPORT_TYPE to disable tracing
|
||||
- TRANSPORT_TYPE=http
|
||||
- STORAGE_TYPE=mysql
|
||||
# - JAVA_OPTS=your jvm params here
|
||||
expose:
|
||||
- 9411
|
||||
ports:
|
||||
# Historical port used for the Zipkin HTTP Api
|
||||
- 9411:9411
|
||||
# Zipkin UI used to be on a separate process listening on port 8080
|
||||
- 8080:9411
|
||||
links:
|
||||
- mysql:storage
|
||||
web:
|
||||
image: openzipkin/zipkin-web:1.36.0
|
||||
environment:
|
||||
# Remove TRANSPORT_TYPE to disable tracing
|
||||
- TRANSPORT_TYPE=http
|
||||
ports:
|
||||
- 8080:8080
|
||||
- 9990:9990
|
||||
links:
|
||||
- query
|
||||
|
||||
Reference in New Issue
Block a user