Skip to content
Merged
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: 4 additions & 2 deletions spring-cloud-sleuth-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<name>spring-cloud-sleuth-dependencies</name>
<description>Spring Cloud Sleuth Dependencies</description>
<properties>
<zipkin.version>2.2.1</zipkin.version>
<!-- misaligned intentionally https://github.com/spring-projects/spring-boot/issues/10778-->
<zipkin.version>2.2.0</zipkin.version>
<zipkin2.version>2.2.1</zipkin2.version>
<zipkin-reporter.version>1.1.2</zipkin-reporter.version>
<zipkin-reporter2.version>2.1.3</zipkin-reporter2.version>
</properties>
Expand Down Expand Up @@ -73,7 +75,7 @@
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>${zipkin.version}</version>
<version>${zipkin2.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
Expand Down
10 changes: 0 additions & 10 deletions spring-cloud-sleuth-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@
<artifactId>spring-cloud-sleuth-sample-test-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;

import zipkin.Span;
import zipkin2.Span;
import zipkin2.reporter.Reporter;

/**
* @author Spencer Gibb
Expand All @@ -43,8 +43,8 @@ public static void main(String[] args) {
// Use this for debugging (or if there is no Zipkin server running on port 9411)
@Bean
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
public ZipkinSpanReporter spanCollector() {
return new ZipkinSpanReporter() {
public Reporter<Span> spanReporter() {
return new Reporter<Span>() {
@Override
public void report(Span span) {
logger.info(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import java.util.List;

import org.apache.commons.logging.Log;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;

import zipkin.Span;
import zipkin2.Span;
import zipkin2.reporter.Reporter;

/**
* Span Collector that logs spans and adds Spans to a list
*
* @author Marcin Grzejszczak
*/
public class IntegrationTestZipkinSpanReporter implements ZipkinSpanReporter {
public class IntegrationTestZipkinSpanReporter implements Reporter<Span> {

private static final Log log = org.apache.commons.logging.LogFactory
.getLog(IntegrationTestZipkinSpanReporter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package integration;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Random;
Expand All @@ -27,7 +25,6 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -37,8 +34,8 @@
import integration.MessagingApplicationTests.IntegrationSpanCollectorConfig;
import sample.SampleMessagingApplication;
import tools.AbstractIntegrationTest;
import zipkin.Constants;
import zipkin.Span;
import zipkin2.Span;
import zipkin2.reporter.Reporter;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.BDDAssertions.then;
Expand Down Expand Up @@ -81,7 +78,7 @@ public void should_have_passed_trace_id_and_generate_new_span_id_when_message_is
httpMessageWithTraceIdInHeadersIsSuccessfullySent(sampleAppUrl + "/", traceId, spanId).run()
);

await().atMost(5, SECONDS).untilAsserted(() -> {
await().atMost(10, SECONDS).untilAsserted(() -> {
thenAllSpansHaveTraceIdEqualTo(traceId);
thenTheSpansHaveProperParentStructure();
});
Expand All @@ -97,64 +94,63 @@ public void should_have_passed_trace_id_with_annotations_in_async_thread_when_me

await().atMost(5, SECONDS).untilAsserted(() -> {
thenAllSpansHaveTraceIdEqualTo(traceId);
thenThereIsAtLeastOneBinaryAnnotationWithKey("background-sleep-millis");
thenThereIsAtLeastOneTagWithKey("background-sleep-millis");
});
}

private void thenThereIsAtLeastOneBinaryAnnotationWithKey(String binaryAnnotationKey) {
private void thenThereIsAtLeastOneTagWithKey(String key) {
then(this.integrationTestSpanCollector.hashedSpans.stream()
.map(s -> s.binaryAnnotations)
.flatMap(Collection::stream)
.anyMatch(b -> b.key.equals(binaryAnnotationKey))).isTrue();
.map(Span::tags)
.flatMap(m -> m.keySet().stream())
.anyMatch(b -> b.equals(key))).isTrue();
}

private void thenAllSpansHaveTraceIdEqualTo(long traceId) {
String traceIdHex = Long.toHexString(traceId);
then(this.integrationTestSpanCollector.hashedSpans.stream()
.allMatch(span -> span.traceId == traceId)).describedAs("All spans have same trace id").isTrue();
.allMatch(span -> span.traceId().equals(traceIdHex))).describedAs("All spans have same trace id").isTrue();
}

private void thenTheSpansHaveProperParentStructure() {
Optional<Span> firstHttpSpan = findFirstHttpRequestSpan();
List<Span> eventSpans = findAllEventRelatedSpans();
Optional<Span> eventSentSpan = findSpanWithAnnotation(Constants.SERVER_SEND);
Optional<Span> eventReceivedSpan = findSpanWithAnnotation(Constants.CLIENT_RECV);
Optional<Span> eventSentSpan = findSpanWithKind(Span.Kind.SERVER);
Optional<Span> eventReceivedSpan = findSpanWithKind(Span.Kind.CLIENT);
Optional<Span> lastHttpSpansParent = findLastHttpSpansParent();
// "http:/parent/" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS)
Collections.sort(this.integrationTestSpanCollector.hashedSpans);
thenAllSpansArePresent(firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan);
then(this.integrationTestSpanCollector.hashedSpans).as("There were 4 spans").hasSize(4);
log.info("Checking the parent child structure");
List<Optional<Span>> parentChild = this.integrationTestSpanCollector.hashedSpans.stream()
.filter(span -> span.parentId != null)
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id == span.parentId).findAny()
.filter(span -> span.parentId() != null)
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id().equals(span.parentId())).findAny()
).collect(Collectors.toList());
log.info("List of parents and children " + parentChild);
then(parentChild.stream().allMatch(Optional::isPresent)).isTrue();
}

