Skip to content

Commit

Permalink
Added Spring Cloud Sleuth
Browse files Browse the repository at this point in the history
  • Loading branch information
cer committed Sep 11, 2016
1 parent e15b1ad commit d258bc3
Show file tree
Hide file tree
Showing 26 changed files with 448 additions and 36 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ On Mac OSX you can run `brew install chromedriver`.

## The quick way

The quickest way to build and run the services on Mac OSX is the script `build-test-and-run-all.sh`.
The quickest way to build and run the services on Linux/Mac OSX is with the following commands:

```
. ./set-env.sh
./gradle-all.sh assemble
docker-compose up -d
./show-urls.sh
```

Otherwise, follow these instructions.

Expand Down Expand Up @@ -60,6 +67,16 @@ cd eureka-server
./gradlew build
```

## Build the Zipkin server

This application uses Zipkin for distributed tracing.
Build the Zipkin server using the following commands:

```
cd zipkin-server
./gradlew build
```

## Building the RESTful service

Use the following commands to build the RESTful service:
Expand Down Expand Up @@ -135,10 +152,12 @@ docker-compose up -d web

You can access the web application by visiting the following URL: `http://${DOCKER_HOST_IP?}:8080/register.html`

There are also other URLs that you can visit:
There are also other URLs that you can visit.
The following command will wait until the services are available and displays the URLs:

* `http://${DOCKER_HOST_IP?}:8761` - Eureka console
* `http://${DOCKER_HOST_IP?}:8081/swagger-ui.html` - the Swagger UI
```
./show-urls.sh
```

# Building and running Docker images

Expand Down
16 changes: 4 additions & 12 deletions build-and-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

set -e

if [ -z "$DOCKER_HOST_IP" ] ; then
if which docker-machine >/dev/null; then
export DOCKER_HOST_IP=$(docker-machine ip default)
else
export DOCKER_HOST_IP=localhost
fi
echo set DOCKER_HOST_IP $DOCKER_HOST_IP
fi

. ./set-env.sh
docker-compose stop
docker-compose rm -v --force

Expand All @@ -19,13 +11,13 @@ docker-compose up -d rabbitmq mongodb
cd eureka-server
./gradlew build

cd ../zipkin-server
./gradlew build

cd ..

cd spring-boot-restful-service

export SPRING_RABBITMQ_HOST=${DOCKER_HOST_IP?}
export SPRING_DATA_MONGODB_URI=mongodb://${DOCKER_HOST_IP?}/userregistration

./gradlew build

cd ..
Expand Down
22 changes: 21 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rabbitmq:
image: rabbitmq:3.5.3
image: rabbitmq:3.5.3-management
ports:
- "5672:5672"
- "15672:15672"
Expand All @@ -13,6 +13,19 @@ eureka:
ports:
- "8761:8761"

zipkin:
image: java:openjdk-8u91-jdk
working_dir: /app
volumes:
- ./zipkin-server/build/libs:/app
command: java -jar /app/zipkin-server.jar --server.port=9411
links:
- rabbitmq
ports:
- "9411:9411"
environment:
RABBIT_HOST: rabbitmq

mongodb:
image: mongo:3.0.4
ports:
Expand All @@ -38,6 +51,8 @@ restfulservice:
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1

web:
image: java:openjdk-8u91-jdk
Expand All @@ -49,9 +64,14 @@ web:
- "8080:8080"
links:
- eureka
- rabbitmq
environment:
USER_REGISTRATION_URL: http://REGISTRATION-SERVICE/user
SPRING_APPLICATION_NAME: registration-web
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1
SPRING_SLEUTH_WEB_SKIPPATTERN: "/api-docs.*|/autoconfig|/configprops|/dump|/health|/info|/metrics.*|/mappings|/trace|/swagger.*|.*\\.png|.*\\.css|.*\\.js|/favicon.ico|/hystrix.stream"
4 changes: 2 additions & 2 deletions eureka-server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
Expand All @@ -15,7 +15,7 @@ apply plugin: 'spring-boot'

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.RELEASE'
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR4'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle-all.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash -e

for dir in spring-boot-*; do
for dir in spring-boot-* zipkin-server eureka-server ; do
(cd $dir ; ./gradlew -b build.gradle $*)
done
5 changes: 3 additions & 2 deletions run-e2e-test-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ docker-compose -f docker-compose-images.yml up -d
#sleep 30
#echo ... running

./register-user.sh

set +e
(cd e2e-test ; ./gradlew cleanTest test)
set -e
(cd e2e-test ; ./gradlew cleanTest test)

docker-compose stop
Expand Down
3 changes: 3 additions & 0 deletions run-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ docker-compose up -d

./register-user.sh

set +e
(cd e2e-test ; ./gradlew cleanTest test)
set -e
(cd e2e-test ; ./gradlew cleanTest test)

docker-compose stop
Expand Down
14 changes: 14 additions & 0 deletions set-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash -e

