Updates to latest Zipkin and avoids Endpoint factory method (#417)
Now that Endpoint has ipv6, the factory method is even worse than it was before. This switches to a builder instead. Note: Endpoint now has a nice toString which should help debugging.
This commit is contained in:
@@ -14,8 +14,8 @@
|
|||||||
<name>spring-cloud-sleuth-dependencies</name>
|
<name>spring-cloud-sleuth-dependencies</name>
|
||||||
<description>Spring Cloud Sleuth Dependencies</description>
|
<description>Spring Cloud Sleuth Dependencies</description>
|
||||||
<properties>
|
<properties>
|
||||||
<zipkin.version>1.11.1</zipkin.version>
|
<zipkin.version>1.13.1</zipkin.version>
|
||||||
<zipkin-reporter.version>0.5.0</zipkin-reporter.version>
|
<zipkin-reporter.version>0.6.1</zipkin-reporter.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -59,12 +59,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.zipkin.java</groupId>
|
<groupId>io.zipkin.java</groupId>
|
||||||
<artifactId>zipkin</artifactId>
|
<artifactId>zipkin</artifactId>
|
||||||
<version>1.11.1</version>
|
<version>1.13.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.zipkin.java</groupId>
|
<groupId>io.zipkin.java</groupId>
|
||||||
<artifactId>zipkin-server</artifactId>
|
<artifactId>zipkin-server</artifactId>
|
||||||
<version>1.11.1</version>
|
<version>1.13.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|||||||
@@ -18,14 +18,12 @@ package org.springframework.cloud.sleuth.zipkin.stream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.springframework.cloud.sleuth.Span;
|
import org.springframework.cloud.sleuth.Span;
|
||||||
import org.springframework.cloud.sleuth.stream.Host;
|
import org.springframework.cloud.sleuth.stream.Host;
|
||||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||||
import org.springframework.cloud.sleuth.stream.Spans;
|
import org.springframework.cloud.sleuth.stream.Spans;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import zipkin.BinaryAnnotation;
|
import zipkin.BinaryAnnotation;
|
||||||
import zipkin.Constants;
|
import zipkin.Constants;
|
||||||
import zipkin.Endpoint;
|
import zipkin.Endpoint;
|
||||||
@@ -76,8 +74,10 @@ final class ConvertToZipkinSpanList {
|
|||||||
static zipkin.Span convert(Span span, Host host) {
|
static zipkin.Span convert(Span span, Host host) {
|
||||||
Builder zipkinSpan = zipkin.Span.builder();
|
Builder zipkinSpan = zipkin.Span.builder();
|
||||||
|
|
||||||
Endpoint ep = Endpoint.create(host.getServiceName(), host.getIpv4(),
|
Endpoint ep = Endpoint.builder()
|
||||||
host.getPort().shortValue());
|
.serviceName(host.getServiceName())
|
||||||
|
.ipv4(host.getIpv4())
|
||||||
|
.port(host.getPort() != null ? host.getPort() : 0).build();
|
||||||
|
|
||||||
// A zipkin span without any annotations cannot be queried, add special "lc" to
|
// A zipkin span without any annotations cannot be queried, add special "lc" to
|
||||||
// avoid that.
|
// avoid that.
|
||||||
@@ -125,8 +125,7 @@ final class ConvertToZipkinSpanList {
|
|||||||
Endpoint ep) {
|
Endpoint ep) {
|
||||||
String serviceName = span.tags().containsKey(Span.SPAN_PEER_SERVICE_TAG_NAME)
|
String serviceName = span.tags().containsKey(Span.SPAN_PEER_SERVICE_TAG_NAME)
|
||||||
? span.tags().get(Span.SPAN_PEER_SERVICE_TAG_NAME) : ep.serviceName;
|
? span.tags().get(Span.SPAN_PEER_SERVICE_TAG_NAME) : ep.serviceName;
|
||||||
Endpoint endpoint = ep.port == null ? Endpoint.create(serviceName, ep.ipv4)
|
Endpoint endpoint = ep.toBuilder().serviceName(serviceName).build();
|
||||||
: Endpoint.create(serviceName, ep.ipv4, ep.port);
|
|
||||||
zipkinSpan.addBinaryAnnotation(
|
zipkinSpan.addBinaryAnnotation(
|
||||||
BinaryAnnotation.address(Constants.SERVER_ADDR, endpoint));
|
BinaryAnnotation.address(Constants.SERVER_ADDR, endpoint));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.springframework.cloud.sleuth.zipkin.stream;
|
package org.springframework.cloud.sleuth.zipkin.stream;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.cloud.sleuth.Span;
|
import org.springframework.cloud.sleuth.Span;
|
||||||
import org.springframework.cloud.sleuth.stream.Host;
|
import org.springframework.cloud.sleuth.stream.Host;
|
||||||
@@ -30,7 +29,10 @@ public class ZipkinMessageListenerTests {
|
|||||||
Span span = new Span(1, 3, "http:name", 1L, Collections.<Long>emptyList(), 2L, true, true,
|
Span span = new Span(1, 3, "http:name", 1L, Collections.<Long>emptyList(), 2L, true, true,
|
||||||
"process");
|
"process");
|
||||||
Host host = new Host("myservice", "1.2.3.4", 8080);
|
Host host = new Host("myservice", "1.2.3.4", 8080);
|
||||||
Endpoint endpoint = Endpoint.create("myservice", 1 << 24 | 2 << 16 | 3 << 8 | 4, 8080);
|
Endpoint endpoint = Endpoint.builder()
|
||||||
|
.serviceName("myservice")
|
||||||
|
.ipv4(1 << 24 | 2 << 16 | 3 << 8 | 4)
|
||||||
|
.port(8080).build();
|
||||||
|
|
||||||
/** Sleuth timestamps are millisecond granularity while zipkin is microsecond. */
|
/** Sleuth timestamps are millisecond granularity while zipkin is microsecond. */
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.zipkin;
|
|||||||
import org.springframework.cloud.client.ServiceInstance;
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.cloud.commons.util.InetUtils;
|
import org.springframework.cloud.commons.util.InetUtils;
|
||||||
|
|
||||||
import zipkin.Endpoint;
|
import zipkin.Endpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +42,10 @@ public class DiscoveryClientEndpointLocator implements EndpointLocator {
|
|||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
throw new NoServiceInstanceAvailableException();
|
throw new NoServiceInstanceAvailableException();
|
||||||
}
|
}
|
||||||
return Endpoint.create(instance.getServiceId(), getIpAddress(instance), instance.getPort());
|
return Endpoint.builder()
|
||||||
|
.serviceName(instance.getServiceId())
|
||||||
|
.ipv4(getIpAddress(instance))
|
||||||
|
.port(instance.getPort()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIpAddress(ServiceInstance instance) {
|
private int getIpAddress(ServiceInstance instance) {
|
||||||
|
|||||||
@@ -48,9 +48,11 @@ public class ServerPropertiesEndpointLocator implements EndpointLocator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Endpoint local() {
|
public Endpoint local() {
|
||||||
int address = getAddress();
|
return Endpoint.builder()
|
||||||
Integer port = getPort();
|
.serviceName(this.appName)
|
||||||
return Endpoint.create(this.appName, address, port);
|
.ipv4(getAddress())
|
||||||
|
.port(getPort())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(EmbeddedServletContainerInitializedEvent.class)
|
@EventListener(EmbeddedServletContainerInitializedEvent.class)
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ public class FallbackHavingEndpointLocatorTests {
|
|||||||
|
|
||||||
@Mock DiscoveryClientEndpointLocator discoveryClientEndpointLocator;
|
@Mock DiscoveryClientEndpointLocator discoveryClientEndpointLocator;
|
||||||
@Mock ServerPropertiesEndpointLocator serverPropertiesEndpointLocator;
|
@Mock ServerPropertiesEndpointLocator serverPropertiesEndpointLocator;
|
||||||
Endpoint expectedEndpoint = Endpoint.create("my-tomcat", 127 << 24 | 1, 8080);
|
Endpoint expectedEndpoint = Endpoint.builder()
|
||||||
|
.serviceName("my-tomcat").ipv4(127 << 24 | 1).port(8080).build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_use_system_property_locator_if_discovery_client_locator_is_not_present() {
|
public void should_use_system_property_locator_if_discovery_client_locator_is_not_present() {
|
||||||
|
|||||||
Reference in New Issue
Block a user