Bumping versions
This commit is contained in:
@@ -41,8 +41,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
class DefaultEndpointLocator implements EndpointLocator,
|
||||
ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
class DefaultEndpointLocator implements EndpointLocator, ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DefaultEndpointLocator.class);
|
||||
|
||||
@@ -60,9 +59,8 @@ class DefaultEndpointLocator implements EndpointLocator,
|
||||
|
||||
private InetAddress firstNonLoopbackAddress;
|
||||
|
||||
DefaultEndpointLocator(Registration registration, ServerProperties serverProperties,
|
||||
Environment environment, ZipkinProperties zipkinProperties,
|
||||
InetUtils inetUtils) {
|
||||
DefaultEndpointLocator(Registration registration, ServerProperties serverProperties, Environment environment,
|
||||
ZipkinProperties zipkinProperties, InetUtils inetUtils) {
|
||||
this.registration = registration;
|
||||
this.serverProperties = serverProperties;
|
||||
this.environment = environment;
|
||||
@@ -83,8 +81,7 @@ class DefaultEndpointLocator implements EndpointLocator,
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Span will contain serviceName [" + serviceName + "]");
|
||||
}
|
||||
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(serviceName)
|
||||
.port(getPort());
|
||||
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(serviceName).port(getPort());
|
||||
return addAddress(builder).build();
|
||||
}
|
||||
|
||||
@@ -129,8 +126,7 @@ class DefaultEndpointLocator implements EndpointLocator,
|
||||
return builder;
|
||||
}
|
||||
else if (this.environment.containsProperty(IP_ADDRESS_PROP_NAME)
|
||||
&& builder.parseIp(this.environment.getProperty(IP_ADDRESS_PROP_NAME,
|
||||
String.class))) {
|
||||
&& builder.parseIp(this.environment.getProperty(IP_ADDRESS_PROP_NAME, String.class))) {
|
||||
return builder;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -51,8 +51,8 @@ class DefaultZipkinRestTemplateCustomizer implements ZipkinRestTemplateCustomize
|
||||
|
||||
private class GZipInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
||||
throws IOException {
|
||||
request.getHeaders().add("Content-Encoding", "gzip");
|
||||
ByteArrayOutputStream gzipped = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream compressor = new GZIPOutputStream(gzipped)) {
|
||||
|
||||
@@ -78,11 +78,9 @@ import org.springframework.web.client.RestTemplate;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(ZipkinProperties.class)
|
||||
@ConditionalOnProperty(value = { "spring.sleuth.enabled", "spring.zipkin.enabled" },
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = { "spring.sleuth.enabled", "spring.zipkin.enabled" }, matchIfMissing = true)
|
||||
@AutoConfigureBefore(TraceAutoConfiguration.class)
|
||||
@AutoConfigureAfter(
|
||||
name = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration")
|
||||
@AutoConfigureAfter(name = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration")
|
||||
@Import(ZipkinSenderConfigurationImportSelector.class)
|
||||
// public because the constant REPORTER_BEAN_NAME was documented
|
||||
public class ZipkinAutoConfiguration {
|
||||
@@ -119,28 +117,25 @@ public class ZipkinAutoConfiguration {
|
||||
|
||||
@Bean(REPORTER_BEAN_NAME)
|
||||
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
|
||||
public Reporter<Span> reporter(ReporterMetrics reporterMetrics,
|
||||
ZipkinProperties zipkin, @Qualifier(SENDER_BEAN_NAME) Sender sender) {
|
||||
public Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
|
||||
@Qualifier(SENDER_BEAN_NAME) Sender sender) {
|
||||
CheckResult checkResult = checkResult(sender, 1_000L);
|
||||
logCheckResult(sender, checkResult);
|
||||
|
||||
// historical constraint. Note: AsyncReporter supports memory bounds
|
||||
AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender)
|
||||
.queuedMaxSpans(1000)
|
||||
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS)
|
||||
.metrics(reporterMetrics).build(zipkin.getEncoder());
|
||||
AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender).queuedMaxSpans(1000)
|
||||
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS).metrics(reporterMetrics)
|
||||
.build(zipkin.getEncoder());
|
||||
|
||||
return asyncReporter;
|
||||
}
|
||||
|
||||
private void logCheckResult(Sender sender, CheckResult checkResult) {
|
||||
if (log.isDebugEnabled() && checkResult != null && checkResult.ok()) {
|
||||
log.debug("Check result of the [" + sender.toString() + "] is [" + checkResult
|
||||
+ "]");
|
||||
log.debug("Check result of the [" + sender.toString() + "] is [" + checkResult + "]");
|
||||
}
|
||||
else if (checkResult != null && !checkResult.ok()) {
|
||||
log.warn("Check result of the [" + sender.toString() + "] contains an error ["
|
||||
+ checkResult + "]");
|
||||
log.warn("Check result of the [" + sender.toString() + "] contains an error [" + checkResult + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +160,8 @@ public class ZipkinAutoConfiguration {
|
||||
return outcome[0];
|
||||
}
|
||||
thread.interrupt();
|
||||
return CheckResult.failed(new TimeoutException(
|
||||
thread.getName() + " timed out after " + deadlineMillis + "ms"));
|
||||
return CheckResult
|
||||
.failed(new TimeoutException(thread.getName() + " timed out after " + deadlineMillis + "ms"));
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -176,8 +171,7 @@ public class ZipkinAutoConfiguration {
|
||||
|
||||
/** Returns one handler for as many reporters as exist. */
|
||||
@Bean
|
||||
SpanHandler zipkinSpanHandler(@Nullable List<Reporter<Span>> spanReporters,
|
||||
@Nullable Tag<Throwable> errorTag) {
|
||||
SpanHandler zipkinSpanHandler(@Nullable List<Reporter<Span>> spanReporters, @Nullable Tag<Throwable> errorTag) {
|
||||
if (spanReporters == null) {
|
||||
return SpanHandler.NOOP;
|
||||
}
|
||||
@@ -202,8 +196,7 @@ public class ZipkinAutoConfiguration {
|
||||
@Bean
|
||||
TracingCustomizer reorderZipkinHandlersLast() {
|
||||
return builder -> {
|
||||
List<SpanHandler> configuredSpanHandlers = new ArrayList<>(
|
||||
builder.spanHandlers());
|
||||
List<SpanHandler> configuredSpanHandlers = new ArrayList<>(builder.spanHandlers());
|
||||
configuredSpanHandlers.sort(SPAN_HANDLER_COMPARATOR);
|
||||
builder.clearSpanHandlers();
|
||||
for (SpanHandler spanHandler : configuredSpanHandlers) {
|
||||
@@ -214,15 +207,14 @@ public class ZipkinAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ZipkinRestTemplateCustomizer zipkinRestTemplateCustomizer(
|
||||
ZipkinProperties zipkinProperties) {
|
||||
public ZipkinRestTemplateCustomizer zipkinRestTemplateCustomizer(ZipkinProperties zipkinProperties) {
|
||||
return new DefaultZipkinRestTemplateCustomizer(zipkinProperties);
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnMissingBean(EndpointLocator.class)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.locator.discovery.enabled",
|
||||
havingValue = "false", matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.locator.discovery.enabled", havingValue = "false",
|
||||
matchIfMissing = true)
|
||||
protected static class DefaultEndpointLocatorConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -239,8 +231,8 @@ public class ZipkinAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public EndpointLocator zipkinEndpointLocator() {
|
||||
return new DefaultEndpointLocator(null, this.serverProperties,
|
||||
this.environment, this.zipkinProperties, this.inetUtils);
|
||||
return new DefaultEndpointLocator(null, this.serverProperties, this.environment, this.zipkinProperties,
|
||||
this.inetUtils);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -248,8 +240,7 @@ public class ZipkinAutoConfiguration {
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Registration.class)
|
||||
@ConditionalOnMissingBean(EndpointLocator.class)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.locator.discovery.enabled",
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(value = "spring.zipkin.locator.discovery.enabled", havingValue = "true")
|
||||
protected static class RegistrationEndpointLocatorConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -269,8 +260,8 @@ public class ZipkinAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public EndpointLocator zipkinEndpointLocator() {
|
||||
return new DefaultEndpointLocator(this.registration, this.serverProperties,
|
||||
this.environment, this.zipkinProperties, this.inetUtils);
|
||||
return new DefaultEndpointLocator(this.registration, this.serverProperties, this.environment,
|
||||
this.zipkinProperties, this.inetUtils);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -329,8 +320,7 @@ public class ZipkinAutoConfiguration {
|
||||
catch (RuntimeException ex) {
|
||||
// TODO: message lifted from ListReporter: this is probably too much
|
||||
// for warn level
|
||||
log.warn("Exception occurred while trying to report the span " + span,
|
||||
ex);
|
||||
log.warn("Exception occurred while trying to report the span " + span, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,7 @@ class LoadBalancerClientZipkinLoadBalancer implements ZipkinLoadBalancer {
|
||||
|
||||
private final ZipkinProperties zipkinProperties;
|
||||
|
||||
LoadBalancerClientZipkinLoadBalancer(LoadBalancerClient loadBalancerClient,
|
||||
ZipkinProperties zipkinProperties) {
|
||||
LoadBalancerClientZipkinLoadBalancer(LoadBalancerClient loadBalancerClient, ZipkinProperties zipkinProperties) {
|
||||
this.loadBalancerClient = loadBalancerClient;
|
||||
this.zipkinProperties = zipkinProperties;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,7 @@ final class RestTemplateSender extends Sender {
|
||||
*/
|
||||
transient boolean closeCalled;
|
||||
|
||||
RestTemplateSender(RestTemplate restTemplate, String baseUrl,
|
||||
BytesEncoder<Span> encoder) {
|
||||
RestTemplateSender(RestTemplate restTemplate, String baseUrl, BytesEncoder<Span> encoder) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.encoding = encoder.encoding();
|
||||
if (encoder.equals(JSON_V2)) {
|
||||
@@ -71,8 +70,7 @@ final class RestTemplateSender extends Sender {
|
||||
this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v1/spans";
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException(
|
||||
"Unsupported encoding: " + this.encoding.name());
|
||||
throw new UnsupportedOperationException("Unsupported encoding: " + this.encoding.name());
|
||||
}
|
||||
this.messageEncoder = BytesMessageEncoder.forEncoding(this.encoding);
|
||||
}
|
||||
@@ -124,8 +122,8 @@ final class RestTemplateSender extends Sender {
|
||||
void post(byte[] json) {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(this.mediaType);
|
||||
RequestEntity<byte[]> requestEntity = new RequestEntity<>(json, httpHeaders,
|
||||
HttpMethod.POST, URI.create(this.url));
|
||||
RequestEntity<byte[]> requestEntity = new RequestEntity<>(json, httpHeaders, HttpMethod.POST,
|
||||
URI.create(this.url));
|
||||
this.restTemplate.exchange(requestEntity, String.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ class ZipkinActiveMqSenderConfiguration {
|
||||
|
||||
@Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME)
|
||||
Sender activeMqSender(ActiveMQConnectionFactory factory) {
|
||||
return ActiveMQSender.newBuilder().connectionFactory(factory)
|
||||
.messageMaxBytes(this.messageMaxBytes).queue(this.queue).build();
|
||||
return ActiveMQSender.newBuilder().connectionFactory(factory).messageMaxBytes(this.messageMaxBytes)
|
||||
.queue(this.queue).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ class ZipkinKafkaSenderConfiguration {
|
||||
if (bootstrapServers instanceof List) {
|
||||
properties.put("bootstrap.servers", join((List) bootstrapServers));
|
||||
}
|
||||
return KafkaSender.newBuilder().topic(this.topic).overrides(properties)
|
||||
.build();
|
||||
return KafkaSender.newBuilder().topic(this.topic).overrides(properties).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,12 +45,9 @@ class ZipkinRabbitSenderConfiguration {
|
||||
private String addresses;
|
||||
|
||||
@Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME)
|
||||
Sender rabbitSender(CachingConnectionFactory connectionFactory,
|
||||
RabbitProperties config) {
|
||||
String addresses = StringUtils.hasText(this.addresses) ? this.addresses
|
||||
: config.determineAddresses();
|
||||
return RabbitMQSender.newBuilder()
|
||||
.connectionFactory(connectionFactory.getRabbitConnectionFactory())
|
||||
Sender rabbitSender(CachingConnectionFactory connectionFactory, RabbitProperties config) {
|
||||
String addresses = StringUtils.hasText(this.addresses) ? this.addresses : config.determineAddresses();
|
||||
return RabbitMQSender.newBuilder().connectionFactory(connectionFactory.getRabbitConnectionFactory())
|
||||
.queue(this.queue).addresses(addresses).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
@EnableConfigurationProperties(ZipkinSenderProperties.class)
|
||||
class ZipkinRestTemplateSenderConfiguration {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ZipkinRestTemplateSenderConfiguration.class);
|
||||
private static final Log log = LogFactory.getLog(ZipkinRestTemplateSenderConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
ZipkinUrlExtractor extractor;
|
||||
@@ -63,8 +62,7 @@ class ZipkinRestTemplateSenderConfiguration {
|
||||
ZipkinRestTemplateCustomizer zipkinRestTemplateCustomizer) {
|
||||
RestTemplate restTemplate = new ZipkinRestTemplateWrapper(zipkin, this.extractor);
|
||||
restTemplate = zipkinRestTemplateCustomizer.customizeTemplate(restTemplate);
|
||||
return new RestTemplateSender(restTemplate, zipkin.getBaseUrl(),
|
||||
zipkin.getEncoder());
|
||||
return new RestTemplateSender(restTemplate, zipkin.getBaseUrl(), zipkin.getEncoder());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -145,8 +143,8 @@ class ZipkinRestTemplateSenderConfiguration {
|
||||
static class DiscoveryClientZipkinUrlExtractorConfiguration {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
static class ZipkinClientLoadBalancedConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -154,17 +152,14 @@ class ZipkinRestTemplateSenderConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ZipkinLoadBalancer loadBalancerClientZipkinLoadBalancer(
|
||||
ZipkinProperties zipkinProperties) {
|
||||
return new LoadBalancerClientZipkinLoadBalancer(this.client,
|
||||
zipkinProperties);
|
||||
ZipkinLoadBalancer loadBalancerClientZipkinLoadBalancer(ZipkinProperties zipkinProperties) {
|
||||
return new LoadBalancerClientZipkinLoadBalancer(this.client, zipkinProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled",
|
||||
havingValue = "false")
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled", havingValue = "false")
|
||||
static class ZipkinClientNoOpConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -205,8 +200,7 @@ class ZipkinRestTemplateWrapper extends RestTemplate {
|
||||
|
||||
private final ZipkinUrlExtractor extractor;
|
||||
|
||||
ZipkinRestTemplateWrapper(ZipkinProperties zipkinProperties,
|
||||
ZipkinUrlExtractor extractor) {
|
||||
ZipkinRestTemplateWrapper(ZipkinProperties zipkinProperties, ZipkinUrlExtractor extractor) {
|
||||
this.zipkinProperties = zipkinProperties;
|
||||
this.extractor = extractor;
|
||||
setRequestFactory(clientHttpRequestFactory());
|
||||
@@ -220,9 +214,8 @@ class ZipkinRestTemplateWrapper extends RestTemplate {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> T doExecute(URI originalUrl, HttpMethod method,
|
||||
RequestCallback requestCallback, ResponseExtractor<T> responseExtractor)
|
||||
throws RestClientException {
|
||||
protected <T> T doExecute(URI originalUrl, HttpMethod method, RequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
URI uri = this.extractor.zipkinUrl(this.zipkinProperties);
|
||||
URI newUri = resolvedZipkinUri(originalUrl, uri);
|
||||
return super.doExecute(newUri, method, requestCallback, responseExtractor);
|
||||
@@ -230,15 +223,14 @@ class ZipkinRestTemplateWrapper extends RestTemplate {
|
||||
|
||||
private URI resolvedZipkinUri(URI originalUrl, URI resolvedZipkinUri) {
|
||||
try {
|
||||
return new URI(resolvedZipkinUri.getScheme(), resolvedZipkinUri.getUserInfo(),
|
||||
resolvedZipkinUri.getHost(), resolvedZipkinUri.getPort(),
|
||||
originalUrl.getPath(), originalUrl.getQuery(),
|
||||
return new URI(resolvedZipkinUri.getScheme(), resolvedZipkinUri.getUserInfo(), resolvedZipkinUri.getHost(),
|
||||
resolvedZipkinUri.getPort(), originalUrl.getPath(), originalUrl.getQuery(),
|
||||
originalUrl.getFragment());
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Failed to create the new URI from original [" + originalUrl
|
||||
+ "] and new one [" + resolvedZipkinUri + "]");
|
||||
log.debug("Failed to create the new URI from original [" + originalUrl + "] and new one ["
|
||||
+ resolvedZipkinUri + "]");
|
||||
}
|
||||
return originalUrl;
|
||||
}
|
||||
|
||||
@@ -31,16 +31,13 @@ import static org.springframework.cloud.sleuth.zipkin2.sender.ZipkinSenderConfig
|
||||
class ZipkinSenderCondition extends SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata md) {
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata md) {
|
||||
String sourceClass = "";
|
||||
if (md instanceof ClassMetadata) {
|
||||
sourceClass = ((ClassMetadata) md).getClassName();
|
||||
}
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("ZipkinSender",
|
||||
sourceClass);
|
||||
String property = context.getEnvironment()
|
||||
.getProperty("spring.zipkin.sender.type");
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("ZipkinSender", sourceClass);
|
||||
String property = context.getEnvironment().getProperty("spring.zipkin.sender.type");
|
||||
if (StringUtils.isEmpty(property)) {
|
||||
return ConditionOutcome.match(message.because("automatic sender type"));
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ public class ZipkinSenderConfigurationImportSelector implements ImportSelector {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Unknown configuration class " + configurationClassName);
|
||||
throw new IllegalStateException("Unknown configuration class " + configurationClassName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,68 +49,58 @@ public class DefaultEndpointLocatorConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldDefaultToServerPropertiesEndpointLocator() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
EmptyConfiguration.class).run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isInstanceOf(DefaultEndpointLocator.class);
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(EmptyConfiguration.class)
|
||||
.run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class)).isInstanceOf(DefaultEndpointLocator.class);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldDefaultToServerPropertiesEndpointLocatorEvenWhenDiscoveryClientPresent() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithRegistration.class).run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isInstanceOf(DefaultEndpointLocator.class);
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(ConfigurationWithRegistration.class)
|
||||
.run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class)).isInstanceOf(DefaultEndpointLocator.class);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldRespectExistingEndpointLocator() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithCustomLocator.class).run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(ConfigurationWithCustomLocator.class)
|
||||
.run("--spring.jmx.enabled=false");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class)).isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldSetServiceNameToServiceId() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithRegistration.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class).local().serviceName())
|
||||
.isEqualTo("from-registration");
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(ConfigurationWithRegistration.class)
|
||||
.run("--spring.jmx.enabled=false", "--spring.zipkin.locator.discovery.enabled=true");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class).local().serviceName()).isEqualTo("from-registration");
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldAcceptServiceNameOverride() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithRegistration.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true",
|
||||
"--spring.zipkin.service.name=foo");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class).local().serviceName())
|
||||
.isEqualTo("foo");
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(ConfigurationWithRegistration.class).run(
|
||||
"--spring.jmx.enabled=false", "--spring.zipkin.locator.discovery.enabled=true",
|
||||
"--spring.zipkin.service.name=foo");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class).local().serviceName()).isEqualTo("foo");
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointLocatorShouldRespectExistingEndpointLocatorEvenWhenAskedToBeDiscovery() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ConfigurationWithRegistration.class, ConfigurationWithCustomLocator.class)
|
||||
.run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class))
|
||||
.isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(ConfigurationWithRegistration.class,
|
||||
ConfigurationWithCustomLocator.class).run("--spring.jmx.enabled=false",
|
||||
"--spring.zipkin.locator.discovery.enabled=true");
|
||||
assertThat(ctxt.getBean(EndpointLocator.class)).isSameAs(ConfigurationWithCustomLocator.locator);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void portDefaultsTo8080() throws UnknownHostException {
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
|
||||
new ServerProperties(), this.environment, new ZipkinProperties(),
|
||||
localAddress(ADDRESS1234));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, new ServerProperties(), this.environment,
|
||||
new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().port()).isEqualTo(8080);
|
||||
}
|
||||
@@ -120,17 +110,16 @@ public class DefaultEndpointLocatorConfigurationTest {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
properties.setPort(1234);
|
||||
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
|
||||
this.environment, new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties, this.environment,
|
||||
new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().port()).isEqualTo(1234);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void portDefaultsToLocalhost() throws UnknownHostException {
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
|
||||
new ServerProperties(), this.environment, new ZipkinProperties(),
|
||||
localAddress(ADDRESS1234));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, new ServerProperties(), this.environment,
|
||||
new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().ipv4()).isEqualTo("1.2.3.4");
|
||||
}
|
||||
@@ -140,9 +129,8 @@ public class DefaultEndpointLocatorConfigurationTest {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
properties.setAddress(InetAddress.getByAddress(ADDRESS1234));
|
||||
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
|
||||
this.environment, new ZipkinProperties(),
|
||||
localAddress(new byte[] { 4, 4, 4, 4 }));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties, this.environment,
|
||||
new ZipkinProperties(), localAddress(new byte[] { 4, 4, 4, 4 }));
|
||||
|
||||
assertThat(locator.local().ipv4()).isEqualTo("1.2.3.4");
|
||||
}
|
||||
@@ -153,8 +141,8 @@ public class DefaultEndpointLocatorConfigurationTest {
|
||||
ZipkinProperties zipkinProperties = new ZipkinProperties();
|
||||
zipkinProperties.getService().setName("foo");
|
||||
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
|
||||
this.environment, zipkinProperties, localAddress(ADDRESS1234));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties, this.environment,
|
||||
zipkinProperties, localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().serviceName()).isEqualTo("foo");
|
||||
}
|
||||
@@ -164,16 +152,15 @@ public class DefaultEndpointLocatorConfigurationTest {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
properties.setPort(-1);
|
||||
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
|
||||
this.environment, new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties, this.environment,
|
||||
new ZipkinProperties(), localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().port()).isEqualTo(8080);
|
||||
}
|
||||
|
||||
private InetUtils localAddress(byte[] address) throws UnknownHostException {
|
||||
InetUtils mocked = Mockito.spy(new InetUtils(new InetUtilsProperties()));
|
||||
Mockito.when(mocked.findFirstNonLoopbackAddress())
|
||||
.thenReturn(InetAddress.getByAddress(address));
|
||||
Mockito.when(mocked.findFirstNonLoopbackAddress()).thenReturn(InetAddress.getByAddress(address));
|
||||
return mocked;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,13 +123,11 @@ public class ZipkinAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void should_apply_micrometer_reporter_metrics_when_meter_registry_bean_present() {
|
||||
this.contextRunner.withUserConfiguration(WithMeterRegistry.class)
|
||||
.run((context) -> {
|
||||
ReporterMetrics bean = context.getBean(ReporterMetrics.class);
|
||||
this.contextRunner.withUserConfiguration(WithMeterRegistry.class).run((context) -> {
|
||||
ReporterMetrics bean = context.getBean(ReporterMetrics.class);
|
||||
|
||||
BDDAssertions.then(bean)
|
||||
.isInstanceOf(MicrometerReporterMetrics.class);
|
||||
});
|
||||
BDDAssertions.then(bean).isInstanceOf(MicrometerReporterMetrics.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,30 +141,25 @@ public class ZipkinAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void should_apply_in_memory_metrics_when_meter_registry_class_missing() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(MeterRegistry.class))
|
||||
.run((context) -> {
|
||||
ReporterMetrics bean = context.getBean(ReporterMetrics.class);
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(MeterRegistry.class)).run((context) -> {
|
||||
ReporterMetrics bean = context.getBean(ReporterMetrics.class);
|
||||
|
||||
BDDAssertions.then(bean).isInstanceOf(InMemoryReporterMetrics.class);
|
||||
});
|
||||
BDDAssertions.then(bean).isInstanceOf(InMemoryReporterMetrics.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultsToV2Endpoint() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.base-url",
|
||||
this.server.url("/").toString());
|
||||
this.context.register(ZipkinAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
|
||||
Config.class);
|
||||
environment().setProperty("spring.zipkin.base-url", this.server.url("/").toString());
|
||||
this.context.register(ZipkinAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class, Config.class);
|
||||
this.context.refresh();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
|
||||
.tag("foo", "bar").start();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo").tag("foo", "bar").start();
|
||||
|
||||
span.finish();
|
||||
|
||||
Awaitility.await().untilAsserted(
|
||||
() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
Awaitility.await().untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
// first request is for health check
|
||||
this.server.takeRequest();
|
||||
// second request is the span one
|
||||
@@ -183,20 +176,16 @@ public class ZipkinAutoConfigurationTests {
|
||||
@Test
|
||||
public void encoderDirectsEndpoint() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.base-url",
|
||||
this.server.url("/").toString());
|
||||
environment().setProperty("spring.zipkin.base-url", this.server.url("/").toString());
|
||||
environment().setProperty("spring.zipkin.encoder", "JSON_V1");
|
||||
this.context.register(ZipkinAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
|
||||
Config.class);
|
||||
this.context.register(ZipkinAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class, Config.class);
|
||||
this.context.refresh();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
|
||||
.tag("foo", "bar").start();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo").tag("foo", "bar").start();
|
||||
|
||||
span.finish();
|
||||
|
||||
Awaitility.await().untilAsserted(
|
||||
() -> then(this.server.getRequestCount()).isGreaterThan(0));
|
||||
Awaitility.await().untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(0));
|
||||
// first request is for health check
|
||||
this.server.takeRequest();
|
||||
// second request is the span one
|
||||
@@ -210,9 +199,8 @@ public class ZipkinAutoConfigurationTests {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.rabbitmq.queue", "zipkin2");
|
||||
environment().setProperty("spring.zipkin.sender.type", "rabbit");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, ZipkinAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
|
||||
@@ -225,9 +213,8 @@ public class ZipkinAutoConfigurationTests {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.kafka.topic", "zipkin2");
|
||||
environment().setProperty("spring.zipkin.sender.type", "kafka");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, KafkaAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class)).isInstanceOf(KafkaSender.class);
|
||||
@@ -242,9 +229,8 @@ public class ZipkinAutoConfigurationTests {
|
||||
environment().setProperty("spring.zipkin.activemq.queue", "zipkin2");
|
||||
environment().setProperty("spring.zipkin.activemq.message-max-bytes", "50");
|
||||
environment().setProperty("spring.zipkin.sender.type", "activemq");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
ActiveMQAutoConfiguration.class, ZipkinAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, ActiveMQAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class)).isInstanceOf(ActiveMQSender.class);
|
||||
@@ -256,13 +242,11 @@ public class ZipkinAutoConfigurationTests {
|
||||
public void canOverrideBySender() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.sender.type", "web");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class,
|
||||
KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class).getClass().getName())
|
||||
.contains("RestTemplateSender");
|
||||
then(this.context.getBean(Sender.class).getClass().getName()).contains("RestTemplateSender");
|
||||
|
||||
this.context.close();
|
||||
}
|
||||
@@ -271,13 +255,11 @@ public class ZipkinAutoConfigurationTests {
|
||||
public void canOverrideBySenderAndIsCaseInsensitive() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.sender.type", "WEB");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class,
|
||||
KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class).getClass().getName())
|
||||
.contains("RestTemplateSender");
|
||||
then(this.context.getBean(Sender.class).getClass().getName()).contains("RestTemplateSender");
|
||||
|
||||
this.context.close();
|
||||
}
|
||||
@@ -286,9 +268,8 @@ public class ZipkinAutoConfigurationTests {
|
||||
public void rabbitWinsWhenKafkaPresent() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.sender.type", "rabbit");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
|
||||
ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class,
|
||||
KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class, TraceAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
|
||||
@@ -299,28 +280,24 @@ public class ZipkinAutoConfigurationTests {
|
||||
@Test
|
||||
public void supportsMultipleReporters() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
environment().setProperty("spring.zipkin.base-url",
|
||||
this.server.url("/").toString());
|
||||
this.context.register(ZipkinAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
|
||||
Config.class, MultipleReportersConfig.class);
|
||||
environment().setProperty("spring.zipkin.base-url", this.server.url("/").toString());
|
||||
this.context.register(ZipkinAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class, Config.class, MultipleReportersConfig.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBeansOfType(Sender.class)).hasSize(2);
|
||||
then(this.context.getBeansOfType(Sender.class))
|
||||
.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME, "otherSender");
|
||||
then(this.context.getBeansOfType(Sender.class)).containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME,
|
||||
"otherSender");
|
||||
|
||||
then(this.context.getBeansOfType(Reporter.class)).hasSize(2);
|
||||
then(this.context.getBeansOfType(Reporter.class)).containsKeys(
|
||||
ZipkinAutoConfiguration.REPORTER_BEAN_NAME, "otherReporter");
|
||||
then(this.context.getBeansOfType(Reporter.class)).containsKeys(ZipkinAutoConfiguration.REPORTER_BEAN_NAME,
|
||||
"otherReporter");
|
||||
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
|
||||
.tag("foo", "bar").start();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo").tag("foo", "bar").start();
|
||||
|
||||
span.finish();
|
||||
|
||||
Awaitility.await().untilAsserted(
|
||||
() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
Awaitility.await().untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
// first request is for health check
|
||||
this.server.takeRequest();
|
||||
// second request is the span one
|
||||
@@ -328,34 +305,28 @@ public class ZipkinAutoConfigurationTests {
|
||||
then(request.getPath()).isEqualTo("/api/v2/spans");
|
||||
then(request.getBody().readUtf8()).contains("localEndpoint");
|
||||
|
||||
MultipleReportersConfig.OtherSender sender = this.context
|
||||
.getBean(MultipleReportersConfig.OtherSender.class);
|
||||
MultipleReportersConfig.OtherSender sender = this.context.getBean(MultipleReportersConfig.OtherSender.class);
|
||||
Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOverrideDefaultBeans() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(ZipkinAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
|
||||
Config.class, MyConfig.class);
|
||||
this.context.register(ZipkinAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceAutoConfiguration.class, Config.class, MyConfig.class);
|
||||
this.context.refresh();
|
||||
|
||||
then(this.context.getBeansOfType(Sender.class)).hasSize(1);
|
||||
then(this.context.getBeansOfType(Sender.class))
|
||||
.containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
|
||||
then(this.context.getBeansOfType(Sender.class)).containsKeys(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
|
||||
|
||||
then(this.context.getBeansOfType(Reporter.class)).hasSize(1);
|
||||
then(this.context.getBeansOfType(Reporter.class))
|
||||
.containsKeys(ZipkinAutoConfiguration.REPORTER_BEAN_NAME);
|
||||
then(this.context.getBeansOfType(Reporter.class)).containsKeys(ZipkinAutoConfiguration.REPORTER_BEAN_NAME);
|
||||
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
|
||||
.tag("foo", "bar").start();
|
||||
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo").tag("foo", "bar").start();
|
||||
|
||||
span.finish();
|
||||
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(this.server.getRequestCount()).isEqualTo(0));
|
||||
Awaitility.await().untilAsserted(() -> then(this.server.getRequestCount()).isEqualTo(0));
|
||||
|
||||
MyConfig.MySender sender = this.context.getBean(MyConfig.MySender.class);
|
||||
Awaitility.await().untilAsserted(() -> then(sender.isSpanSent()).isTrue());
|
||||
@@ -375,8 +346,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
RuntimeException exception = new RuntimeException("dead");
|
||||
when(sender.check()).thenReturn(CheckResult.failed(exception));
|
||||
|
||||
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error())
|
||||
.isSameAs(exception);
|
||||
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error()).isSameAs(exception);
|
||||
}
|
||||
|
||||
/** Bug in {@link Sender} as it shouldn't throw */
|
||||
@@ -386,8 +356,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
RuntimeException exception = new RuntimeException("dead");
|
||||
when(sender.check()).thenThrow(exception);
|
||||
|
||||
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error())
|
||||
.isSameAs(exception);
|
||||
assertThat(ZipkinAutoConfiguration.checkResult(sender, 200).error()).isSameAs(exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -428,8 +397,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
public String toString() {
|
||||
return "FakeSender{}";
|
||||
}
|
||||
}, 200).error()).isInstanceOf(TimeoutException.class)
|
||||
.hasMessage("FakeSender{} check() timed out after 200ms");
|
||||
}, 200).error()).isInstanceOf(TimeoutException.class).hasMessage("FakeSender{} check() timed out after 200ms");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -449,8 +417,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
SpanHandler handlerOne() {
|
||||
return new SpanHandler() {
|
||||
@Override
|
||||
public boolean end(TraceContext traceContext, MutableSpan span,
|
||||
Cause cause) {
|
||||
public boolean end(TraceContext traceContext, MutableSpan span, Cause cause) {
|
||||
span.name("foo");
|
||||
return true; // keep this span
|
||||
}
|
||||
@@ -461,8 +428,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
SpanHandler handlerTwo() {
|
||||
return new SpanHandler() {
|
||||
@Override
|
||||
public boolean end(TraceContext traceContext, MutableSpan span,
|
||||
Cause cause) {
|
||||
public boolean end(TraceContext traceContext, MutableSpan span, Cause cause) {
|
||||
span.name(span.name() + " bar");
|
||||
return true; // keep this span
|
||||
}
|
||||
|
||||
@@ -41,17 +41,17 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@SpringBootTest(classes = ZipkinDiscoveryClientTests.Config.class, properties = {
|
||||
"spring.zipkin.baseUrl=https://zipkin/", "spring.zipkin.sender.type=web" // override
|
||||
// default
|
||||
// priority
|
||||
// which
|
||||
// picks
|
||||
// rabbit
|
||||
// due
|
||||
// to
|
||||
// classpath
|
||||
})
|
||||
@SpringBootTest(classes = ZipkinDiscoveryClientTests.Config.class,
|
||||
properties = { "spring.zipkin.baseUrl=https://zipkin/", "spring.zipkin.sender.type=web" // override
|
||||
// default
|
||||
// priority
|
||||
// which
|
||||
// picks
|
||||
// rabbit
|
||||
// due
|
||||
// to
|
||||
// classpath
|
||||
})
|
||||
public class ZipkinDiscoveryClientTests {
|
||||
|
||||
public static MockWebServer ZIPKIN_RULE = new MockWebServer();
|
||||
@@ -75,8 +75,7 @@ public class ZipkinDiscoveryClientTests {
|
||||
|
||||
span.finish();
|
||||
|
||||
Awaitility.await().untilAsserted(
|
||||
() -> then(ZIPKIN_RULE.getRequestCount()).isGreaterThan(0));
|
||||
Awaitility.await().untilAsserted(() -> then(ZIPKIN_RULE.getRequestCount()).isGreaterThan(0));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -92,14 +91,13 @@ public class ZipkinDiscoveryClientTests {
|
||||
LoadBalancerClient loadBalancerClient() {
|
||||
return new LoadBalancerClient() {
|
||||
@Override
|
||||
public <T> T execute(String serviceId, LoadBalancerRequest<T> request)
|
||||
throws IOException {
|
||||
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(String serviceId, ServiceInstance serviceInstance,
|
||||
LoadBalancerRequest<T> request) throws IOException {
|
||||
public <T> T execute(String serviceId, ServiceInstance serviceInstance, LoadBalancerRequest<T> request)
|
||||
throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,11 @@ import static zipkin2.codec.SpanBytesEncoder.PROTO3;
|
||||
|
||||
public class RestTemplateSenderTest {
|
||||
|
||||
static final Span SPAN = Span.newBuilder().traceId("7180c278b62e8f6a216a2aea45d08fc9")
|
||||
.parentId("6b221d5bc9e6496c").id("5b4185666d50f68b").name("get /backend")
|
||||
.kind(Span.Kind.SERVER).shared(true)
|
||||
.localEndpoint(Endpoint.newBuilder().serviceName("backend")
|
||||
.ip("192.168.99.101").port(9000).build())
|
||||
.timestamp(1472470996250000L).duration(100000L).putTag("http.method", "GET")
|
||||
.putTag("http.path", "/backend").build();
|
||||
static final Span SPAN = Span.newBuilder().traceId("7180c278b62e8f6a216a2aea45d08fc9").parentId("6b221d5bc9e6496c")
|
||||
.id("5b4185666d50f68b").name("get /backend").kind(Span.Kind.SERVER).shared(true)
|
||||
.localEndpoint(Endpoint.newBuilder().serviceName("backend").ip("192.168.99.101").port(9000).build())
|
||||
.timestamp(1472470996250000L).duration(100000L).putTag("http.method", "GET").putTag("http.path", "/backend")
|
||||
.build();
|
||||
|
||||
public MockWebServer server = new MockWebServer();
|
||||
|
||||
@@ -56,8 +54,7 @@ public class RestTemplateSenderTest {
|
||||
|
||||
String endpoint = this.server.url("/api/v2/spans").toString();
|
||||
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint,
|
||||
JSON_V2);
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint, JSON_V2);
|
||||
|
||||
/**
|
||||
* Tests that json is not manipulated as a side-effect of using rest template.
|
||||
@@ -84,15 +81,13 @@ public class RestTemplateSenderTest {
|
||||
assertThat(request.getHeader("Content-Type")).isEqualTo("application/x-protobuf");
|
||||
|
||||
// proto3 encoding of ListOfSpan is simply a repeated span entry
|
||||
assertThat(request.getBody().readByteArray())
|
||||
.containsExactly(SpanBytesEncoder.PROTO3.encode(SPAN));
|
||||
assertThat(request.getBody().readByteArray()).containsExactly(SpanBytesEncoder.PROTO3.encode(SPAN));
|
||||
}
|
||||
|
||||
Call<Void> send(Span... spans) {
|
||||
SpanBytesEncoder bytesEncoder = this.sender.encoding() == Encoding.JSON
|
||||
? SpanBytesEncoder.JSON_V2 : SpanBytesEncoder.PROTO3;
|
||||
return this.sender
|
||||
.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
|
||||
SpanBytesEncoder bytesEncoder = this.sender.encoding() == Encoding.JSON ? SpanBytesEncoder.JSON_V2
|
||||
: SpanBytesEncoder.PROTO3;
|
||||
return this.sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,10 +44,8 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
public void disableZipkinDiscoveryClient() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ZipkinRestTemplateSenderConfigurationTest.MyDiscoveryClientZipkinUrlExtractorConfiguration.class,
|
||||
ZipkinProperties.class)
|
||||
.run("--spring.zipkin.discovery-client-enabled=false");
|
||||
assertThat(ctxt.getBean(ZipkinLoadBalancer.class))
|
||||
.isInstanceOf(NoOpZipkinLoadBalancer.class);
|
||||
ZipkinProperties.class).run("--spring.zipkin.discovery-client-enabled=false");
|
||||
assertThat(ctxt.getBean(ZipkinLoadBalancer.class)).isInstanceOf(NoOpZipkinLoadBalancer.class);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@@ -55,10 +53,8 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
public void enableZipkinDiscoveryClient() {
|
||||
ConfigurableApplicationContext ctxt = new SpringApplication(
|
||||
ZipkinRestTemplateSenderConfigurationTest.MyDiscoveryClientZipkinUrlExtractorConfiguration.class,
|
||||
ZipkinProperties.class)
|
||||
.run("--spring.zipkin.discovery-client-enabled=true");
|
||||
assertThat(ctxt.getBean(ZipkinLoadBalancer.class))
|
||||
.isInstanceOf(LoadBalancerClientZipkinLoadBalancer.class);
|
||||
ZipkinProperties.class).run("--spring.zipkin.discovery-client-enabled=true");
|
||||
assertThat(ctxt.getBean(ZipkinLoadBalancer.class)).isInstanceOf(LoadBalancerClientZipkinLoadBalancer.class);
|
||||
ctxt.close();
|
||||
}
|
||||
|
||||
@@ -78,8 +74,7 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
|
||||
URI uri = extractor.zipkinUrl(zipkinProperties);
|
||||
|
||||
assertThat(uri.toString())
|
||||
.isEqualTo(URI.create(zipkinProperties.getBaseUrl()).toString());
|
||||
assertThat(uri.toString()).isEqualTo(URI.create(zipkinProperties.getBaseUrl()).toString());
|
||||
assertThat(portCalculated).isFalse();
|
||||
}
|
||||
|
||||
@@ -92,8 +87,7 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
|
||||
URI uri = extractor.zipkinUrl(zipkinProperties);
|
||||
|
||||
assertThat(uri.toString())
|
||||
.isEqualTo(URI.create("https://example.com").toString());
|
||||
assertThat(uri.toString()).isEqualTo(URI.create("https://example.com").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,8 +98,7 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
|
||||
URI uri = extractor.zipkinUrl(zipkinProperties);
|
||||
|
||||
assertThat(uri.toString())
|
||||
.isEqualTo(URI.create(zipkinProperties.getBaseUrl()).toString());
|
||||
assertThat(uri.toString()).isEqualTo(URI.create(zipkinProperties.getBaseUrl()).toString());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -113,8 +106,8 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
static class MyDiscoveryClientZipkinUrlExtractorConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
static class ZipkinClientLoadBalancedConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -122,17 +115,14 @@ public class ZipkinRestTemplateSenderConfigurationTest {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ZipkinLoadBalancer loadBalancerClientZipkinLoadBalancer(
|
||||
ZipkinProperties zipkinProperties) {
|
||||
return new LoadBalancerClientZipkinLoadBalancer(this.client,
|
||||
zipkinProperties);
|
||||
ZipkinLoadBalancer loadBalancerClientZipkinLoadBalancer(ZipkinProperties zipkinProperties) {
|
||||
return new LoadBalancerClientZipkinLoadBalancer(this.client, zipkinProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled",
|
||||
havingValue = "false")
|
||||
@ConditionalOnProperty(value = "spring.zipkin.discovery-client-enabled", havingValue = "false")
|
||||
static class ZipkinClientNoOpConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user