Skip to content

Commit 06209c0

Browse files
Sleuth 2.0, Boot 2.0, Zipkin via rabbit
1 parent 4dc15ca commit 06209c0

File tree

19 files changed

+344
-247
lines changed

19 files changed

+344
-247
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ build/
2121
zipkin.jar
2222
zipkin.jar.asc
2323
zipkin.jar.md5.asc
24+
out/

acceptance-tests/src/test/groovy/io/spring/cloud/samples/docs/acceptance/MessageFlowSpec.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package io.spring.cloud.samples.docs.acceptance
1818
import groovy.json.JsonSlurper
1919
import groovy.util.logging.Slf4j
2020
import io.spring.cloud.samples.docs.acceptance.common.tech.ExceptionLoggingRestTemplate
21+
import io.spring.cloud.samples.docs.acceptance.common.tech.SpanUtil
2122
import io.spring.cloud.samples.docs.acceptance.common.tech.TestConfiguration
2223
import org.springframework.beans.factory.annotation.Value
2324
import org.springframework.boot.test.context.SpringBootContextLoader
24-
import org.springframework.cloud.sleuth.Span
2525
import org.springframework.http.HttpHeaders
2626
import org.springframework.http.HttpMethod
2727
import org.springframework.http.HttpStatus
@@ -35,13 +35,13 @@ import zipkin.Codec
3535

3636
import static org.awaitility.Awaitility.await
3737
import static java.util.concurrent.TimeUnit.SECONDS
38-
import static org.springframework.cloud.sleuth.Span.SPAN_ID_NAME
3938

4039
@ContextConfiguration(classes = TestConfiguration, loader = SpringBootContextLoader)
4140
@Slf4j
4241
class MessageFlowSpec extends Specification {
4342

44-
public static final String TRACE_ID_HEADER_NAME = Span.TRACE_ID_NAME
43+
public static final String TRACE_ID_HEADER_NAME = "X-B3-TraceId"
44+
public static final String SPAN_ID_NAME = "X-B3-SpanId"
4545
private static final List<String> APP_NAMES = ['service1', 'service2', 'service3', 'service4']
4646

4747
@Value('${serviceUrl:http://localhost:8081}') String service1Url
@@ -59,7 +59,7 @@ class MessageFlowSpec extends Specification {
5959
and: "The dependency graph looks like in the docs"
6060
dependency_graph_is_correct()
6161
where:
62-
traceId = Span.idToHex(new Random().nextLong())
62+
traceId = SpanUtil.idToHex(new Random().nextLong())
6363
}
6464

6565
@Unroll
@@ -71,7 +71,7 @@ class MessageFlowSpec extends Specification {
7171
then: "Entry in Zipkin is present for the traceId"
7272
failed_entry_for_trace_id_is_present_in_Zipkin(traceId)
7373
where:
74-
traceId = Span.idToHex(new Random().nextLong())
74+
traceId = SpanUtil.idToHex(new Random().nextLong())
7575
}
7676

7777
private request_sent_for_service1_with_traceId( RequestEntity request) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.spring.cloud.samples.docs.acceptance.common.tech;
2+
3+
/**
4+
* @author Marcin Grzejszczak
5+
* @since
6+
*/
7+
public class SpanUtil {
8+
9+
/**
10+
* Represents given long id as 16-character lower-hex string
11+
*/
12+
public static String idToHex(long id) {
13+
char[] data = new char[16];
14+
writeHexLong(data, 0, id);
15+
return new String(data);
16+
}
17+
18+
/** Inspired by {@code okio.Buffer.writeLong} */
19+
static void writeHexLong(char[] data, int pos, long v) {
20+
writeHexByte(data, pos + 0, (byte) ((v >>> 56L) & 0xff));
21+
writeHexByte(data, pos + 2, (byte) ((v >>> 48L) & 0xff));
22+
writeHexByte(data, pos + 4, (byte) ((v >>> 40L) & 0xff));
23+
writeHexByte(data, pos + 6, (byte) ((v >>> 32L) & 0xff));
24+
writeHexByte(data, pos + 8, (byte) ((v >>> 24L) & 0xff));
25+
writeHexByte(data, pos + 10, (byte) ((v >>> 16L) & 0xff));
26+
writeHexByte(data, pos + 12, (byte) ((v >>> 8L) & 0xff));
27+
writeHexByte(data, pos + 14, (byte) (v & 0xff));
28+
}
29+
30+
static void writeHexByte(char[] data, int pos, byte b) {
31+
data[pos + 0] = HEX_DIGITS[(b >> 4) & 0xf];
32+
data[pos + 1] = HEX_DIGITS[b & 0xf];
33+
}
34+
35+
static final char[] HEX_DIGITS =
36+
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
37+
}

build.gradle

Lines changed: 139 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,165 @@
11
buildscript {
2-
repositories {
3-
mavenLocal()
4-
mavenCentral()
5-
maven {
6-
url "http://repo.spring.io/snapshot"
7-
}
8-
maven {
9-
url "http://repo.spring.io/milestone"
10-
}
11-
maven {
12-
url "http://repo.spring.io/libs-release-local"
13-
}
14-
maven {
15-
url "http://repo.spring.io/libs-staging-local/"
16-
}
17-
}
18-
dependencies {
19-
classpath "org.springframework.boot:spring-boot-gradle-plugin:${BOOT_VERSION}"
20-
}
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
maven {
6+
url "http://repo.spring.io/snapshot"
7+
}
8+
maven {
9+
url "http://repo.spring.io/milestone"
10+
}
11+
maven {
12+
url "http://repo.spring.io/libs-release-local"
13+
}
14+
}
15+
dependencies {
16+
classpath "org.springframework.boot:spring-boot-gradle-plugin:${BOOT_VERSION}"
17+
}
2118
}
2219

