Added a property to toggle discovery client support for zipkin client. Fixes gh-919

This commit is contained in:
Marcin Grzejszczak
2018-03-29 09:39:38 +02:00
parent 5ed219e34f
commit eb9b305f7f
3 changed files with 34 additions and 2 deletions

View File

@@ -518,13 +518,26 @@ spring.zipkin.baseUrl: http://192.168.99.100:9411/
----
If you want to find Zipkin via service discovery it's enough to pass the
Zipkin's service id inside the URL (example for `zipkinserver` service id)
Zipkin's service id inside the URL. If you want to disable this feature
just set `spring.zipkin.discoveryClientEnabled` to `false.
Example for `zipkinserver` service id:
[source,yaml]
----
spring.zipkin.baseUrl: http://zipkinserver/
----
When this Discovery Client feature is enabled, Sleuth uses
`LoadBalancerClient` to find the URL of the Zipkin Server. It means
that you can set up the load balancing configuration e.g. via Ribbon.
[source,yaml]
----
zipkinserver:
ribbon:
ListOfServers: host1,host2
----
If you have web, rabbit or kafka together on the classpath, you might need
to pick the means by which you would like to send spans to zipkin. To do that
just set either `web`, `rabbit` or `kafka` to the `spring.zipkin.sender.type` property.

View File

@@ -28,11 +28,19 @@ import zipkin2.codec.SpanBytesEncoder;
*/
@ConfigurationProperties("spring.zipkin")
public class ZipkinProperties {
/** URL of the zipkin query server instance. You can also provide
/**
* URL of the zipkin query server instance. You can also provide
* the service id of the Zipkin server if Zipkin's registered in
* service discovery (e.g. http://zipkinserver/)
*/
private String baseUrl = "http://localhost:9411/";
/**
* If set to {@code false}, will treat the {@link ZipkinProperties#baseUrl}
* as a URL always
*/
private Boolean discoveryClientEnabled;
/**
* Enables sending spans to Zipkin
*/
@@ -68,6 +76,14 @@ public class ZipkinProperties {
return this.enabled;
}
public Boolean getDiscoveryClientEnabled() {
return this.discoveryClientEnabled;
}
public void setDiscoveryClientEnabled(Boolean discoveryClientEnabled) {
this.discoveryClientEnabled = discoveryClientEnabled;
}
public int getMessageTimeout() {
return this.messageTimeout;
}

View File

@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.sleuth.zipkin2.ZipkinLoadBalancer;
@@ -42,6 +43,7 @@ class ZipkinRestTemplateSenderConfiguration {
@Configuration
@ConditionalOnMissingClass("org.springframework.cloud.client.loadbalancer.LoadBalancerClient")
@ConditionalOnProperty(value = "spring.zipkin.discoveryClientEnabled", havingValue = "false")
static class DefaultZipkinUrlExtractorConfiguration {
@Autowired(required = false) LoadBalancerClient client;
@@ -58,6 +60,7 @@ class ZipkinRestTemplateSenderConfiguration {
@Configuration
@ConditionalOnClass(LoadBalancerClient.class)
@ConditionalOnProperty(value = "spring.zipkin.discoveryClientEnabled", havingValue = "true", matchIfMissing = true)
static class DiscoveryClientZipkinUrlExtractorConfiguration {
@Autowired(required = false) LoadBalancerClient client;