Add ribbon/zuul features and docs plus a sample

This commit is contained in:
Dave Syer
2015-08-13 10:44:43 +01:00
parent 74ee062d6d
commit 4b7154e1e5
25 changed files with 493 additions and 44 deletions

View File

@@ -19,6 +19,7 @@
<modules>
<module>spring-cloud-sleuth-sample</module>
<module>spring-cloud-sleuth-sample-messaging</module>
<module>spring-cloud-sleuth-sample-ribbon</module>
<module>spring-cloud-sleuth-sample-zipkin</module>
</modules>

View File

@@ -72,7 +72,7 @@ public class SampleMessagingApplication {
// Use this for debugging (or if there is no Zipkin collector running on port 9410)
@Bean
@ConditionalOnProperty("span.logging.enabled")
@ConditionalOnProperty(value="sample.zipkin.enabled", havingValue="false")
public SpanCollector spanCollector() {
return new LoggingSpanCollectorImpl();
}

View File

@@ -13,6 +13,6 @@ logging:
pattern:
console: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex'
span:
logging:
# enabled: true
sample:
zipkin:
# enabled: false

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-sleuth-sample-ribbon</artifactId>
<packaging>jar</packaging>
<name>spring-cloud-sleuth-sample-ribbon</name>
<description>Spring Cloud Sleuth Sample</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!--skip deploy -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import java.util.Random;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
* @author Spencer Gibb
* @author Dave Syer
*/
@RestController
public class SampleController {
@Autowired
private RestTemplate restTemplate;
@SneakyThrows
@RequestMapping("/")
public String hi() {
final Random random = new Random();
Thread.sleep(random.nextInt(1000));
String s = this.restTemplate.getForObject("http://zipkin/hi2", String.class);
return "hi/" + s;
}
@SneakyThrows
@RequestMapping("/call")
public String traced() {
String s = this.restTemplate.getForObject("http://zipkin/call", String.class);
return "call/" + s;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample;
import org.springframework.boot.SpringApplication;
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.Sampler;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import com.github.kristofa.brave.LoggingSpanCollectorImpl;
import com.github.kristofa.brave.SpanCollector;
/**
* @author Spencer Gibb
*/
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
@EnableZuulProxy
public class SampleRibbonApplication {
@Bean
public Sampler<?> defaultSampler() {
return new AlwaysSampler();
}
public static void main(String[] args) {
SpringApplication.run(SampleRibbonApplication.class, args);
}
// Use this for debugging (or if there is no Zipkin collector running on port 9410)
@Bean
@ConditionalOnProperty(value="sample.zipkin.enabled", havingValue="false")
public SpanCollector spanCollector() {
return new LoggingSpanCollectorImpl();
}
}

View File

@@ -0,0 +1,46 @@
server:
port: 3382
spring:
application:
name: testSleuthRibbon
sleuth:
log:
json:
enabled: true
zipkin:
ribbon:
listOfServers: localhost:3380
messaging:
ribbon:
listOfServers: localhost:3381
vanilla:
ribbon:
listOfServers: localhost:3379
hystrix:
execution:
isolation:
strategy: SEMAPHORE
zuul:
routes:
zipkin:
url: http://localhost:3380
messaging:
url: http://localhost:3381
vanilla:
url: http://localhost:3379
logging:
pattern:
console: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex'
endpoints:
health:
sensitive: false
restart:
enabled: true
shutdown:
enabled: true

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.sample;
package sample;
import java.util.Random;
import java.util.concurrent.Callable;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.sleuth.sample;
package sample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -49,7 +49,7 @@ public class SampleZipkinApplication {
// Use this for debugging (or if there is no Zipkin collector running on port 9410)
@Bean
@ConditionalOnProperty("span.logging.enabled")
@ConditionalOnProperty(value="sample.zipkin.enabled", havingValue="false")
public SpanCollector spanCollector() {
return new LoggingSpanCollectorImpl();
}

View File

@@ -9,9 +9,9 @@ logging:
pattern:
console: '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex'
span:
logging:
# enabled: true
sample:
zipkin:
# enabled: false
endpoints:
health: