Skip to content

Commit f7ecadf

Browse files
author
Adrian Cole
committed
Misaligns Zipkin v1 from sharing the same version number as v2
This does two things: ensures samples don't use Zipkin v1 in any way, and misaligns the version numbers of zipkin v1 and zipkin v2 apis. This is an attempt to walk around the gradle plugin issue, which only exists when someone is using both versions of zipkin. See spring-projects/spring-boot#10778
1 parent 08093b0 commit f7ecadf

File tree

17 files changed

+127
-240
lines changed

17 files changed

+127
-240
lines changed

spring-cloud-sleuth-dependencies/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<name>spring-cloud-sleuth-dependencies</name>
1515
<description>Spring Cloud Sleuth Dependencies</description>
1616
<properties>
17-
<zipkin.version>2.2.1</zipkin.version>
17+
<!-- misaligned intentionally https://github.com/spring-projects/spring-boot/issues/10778-->
18+
<zipkin.version>2.2.0</zipkin.version>
19+
<zipkin2.version>2.2.1</zipkin2.version>
1820
<zipkin-reporter.version>1.1.2</zipkin-reporter.version>
1921
<zipkin-reporter2.version>2.1.3</zipkin-reporter2.version>
2022
</properties>
@@ -73,7 +75,7 @@
7375
<dependency>
7476
<groupId>io.zipkin.zipkin2</groupId>
7577
<artifactId>zipkin</artifactId>
76-
<version>${zipkin.version}</version>
78+
<version>${zipkin2.version}</version>
7779
</dependency>
7880
<dependency>
7981
<groupId>io.zipkin.java</groupId>

spring-cloud-sleuth-samples/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,11 @@
5454
<artifactId>spring-cloud-sleuth-sample-test-core</artifactId>
5555
<version>${project.version}</version>
5656
</dependency>
57-
<dependency>
58-
<groupId>io.zipkin.java</groupId>
59-
<artifactId>zipkin</artifactId>
60-
<version>2.2.1</version>
61-
</dependency>
6257
<dependency>
6358
<groupId>io.zipkin.zipkin2</groupId>
6459
<artifactId>zipkin</artifactId>
6560
<version>2.2.1</version>
6661
</dependency>
67-
<dependency>
68-
<groupId>io.zipkin.java</groupId>
69-
<artifactId>zipkin-server</artifactId>
70-
<version>2.2.1</version>
71-
</dependency>
7262
</dependencies>
7363
</dependencyManagement>
7464

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</dependency>
6969
<dependency>
7070
<groupId>org.springframework.cloud</groupId>
71-
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
71+
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
7272
</dependency>
7373
<dependency>
7474
<groupId>org.springframework.boot</groupId>

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-feign/src/main/java/sample/SampleFeignApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2424
import org.springframework.cloud.netflix.feign.EnableFeignClients;
25-
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
2625
import org.springframework.context.annotation.Bean;
2726

28-
import zipkin.Span;
27+
import zipkin2.Span;
28+
import zipkin2.reporter.Reporter;
2929

