Fixes missing zipkin service name and polishes span converters.

Missing service name:

Zipkin service names were logged as null, which is invalid and led to
them showing up as "unknown" in the zipkin ui. This was due to a wiring
bug, and a special-case, which this change fixes.

The special-case was when a sleuth span had no annotations. Since zipkin
service names are attached to annotations, they are only queryable when
annotations exist. When there are no annotations, we add the "lc"
binary annotation, which makes that span attached to the correct service
in zipkin.

Polishing:

Zipkin timestamps were not always set as microseconds. This fixes that.

The de-facto label in zipkin for unknown service is "unknown". This
fixes the code, which formerly fell back to "application".

This also removes complexity in assigning timestamp and duration as we
no longer need to make pseudo-annotations "acquire" and "release".

Finally, this adds tests about above consistently to both scs-zipkin and
scs-zipkin-stream.
This commit is contained in:
Adrian Cole
2015-12-29 11:58:38 +08:00
parent fd4df7ce54
commit e3669417dd
12 changed files with 387 additions and 133 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.sleuth.stream;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.cloud.sleuth.Span;
@@ -28,15 +27,14 @@ import org.springframework.context.event.EventListener;
*/
public class ServerPropertiesHostLocator implements HostLocator {
@Value("${spring.application.name:application}")
private String appName;
private ServerProperties serverProperties;
private final ServerProperties serverProperties;
private final String appName;
private Integer port;
public ServerPropertiesHostLocator(ServerProperties serverProperties) {
public ServerPropertiesHostLocator(ServerProperties serverProperties,
String appName) {
this.serverProperties = serverProperties;
this.appName = appName;
}
@Override
@@ -80,7 +78,7 @@ public class ServerPropertiesHostLocator implements HostLocator {
private String getServiceName(Span span) {
String serviceName;
if (span.getProcessId() != null) {
if (span.getProcessId() != null) { // TODO: javadocs say this isn't nullable!
serviceName = span.getProcessId().toLowerCase();
}
else {

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.sleuth.stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
@@ -77,9 +78,12 @@ public class SleuthStreamAutoConfiguration {
@Autowired(required = false)
private ServerProperties serverProperties;
@Value("${spring.application.name:unknown}")
private String appName;
@Bean
public HostLocator zipkinEndpointLocator() {
return new ServerPropertiesHostLocator(this.serverProperties);
return new ServerPropertiesHostLocator(this.serverProperties, this.appName);
}
}
@@ -91,6 +95,9 @@ public class SleuthStreamAutoConfiguration {
@Autowired(required = false)
private ServerProperties serverProperties;
@Value("${spring.application.name:unknown}")
private String appName;
@Autowired(required = false)
private DiscoveryClient client;
@@ -99,7 +106,7 @@ public class SleuthStreamAutoConfiguration {
if (this.client != null) {
return new DiscoveryClientHostLocator(this.client);
}
return new ServerPropertiesHostLocator(this.serverProperties);
return new ServerPropertiesHostLocator(this.serverProperties, this.appName);
}
}