From bac39b58420b7d120bba78ecf9cd01c91d4b2ade Mon Sep 17 00:00:00 2001
From: yirenyishi <mail_yanpeng@163.com>
Date: Sun, 5 Aug 2018 22:48:09 +0800
Subject: [PATCH] sc-zipkin

---
 sc-consumer/build.gradle                      |  3 +-
 sc-consumer/src/main/resources/bootstrap.yml  |  5 ++
 sc-provider/build.gradle                      |  3 +-
 sc-provider/src/main/resources/bootstrap.yml  |  7 ++-
 sc-zipkin/.gitignore                          | 27 +++++++++++
 sc-zipkin/build.gradle                        | 47 +++++++++++++++++++
 .../trgis/sb2sc/Sb2scZipkinApplication.java   | 15 ++++++
 sc-zipkin/src/main/resources/application.yml  | 20 ++++++++
 sc-zuul/build.gradle                          |  2 +
 sc-zuul/src/main/resources/bootstrap.yml      |  5 ++
 settings.gradle                               |  2 +-
 11 files changed, 132 insertions(+), 4 deletions(-)
 create mode 100644 sc-zipkin/.gitignore
 create mode 100644 sc-zipkin/build.gradle
 create mode 100644 sc-zipkin/src/main/java/com/trgis/sb2sc/Sb2scZipkinApplication.java
 create mode 100644 sc-zipkin/src/main/resources/application.yml

