Moved more beans to the conditional on backward compatibility autoconfig; fixes gh-1555

This commit is contained in:
Marcin Grzejszczak
2020-02-18 12:22:13 +01:00
parent 20ca616b69
commit eff71d4f22
2 changed files with 46 additions and 38 deletions

View File

@@ -65,32 +65,7 @@ import org.springframework.util.Assert;
public class ZipkinBackwardsCompatibilityAutoConfiguration { public class ZipkinBackwardsCompatibilityAutoConfiguration {
/** /**
* Reporter that is depending on a {@link Sender} bean which is created in another * Only used for creating a reporter bean with the method below.
* auto-configuration than {@link ZipkinAutoConfiguration}.
* @param reporterMetrics metrics
* @param zipkin zipkin properties
* @param spanBytesEncoder encoder
* @param beanFactory Spring's Bean Factory
* @return span reporter
* @deprecated left for backwards compatibility
*/
@Bean
@Conditional(BackwardsCompatibilityCondition.class)
@Deprecated
Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
BytesEncoder<Span> spanBytesEncoder, DefaultListableBeanFactory beanFactory) {
List<String> beanNames = new ArrayList<>(
Arrays.asList(beanFactory.getBeanNamesForType(Sender.class)));
beanNames.remove(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
Sender sender = (Sender) beanFactory.getBean(beanNames.get(0));
// historical constraint. Note: AsyncReporter supports memory bounds
return AsyncReporter.builder(sender).queuedMaxSpans(1000)
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS)
.metrics(reporterMetrics).build(spanBytesEncoder);
}
/**
* Only used for creating a reporter bean with the method above.
* @param zipkinProperties zipkin properties * @param zipkinProperties zipkin properties
* @return bytes encoder * @return bytes encoder
* @deprecated left for backwards compatibility * @deprecated left for backwards compatibility
@@ -102,17 +77,48 @@ public class ZipkinBackwardsCompatibilityAutoConfiguration {
return zipkinProperties.getEncoder(); return zipkinProperties.getEncoder();
} }
/** @Configuration(proxyBeanMethods = false)
* Deprecated because this is moved to {@link TraceAutoConfiguration}. Left for @Conditional(BackwardsCompatibilityCondition.class)
* backwards compatibility reasons. static class BackwardsCompatibilityConfiguration {
* @return reporter metrics
* @deprecated left for backwards compatibility /**
*/ * Reporter that is depending on a {@link Sender} bean which is created in another
@Bean * auto-configuration than {@link ZipkinAutoConfiguration}.
@ConditionalOnMissingBean * @param reporterMetrics metrics
@Deprecated * @param zipkin zipkin properties
ReporterMetrics zipkinReporterMetrics() { * @param spanBytesEncoder encoder
return new InMemoryReporterMetrics(); * @param beanFactory Spring's Bean Factory
* @return span reporter
* @deprecated left for backwards compatibility
*/
@Bean
@Deprecated
Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
BytesEncoder<Span> spanBytesEncoder,
DefaultListableBeanFactory beanFactory) {
List<String> beanNames = new ArrayList<>(
Arrays.asList(beanFactory.getBeanNamesForType(Sender.class)));
beanNames.remove(ZipkinAutoConfiguration.SENDER_BEAN_NAME);
Sender sender = (Sender) beanFactory.getBean(beanNames.get(0));
// historical constraint. Note: AsyncReporter supports memory bounds
return AsyncReporter.builder(sender).queuedMaxSpans(1000)
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS)
.metrics(reporterMetrics).build(spanBytesEncoder);
}
/**
* Deprecated because this is moved to {@link TraceAutoConfiguration}. Left for
* backwards compatibility reasons.
* @return reporter metrics
* @deprecated left for backwards compatibility
*/
@Bean
@ConditionalOnMissingBean
@Deprecated
ReporterMetrics zipkinReporterMetrics() {
return new InMemoryReporterMetrics();
}
} }
/** /**

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.zipkin2;
import org.junit.Test; import org.junit.Test;
import zipkin2.codec.BytesEncoder; import zipkin2.codec.BytesEncoder;
import zipkin2.reporter.InMemoryReporterMetrics;
import zipkin2.reporter.Reporter; import zipkin2.reporter.Reporter;
import zipkin2.reporter.ReporterMetrics; import zipkin2.reporter.ReporterMetrics;
@@ -43,7 +44,8 @@ public class ZipkinBackwardsCompatibilityAutoConfigurationTests {
assertThat(context.getBean(ZipkinProperties.class)).isNotNull(); assertThat(context.getBean(ZipkinProperties.class)).isNotNull();
assertThat(context.getBean(Reporter.class)).isNotNull(); assertThat(context.getBean(Reporter.class)).isNotNull();
assertThat(context.getBean(BytesEncoder.class)).isNotNull(); assertThat(context.getBean(BytesEncoder.class)).isNotNull();
assertThat(context.getBean(ReporterMetrics.class)).isNotNull(); assertThat(context.getBean(ReporterMetrics.class))
.isInstanceOf(InMemoryReporterMetrics.class);
}); });
} }