private Optional<Span> findLastHttpSpansParent() {
return this.integrationTestSpanCollector.hashedSpans.stream()
.filter(span -> "http:/foo".equals(span.name) && !span.annotations.isEmpty()).findFirst();
.filter(span -> "http:/foo".equals(span.name()) && span.kind() != null).findFirst();
}

private Optional<Span> findSpanWithAnnotation(String annotationName) {
private Optional<Span> findSpanWithKind(Span.Kind kind) {
return this.integrationTestSpanCollector.hashedSpans.stream()
.filter(span -> span.annotations.stream().filter(annotation -> annotationName
.equals(annotation.value)).findFirst().isPresent())
.filter(span -> kind.equals(span.kind()))
.findFirst();
}

private List<Span> findAllEventRelatedSpans() {
return this.integrationTestSpanCollector.hashedSpans.stream()
.filter(span -> "message:messages".equals(span.name) && span.parentId != null).collect(
.filter(span -> "message:messages".equals(span.name()) && span.parentId() != null).collect(
Collectors.toList());
}

private Optional<Span> findFirstHttpRequestSpan() {
return this.integrationTestSpanCollector.hashedSpans.stream()
// home is the name of the method
.filter(span -> span.binaryAnnotations.stream()
.anyMatch(binaryAnnotation -> new String(binaryAnnotation.value).equals("home"))).findFirst();
.filter(span -> span.tags().values().stream()
.anyMatch("home"::equals)).findFirst();
}

private void thenAllSpansArePresent(Optional<Span> firstHttpSpan,
Expand All @@ -178,9 +174,8 @@ private void thenAllSpansArePresent(Optional<Span> firstHttpSpan,
@Configuration
public static class IntegrationSpanCollectorConfig {
@Bean
ZipkinSpanReporter integrationTestZipkinSpanReporter() {
Reporter<Span> integrationTestZipkinSpanReporter() {
return new IntegrationTestZipkinSpanReporter();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;

import zipkin.Span;
import zipkin2.Span;
import zipkin2.reporter.Reporter;

/**
* @author Spencer Gibb
Expand All @@ -51,8 +51,8 @@ public RestTemplate restTemplate() {
// Use this for debugging (or if there is no Zipkin server running on port 9411)
@Bean
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
public ZipkinSpanReporter spanCollector() {
return new ZipkinSpanReporter() {
public Reporter<Span> spanReporter() {
return new Reporter<Span>() {
@Override
public void report(Span span) {
logger.info(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
</dependency>
</dependencies>
Expand Down
Loading