diff --git a/sc-consumer/build.gradle b/sc-consumer/build.gradle
index 9b0b8f8..b23dd0a 100644
--- a/sc-consumer/build.gradle
+++ b/sc-consumer/build.gradle
@@ -35,7 +35,8 @@ dependencies {
 	compile('org.springframework.boot:spring-boot-starter-actuator')
 	compile('org.springframework.cloud:spring-cloud-starter-openfeign')
 	compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
-	testCompile('org.springframework.boot:spring-boot-starter-test')
+	compile('org.springframework.cloud:spring-cloud-starter-sleuth')
+	compile('org.springframework.cloud:spring-cloud-starter-zipkin')
 }
 
 dependencyManagement {
diff --git a/sc-consumer/src/main/resources/bootstrap.yml b/sc-consumer/src/main/resources/bootstrap.yml
index 768eaed..d8e2bc7 100644
--- a/sc-consumer/src/main/resources/bootstrap.yml
+++ b/sc-consumer/src/main/resources/bootstrap.yml
@@ -8,6 +8,11 @@ eureka:
     appname: sc-consumer
 
 spring:
+  zipkin:
+    base-url: http://localhost:9411
+  sleuth:
+    sampler:
+      percentage: 1.0
   application:
     name: sc-consumer
   cloud:
diff --git a/sc-provider/build.gradle b/sc-provider/build.gradle
index 39ce44e..59a3540 100644
--- a/sc-provider/build.gradle
+++ b/sc-provider/build.gradle
@@ -33,7 +33,8 @@ dependencies {
 	compile('org.springframework.cloud:spring-cloud-starter-config')
 	compile('org.springframework.boot:spring-boot-starter-webflux')
 	compile('org.springframework.boot:spring-boot-starter-actuator')
-	testCompile('org.springframework.boot:spring-boot-starter-test')
+	compile('org.springframework.cloud:spring-cloud-starter-sleuth')
+	compile('org.springframework.cloud:spring-cloud-starter-zipkin')
 }
 
 dependencyManagement {
diff --git a/sc-provider/src/main/resources/bootstrap.yml b/sc-provider/src/main/resources/bootstrap.yml
index d65151c..f96cb15 100644
--- a/sc-provider/src/main/resources/bootstrap.yml
+++ b/sc-provider/src/main/resources/bootstrap.yml
@@ -18,4 +18,9 @@ spring:
       fail-fast: true
       username: root
       password: booszy
-      profile: csdn
\ No newline at end of file
+      profile: csdn
+  zipkin:
+    base-url: http://localhost:9411
+  sleuth:
+    sampler:
+      percentage: 1.0
\ No newline at end of file
diff --git a/sc-zipkin/.gitignore b/sc-zipkin/.gitignore
new file mode 100644
index 0000000..2b1babb
--- /dev/null
+++ b/sc-zipkin/.gitignore
@@ -0,0 +1,27 @@
+.gradle
+/build/
+!gradle/wrapper/gradle-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+/out/
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
\ No newline at end of file
diff --git a/sc-zipkin/build.gradle b/sc-zipkin/build.gradle
new file mode 100644
index 0000000..d852334
--- /dev/null
+++ b/sc-zipkin/build.gradle
@@ -0,0 +1,47 @@
+buildscript {
+	ext {
+		springBootVersion = '2.0.3.RELEASE'
+	}
+	repositories {
+		mavenCentral()
+	}
+	dependencies {
+		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+	}
+}
+
+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'org.springframework.boot'
+apply plugin: 'io.spring.dependency-management'
+
+group = 'com.trgis'
+version = '0.0.1-SNAPSHOT'
+sourceCompatibility = 1.8
+
+repositories {
+	mavenCentral()
+}
+
+
+ext {
+	springCloudVersion = 'Finchley.RELEASE'
+}
+configurations {
+	compile.exclude module: 'log4j'
+	compile.exclude module: 'slf4j-log4j12'
+	compile.exclude module: 'spring-boot-starter-logging'
+}
+
+dependencies {
+	compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
+	compile group: 'io.zipkin.java', name: 'zipkin-server', version: '2.9.3'
+	compile group: 'io.zipkin.java', name: 'zipkin-autoconfigure-ui', version: '2.9.3'
+	compile('org.springframework.boot:spring-boot-starter-actuator')
+}
+
+dependencyManagement {
+	imports {
+		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
+	}
+}
diff --git a/sc-zipkin/src/main/java/com/trgis/sb2sc/Sb2scZipkinApplication.java b/sc-zipkin/src/main/java/com/trgis/sb2sc/Sb2scZipkinApplication.java
new file mode 100644
index 0000000..b6e1337
--- /dev/null
+++ b/sc-zipkin/src/main/java/com/trgis/sb2sc/Sb2scZipkinApplication.java
@@ -0,0 +1,15 @@
+package com.trgis.sb2sc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import zipkin.server.internal.EnableZipkinServer;
+
+@EnableDiscoveryClient
+@SpringBootApplication
+@EnableZipkinServer
+public class Sb2scZipkinApplication {
+	public static void main(String[] args) {
+		SpringApplication.run(Sb2scZipkinApplication.class, args);
+	}
+}
diff --git a/sc-zipkin/src/main/resources/application.yml b/sc-zipkin/src/main/resources/application.yml
new file mode 100644
index 0000000..d7c9e54
--- /dev/null
+++ b/sc-zipkin/src/main/resources/application.yml
@@ -0,0 +1,20 @@
+server:
+  port: 9411
+spring:
+  application:
+    name: sc-sc-zipkin
+  profiles:
+    active: csdn
+eureka:
+  client:
+    service-url:
+      defaultZone: http://root:booszy@localhost:8761/eureka/
+  instance:
+    prefer-ip-address: true
+    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
+    appname: sc-zipkin
+management:
+  metrics:
+    web:
+      server:
+        auto-time-requests: false
\ No newline at end of file
diff --git a/sc-zuul/build.gradle b/sc-zuul/build.gradle
index c66d215..fcfa471 100644
--- a/sc-zuul/build.gradle
+++ b/sc-zuul/build.gradle
@@ -33,6 +33,8 @@ dependencies {
 	compile('org.springframework.cloud:spring-cloud-starter-config')
 	compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
 	compile('org.springframework.boot:spring-boot-starter-actuator')
+	compile('org.springframework.cloud:spring-cloud-starter-sleuth')
+	compile('org.springframework.cloud:spring-cloud-starter-zipkin')
 }
 
 dependencyManagement {
diff --git a/sc-zuul/src/main/resources/bootstrap.yml b/sc-zuul/src/main/resources/bootstrap.yml
index 69dfc01..c187012 100644
--- a/sc-zuul/src/main/resources/bootstrap.yml
+++ b/sc-zuul/src/main/resources/bootstrap.yml
@@ -8,6 +8,11 @@ eureka:
     appname: sc-zuul
 
 spring:
+  zipkin:
+    base-url: http://localhost:9411
+  sleuth:
+    sampler:
+      percentage: 1.0
   application:
     name: sc-zuul
   cloud:
diff --git a/settings.gradle b/settings.gradle
index 817fdb8..e692b30 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1,2 @@
 rootProject.name = 'sb2sc'
-include('sc-eureka','sc-config','sc-provider','sc-consumer','sc-zuul','sc-dashboard')
\ No newline at end of file
+include('sc-eureka','sc-config','sc-provider','sc-consumer','sc-zuul','sc-dashboard','sc-zipkin')
\ No newline at end of file