if [ -z "$DOCKER_HOST_IP" ] ; then
if [ -z "$DOCKER_HOST" ] ; then
export DOCKER_HOST_IP=`hostname`
else
echo using ${DOCKER_HOST?}
XX=${DOCKER_HOST%\:*}
export DOCKER_HOST_IP=${XX#tcp\:\/\/}
fi
fi

export SPRING_RABBITMQ_HOST=${DOCKER_HOST_IP?}
export SPRING_DATA_MONGODB_URI=mongodb://${DOCKER_HOST_IP?}/userregistration
7 changes: 5 additions & 2 deletions show-urls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

echo The microservices are running
echo You can visit these URLS
echo http://${DOCKER_HOST_IP?}:8080/register.html - registration
echo http://${DOCKER_HOST_IP?}:8080/register.html - registration UI
echo http://${DOCKER_HOST_IP?}:8761 - Eureka console
echo http://${DOCKER_HOST_IP?}:8081/swagger-ui.html - the Swagger UI
echo http://${DOCKER_HOST_IP?}:8080/swagger-ui.html - the Web Swagger UI
echo http://${DOCKER_HOST_IP?}:8081/swagger-ui.html - the Backend Swagger UI
echo http://${DOCKER_HOST_IP?}:9411 - Zipkin
echo http://${DOCKER_HOST_IP?}:15672 - RabbitMQ admin - guest/guest login
9 changes: 7 additions & 2 deletions spring-boot-restful-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'spring-boot'

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.RELEASE'
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
}
}

Expand All @@ -29,7 +29,12 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-amqp"
compile "org.springframework.boot:spring-boot-starter-actuator"

// compile 'org.springframework.cloud:spring-cloud-starter-config'
// Spring Cloud Sleuth
compile "org.springframework.cloud:spring-cloud-sleuth-stream"
compile "org.springframework.cloud:spring-cloud-starter-sleuth"
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit"
// Spring Cloud Sleuth

compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile "io.springfox:springfox-swagger2:2.1.2"
compile 'io.springfox:springfox-swagger-ui:2.1.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 20 10:11:32 PDT 2014
#Mon Sep 05 20:39:18 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.11-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.11-all.zip
4 changes: 2 additions & 2 deletions spring-boot-restful-service/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springframework.amqp" level="INFO"/>
<logger name="org.springframework.data.mongodb" level="DEBUG"/>
</configuration>
<logger name="org.springframework.data.mongodb" level="INFO"/>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
import org.springframework.context.annotation._
import org.springframework.cloud.sleuth.sampler.AlwaysSampler
import org.springframework.cloud.sleuth.Sampler

@SpringBootApplication
class UserRegistrationConfiguration {
Expand All @@ -31,6 +33,8 @@ class UserRegistrationConfiguration {
@Bean
def userRegistrationsExchange() = new TopicExchange(exchangeName)

@Bean
def sampler() : Sampler = new AlwaysSampler()

}

Expand Down
9 changes: 7 additions & 2 deletions spring-boot-webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: "io.spring.dependency-management"

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.RELEASE'
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
}
}

Expand All @@ -29,7 +29,12 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"

// compile 'org.springframework.cloud:spring-cloud-starter-config'
// Spring Cloud Sleuth
compile "org.springframework.cloud:spring-cloud-sleuth-stream"
compile "org.springframework.cloud:spring-cloud-starter-sleuth"
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit"
// Spring Cloud Sleuth

compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile 'org.springframework.cloud:spring-cloud-starter-hystrix'
compile 'org.webjars:bootstrap:3.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<link rel="stylesheet" href="webjars/bootstrap/3.1.1/css/bootstrap.css">
<link rel="stylesheet" href="styles/main.css">
</head>
<script src="webjars/jquery/2.1.0/jquery.js"></script>
<script src="webjars/jquery-validation/1.11.1/jquery.validate.js"></script>
<body>
<div class="container-fluid">
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-webapp/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
<logger name="net.chrisrichardson.microservices" level="DEBUG"/>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient
import org.springframework.context.annotation._
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.client.RestTemplate
import org.springframework.cloud.sleuth.sampler.AlwaysSampler
import org.springframework.cloud.sleuth.Sampler

import scala.collection.JavaConversions._

Expand All @@ -32,10 +34,13 @@ class UserRegistrationConfiguration {
resolver
}

@Bean
def sampler() : Sampler = new AlwaysSampler()


}

@Configuration
@EnableEurekaClient
@Profile(Array("!enableEureka"))
class NonEurekaClientConfiguration {

Expand Down Expand Up @@ -71,4 +76,3 @@ class EurekaClientConfiguration {
@Bean
def discoveryHealthIndicator(discoveryClient : EurekaClient ) : HealthIndicator = new DiscoveryHealthIndicator(discoveryClient)
}

2 changes: 2 additions & 0 deletions wait-for-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ done=false
host=$1
shift
path=$1
shift
ports=$*

while [[ "$done" = false ]]; do
Expand All @@ -15,6 +16,7 @@ while [[ "$done" = false ]]; do
done=true
else
done=false
break
fi
done
if [[ "$done" = true ]]; then
Expand Down
45 changes: 45 additions & 0 deletions zipkin-server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'spring-boot'

dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR5'
}
}

configurations {
all*.exclude group: "net.java.dev.jna", module: "jna"
}

dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.cloud:spring-cloud-sleuth-zipkin-stream"
compile "io.zipkin.java:zipkin-autoconfigure-ui:1.0.0"
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit"
compile 'net.java.dev.jna:jna-platform:4.2.2'
}

test {
forkEvery 1
}

repositories {
mavenCentral()
maven { url 'http://repo.spring.io/milestone' }
}

task wrapper(type: Wrapper) {
gradleVersion = '2.11'
}
Binary file added zipkin-server/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit d258bc3

Please sign in to comment.