2320
allprojects {
24-
apply plugin: 'java'
21+
apply plugin: 'java'
2522
}
2623

2724
configure(subprojects) {
2825

29-
apply plugin: 'java'
30-
apply plugin: 'eclipse'
31-
apply plugin: 'idea'
32-
apply plugin: 'org.springframework.boot'
33-
34-
ext {
35-
systemPropsFromGradle = {
36-
project.gradle.startParameter.systemPropertiesArgs.entrySet().collect{"-D${it.key}=${it.value}"}
37-
}
38-
buildNrLoc = project.hasProperty('buildNr') ? "${buildNr}" : "1.0.0.SLEUTH_DOCS"
39-
}
40-
41-
group = 'io.spring.cloud.sleuth.docs'
42-
version = buildNrLoc
43-
sourceCompatibility = '1.8'
44-
45-
repositories {
46-
mavenLocal()
47-
jcenter()
48-
maven {
49-
url "http://repo.spring.io/snapshot"
50-
}
51-
maven {
52-
url "http://repo.spring.io/milestone"
53-
}
54-
maven {
55-
url "http://repo.spring.io/libs-release-local"
56-
}
57-
maven {
58-
url "http://repo.spring.io/libs-staging-local/"
59-
}
60-
}
61-
62-
dependencyManagement {
63-
Closure<String> getProp = { String propName -> System.properties[propName] ?:
64-
project.gradle.startParameter.systemPropertiesArgs.get(propName) ?:
65-
hasProperty(propName) ? property(propName) :
66-
System.getenv(propName) ?: ""
67-
}
68-
imports {
69-
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${getProp("BOM_VERSION") ?: "Edgware.BUILD-SNAPSHOT"}"
70-
}
71-
}
72-
73-
wrapper {
74-
gradleVersion '4.6.0'
75-
}
76-
77-
bootRun {
78-
jvmArgs = systemPropsFromGradle()
79-
}
80-
81-
test {
82-
jvmArgs systemPropsFromGradle()
83-
testLogging {
84-
exceptionFormat = 'full'
85-
showStandardStreams = true
86-
}
87-
}
26+
apply plugin: 'java'
27+
apply plugin: 'eclipse'
28+
apply plugin: 'idea'
29+
apply plugin: 'org.springframework.boot'
30+
apply plugin: 'io.spring.dependency-management'
31+
32+
ext {
33+
systemPropsFromGradle = {
34+
project.gradle.startParameter.systemPropertiesArgs.entrySet().collect {
35+
"-D${it.key}=${it.value}"
36+
}
37+
}
38+
buildNrLoc = project.hasProperty('buildNr') ? "${buildNr}" : "1.0.0.SLEUTH_DOCS"
39+
}
40+
41+
group = 'io.spring.cloud.sleuth.docs'
42+
version = buildNrLoc
43+
sourceCompatibility = '1.8'
44+
45+
repositories {
46+
mavenLocal()
47+
jcenter()
48+
maven {
49+
url "http://repo.spring.io/snapshot"
50+
}
51+
maven {
52+
url "http://repo.spring.io/milestone"
53+
}
54+
maven {
55+
url "http://repo.spring.io/libs-release-local"
56+
}
57+
}
58+
59+
dependencyManagement {
60+
Closure<String> getProp = { String propName ->
61+
System.properties[propName] ?:
62+
project.gradle.startParameter.systemPropertiesArgs.get(propName) ?:
63+
hasProperty(propName) ? property(propName) :
64+
System.getenv(propName) ?: ""
65+
}
66+
imports {
67+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${getProp("BOM_VERSION") ?: "Finchley.BUILD-SNAPSHOT"}"
68+
}
69+
}
70+
71+
wrapper {
72+
gradleVersion '4.6'
73+
}
74+
75+
bootRun {
76+
jvmArgs = systemPropsFromGradle()
77+
}
78+
79+
test {
80+
jvmArgs systemPropsFromGradle()
81+
testLogging {
82+
exceptionFormat = 'full'
83+
showStandardStreams = true
84+
}
85+
}
8886

8987
}
9088

9189
configure(subprojects) {
92-
task allDeps(type: DependencyReportTask) {}
90+
task allDeps(type: DependencyReportTask) {}
9391
}
9492