3030
/**
3131
* @author Spencer Gibb
@@ -43,8 +43,8 @@ public static void main(String[] args) {
4343
// Use this for debugging (or if there is no Zipkin server running on port 9411)
4444
@Bean
4545
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
46-
public ZipkinSpanReporter spanCollector() {
47-
return new ZipkinSpanReporter() {
46+
public Reporter<Span> spanReporter() {
47+
return new Reporter<Span>() {
4848
@Override
4949
public void report(Span span) {
5050
logger.info(span);

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-messaging/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</dependency>
8383
<dependency>
8484
<groupId>org.springframework.cloud</groupId>
85-
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
85+
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
8686
</dependency>
8787
<dependency>
8888
<groupId>org.springframework.boot</groupId>

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-messaging/src/test/java/integration/IntegrationTestZipkinSpanReporter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
import java.util.List;
2121

2222
import org.apache.commons.logging.Log;
23-
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
2423

25-
import zipkin.Span;
24+
import zipkin2.Span;
25+
import zipkin2.reporter.Reporter;
2626

2727
/**
2828
* Span Collector that logs spans and adds Spans to a list
2929
*
3030
* @author Marcin Grzejszczak
3131
*/
32-
public class IntegrationTestZipkinSpanReporter implements ZipkinSpanReporter {
32+
public class IntegrationTestZipkinSpanReporter implements Reporter<Span> {
3333

3434
private static final Log log = org.apache.commons.logging.LogFactory
3535
.getLog(IntegrationTestZipkinSpanReporter.class);

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-messaging/src/test/java/integration/MessagingApplicationTests.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package integration;
1717

18-
import java.util.Collection;
19-
import java.util.Collections;
2018
import java.util.List;
2119
import java.util.Optional;
2220
import java.util.Random;
@@ -27,7 +25,6 @@
2725
import org.junit.runner.RunWith;
2826
import org.springframework.beans.factory.annotation.Autowired;
2927
import org.springframework.boot.test.context.SpringBootTest;
30-
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
3128
import org.springframework.context.annotation.Bean;
3229
import org.springframework.context.annotation.Configuration;
3330
import org.springframework.test.annotation.DirtiesContext;
@@ -37,8 +34,8 @@
3734
import integration.MessagingApplicationTests.IntegrationSpanCollectorConfig;
3835
import sample.SampleMessagingApplication;
3936
import tools.AbstractIntegrationTest;
40-
import zipkin.Constants;
41-
import zipkin.Span;
37+
import zipkin2.Span;
38+
import zipkin2.reporter.Reporter;
4239

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

84-
await().atMost(5, SECONDS).untilAsserted(() -> {
81+
await().atMost(10, SECONDS).untilAsserted(() -> {
8582
thenAllSpansHaveTraceIdEqualTo(traceId);
8683
thenTheSpansHaveProperParentStructure();
8784
});
@@ -97,64 +94,63 @@ public void should_have_passed_trace_id_with_annotations_in_async_thread_when_me
9794

9895
await().atMost(5, SECONDS).untilAsserted(() -> {
9996
thenAllSpansHaveTraceIdEqualTo(traceId);
100-
thenThereIsAtLeastOneBinaryAnnotationWithKey("background-sleep-millis");
97+
thenThereIsAtLeastOneTagWithKey("background-sleep-millis");
10198
});
10299
}
103100

104-
private void thenThereIsAtLeastOneBinaryAnnotationWithKey(String binaryAnnotationKey) {
101+
private void thenThereIsAtLeastOneTagWithKey(String key) {
105102
then(this.integrationTestSpanCollector.hashedSpans.stream()
106-
.map(s -> s.binaryAnnotations)
107-
.flatMap(Collection::stream)
108-
.anyMatch(b -> b.key.equals(binaryAnnotationKey))).isTrue();
103+
.map(Span::tags)
104+
.flatMap(m -> m.keySet().stream())
105+
.anyMatch(b -> b.equals(key))).isTrue();
109106
}
110107

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

116114
private void thenTheSpansHaveProperParentStructure() {
117115
Optional<Span> firstHttpSpan = findFirstHttpRequestSpan();
118116
List<Span> eventSpans = findAllEventRelatedSpans();
119-
Optional<Span> eventSentSpan = findSpanWithAnnotation(Constants.SERVER_SEND);
120-
Optional<Span> eventReceivedSpan = findSpanWithAnnotation(Constants.CLIENT_RECV);
117+
Optional<Span> eventSentSpan = findSpanWithKind(Span.Kind.SERVER);
118+
Optional<Span> eventReceivedSpan = findSpanWithKind(Span.Kind.CLIENT);
121119
Optional<Span> lastHttpSpansParent = findLastHttpSpansParent();
122120
// "http:/parent/" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS)
123-
Collections.sort(this.integrationTestSpanCollector.hashedSpans);
124121
thenAllSpansArePresent(firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan);
125122
then(this.integrationTestSpanCollector.hashedSpans).as("There were 4 spans").hasSize(4);
126123
log.info("Checking the parent child structure");
127124
List<Optional<Span>> parentChild = this.integrationTestSpanCollector.hashedSpans.stream()
128-
.filter(span -> span.parentId != null)
129-
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id == span.parentId).findAny()
125+
.filter(span -> span.parentId() != null)
126+
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id().equals(span.parentId())).findAny()
130127
).collect(Collectors.toList());
131128
log.info("List of parents and children " + parentChild);
132129
then(parentChild.stream().allMatch(Optional::isPresent)).isTrue();
133130
}
134131

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