9593
configure(subprojects - project(':acceptance-tests')) {
9694

97-
dependencies {
98-
compile "org.springframework.boot:spring-boot-starter-web"
99-
compile "org.springframework.cloud:spring-cloud-starter-zipkin"
100-
compile "org.springframework.amqp:spring-rabbit"
101-
compile "org.springframework.boot:spring-boot-starter-actuator"
102-
compile "org.aspectj:aspectjrt"
103-
// for JSON logging
104-
runtime('net.logstash.logback:logstash-logback-encoder:4.6') {
105-
exclude group: "ch.qos.logback", module: "logback-core"
106-
}
95+
dependencies {
96+
compile "org.springframework.boot:spring-boot-starter-web"
97+
compile "org.springframework.cloud:spring-cloud-starter-zipkin"
98+
compile "org.springframework.amqp:spring-rabbit"
99+
compile "org.springframework.boot:spring-boot-starter-actuator"
100+
compile "org.aspectj:aspectjrt"
101+
// for JSON logging
102+
runtime('net.logstash.logback:logstash-logback-encoder:5.0') {
103+
exclude group: "ch.qos.logback", module: "logback-core"
104+
}
107105

108-
runtime 'org.aspectj:aspectjweaver'
109-
}
106+
runtime 'org.aspectj:aspectjweaver'
107+
}
110108

111109
}
112110

113111
configure(project(":acceptance-tests")) {
114-
apply plugin: 'groovy'
115-
116-
bootRepackage {
117-
enabled = false
118-
}
119-
120-
bootRun {
121-
enabled = false
122-
}
123-
124-
dependencies {
125-
compile "org.aspectj:aspectjrt:1.8.8"
126-
compile "org.springframework.boot:spring-boot-starter-web"
127-
compile 'org.codehaus.groovy:groovy-all'
128-
129-
testCompile 'org.awaitility:awaitility:2.0.0'
130-
testCompile "org.springframework.boot:spring-boot-starter-test"
131-
testCompile "org.springframework:spring-web"
132-
testCompile "org.springframework.boot:spring-boot-starter-web"
133-
testCompile "org.springframework.cloud:spring-cloud-starter-sleuth"
134-
testCompile "io.zipkin.java:zipkin:1.0.0"
135-
testCompile( 'com.athaydes:spock-reports:1.2.13' ) {
136-
transitive = false // this avoids affecting your version of Groovy/Spock
137-
}
138-
testCompile "org.spockframework:spock-spring"
139-
}
140-
141-
test {
142-
exclude '**/*.*'
143-
}
144-
145-
task acceptanceTests(type: Test) {
146-
jvmArgs systemPropsFromGradle()
147-
testLogging {
148-
exceptionFormat = 'full'
149-
showStandardStreams = true
150-
}
151-
include '**/*.*'
152-
153-
group = "Verification"
154-
description = "Runs the acceptance tests"
155-
}
112+
apply plugin: 'groovy'
113+
114+
bootJar {
115+
enabled = false
116+
}
117+
jar {
118+
enabled = true
119+
}
120+
121+
bootRun {
122+
enabled = false
123+
}
124+
125+
dependencies {
126+
compile "org.aspectj:aspectjrt:1.8.8"
127+
compile "org.springframework.boot:spring-boot-starter-web"
128+
compile 'org.codehaus.groovy:groovy-all'
129+
130+
testCompile 'org.awaitility:awaitility:2.0.0'
131+
testCompile "org.springframework.boot:spring-boot-starter-test"
132+
testCompile "org.springframework:spring-web"
133+
testCompile "org.springframework.boot:spring-boot-starter-web"
134+
testCompile "org.springframework.cloud:spring-cloud-starter-sleuth"
135+
testCompile "io.zipkin.java:zipkin:1.0.0"
136+
testCompile('com.athaydes:spock-reports:1.2.13') {
137+
transitive = false // this avoids affecting your version of Groovy/Spock
138+
}
139+
testCompile "org.spockframework:spock-spring:1.1-groovy-2.4"
140+
}
141+
142+
test {
143+
exclude '**/*.*'
144+
}
145+
146+
task acceptanceTests(type: Test) {
147+
jvmArgs systemPropsFromGradle()
148+
testLogging {
149+
exceptionFormat = 'full'
150+
showStandardStreams = true
151+
}
152+
include '**/*.*'
153+
154+
group = "Verification"
155+
description = "Runs the acceptance tests"
156+
}
156157

157158
}
158159

159160
String getProp(String propName) {
160-
return System.properties[propName] ?:
161-
project.gradle.startParameter.systemPropertiesArgs.get(propName) ?:
162-
hasProperty(propName) ? property(propName) :
163-
System.getenv(propName) ?: ""
161+
return System.properties[propName] ?:
162+
project.gradle.startParameter.systemPropertiesArgs.get(propName) ?:
163+
hasProperty(propName) ? property(propName) :
164+
System.getenv(propName) ?: ""
164165
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ rabbitmq:
22
image: rabbitmq:management
33
ports:
44
- 9672:5672
5-
- 15672
5+
- 15672:15672

0 commit comments

Comments
 (0)