140-
private Optional<Span> findSpanWithAnnotation(String annotationName) {
137+
private Optional<Span> findSpanWithKind(Span.Kind kind) {
141138
return this.integrationTestSpanCollector.hashedSpans.stream()
142-
.filter(span -> span.annotations.stream().filter(annotation -> annotationName
143-
.equals(annotation.value)).findFirst().isPresent())
139+
.filter(span -> kind.equals(span.kind()))
144140
.findFirst();
145141
}
146142

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

153149
private Optional<Span> findFirstHttpRequestSpan() {
154150
return this.integrationTestSpanCollector.hashedSpans.stream()
155151
// home is the name of the method
156-
.filter(span -> span.binaryAnnotations.stream()
157-
.anyMatch(binaryAnnotation -> new String(binaryAnnotation.value).equals("home"))).findFirst();
152+
.filter(span -> span.tags().values().stream()
153+
.anyMatch("home"::equals)).findFirst();
158154
}
159155

160156
private void thenAllSpansArePresent(Optional<Span> firstHttpSpan,
@@ -178,9 +174,8 @@ private void thenAllSpansArePresent(Optional<Span> firstHttpSpan,
178174
@Configuration
179175
public static class IntegrationSpanCollectorConfig {
180176
@Bean
181-
ZipkinSpanReporter integrationTestZipkinSpanReporter() {
177+
Reporter<Span> integrationTestZipkinSpanReporter() {
182178
return new IntegrationTestZipkinSpanReporter();
183179
}
184180
}
185-
186181
}

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-ribbon/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</dependency>
7171
<dependency>
7272
<groupId>org.springframework.cloud</groupId>
73-
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
73+
<artifactId>spring-cloud-sleuth-zipkin2</artifactId>
7474
</dependency>
7575
<dependency>
7676
<groupId>org.springframework.boot</groupId>

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-ribbon/src/main/java/sample/SampleRibbonApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2424
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
25-
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
2625
import org.springframework.context.annotation.Bean;
2726
import org.springframework.scheduling.annotation.EnableAsync;
2827
import org.springframework.web.client.RestTemplate;
2928

30-
import zipkin.Span;
29+
import zipkin2.Span;
30+
import zipkin2.reporter.Reporter;
3131

3232
/**
3333
* @author Spencer Gibb
@@ -51,8 +51,8 @@ public RestTemplate restTemplate() {
5151
// Use this for debugging (or if there is no Zipkin server running on port 9411)
5252
@Bean
5353
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
54-
public ZipkinSpanReporter spanCollector() {
55-
return new ZipkinSpanReporter() {
54+
public Reporter<Span> spanReporter() {
55+
return new Reporter<Span>() {
5656
@Override
5757
public void report(Span span) {
5858
logger.info(span);

spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-test-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<scope>compile</scope>
106106
</dependency>
107107
<dependency>
108-
<groupId>io.zipkin.java</groupId>
108+
<groupId>io.zipkin.zipkin2</groupId>
109109
<artifactId>zipkin</artifactId>
110110
</dependency>
111111
</dependencies>

0 commit comments

Comments
 (0)