Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Spring Boot 2.2 and stops using proxyBeanMethods #2864

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<cassandra-driver-core.version>3.7.2</cassandra-driver-core.version>
<jooq.version>3.12.1</jooq.version>
<micrometer.version>1.3.0</micrometer.version>
<spring-boot.version>2.1.9.RELEASE</spring-boot.version>
<spring-boot.version>2.2.0.RELEASE</spring-boot.version>
<!-- MySQL connector is GPL, even if it has an OSS exception.
https://www.mysql.com/about/legal/licensing/foss-exception/

Expand Down
14 changes: 7 additions & 7 deletions zipkin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
<classifier>slim</classifier>
<!-- https://github.com/spring-projects/spring-boot/issues/3426 transitive exclude doesn't work -->
<excludeGroupIds>
io.zipkin.java,com.google.auto.value,com.google.guava,io.dropwizard.metrics,com.datastax.cassandra,com.github.jnr,org.ow2.asm,org.jooq,javax.xml.bind,org.mariadb.jdbc,com.zaxxer,org.apache.activemq,org.apache.geronimo.specs,org.fusesource.hawtbuf,org.apache.kafka,com.github.luben,org.lz4,org.xerial.snappy,com.rabbitmq,jakarta.annotation,org.apache.thrift,org.apache.logging.log4j
com.google.auto.value,com.google.guava,io.dropwizard.metrics,com.datastax.cassandra,com.github.jnr,org.ow2.asm,org.jooq,javax.xml.bind,org.mariadb.jdbc,com.zaxxer,org.apache.activemq,org.apache.geronimo.specs,org.fusesource.hawtbuf,org.apache.kafka,com.github.luben,org.lz4,org.xerial.snappy,com.rabbitmq,jakarta.annotation,org.apache.thrift,org.apache.logging.log4j
</excludeGroupIds>
<excludes>
<!-- Actuator -->
Expand All @@ -538,12 +538,6 @@
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<!-- Brave -->
<dependency>
<groupId>${armeria.groupId}</groupId>
<artifactId>armeria-brave</artifactId>
</dependency>

<!-- Log4J 2 -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -573,6 +567,12 @@
<!-- <artifactId>LatencyUtils</artifactId>-->
<!-- </dependency>-->

<!-- Static content for the Classic UI -->
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-ui</artifactId>
</dependency>

<!-- storage and collectors which have 3rd party deps -->
<dependency>
<groupId>${project.groupId}.zipkin2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package zipkin2.server.internal;

import com.linecorp.armeria.spring.ArmeriaAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import zipkin2.server.internal.activemq.ZipkinActiveMQCollectorConfiguration;
import zipkin2.server.internal.brave.ZipkinSelfTracingConfiguration;
Expand All @@ -30,7 +29,6 @@
import zipkin2.server.internal.scribe.ZipkinScribeCollectorConfiguration;
import zipkin2.server.internal.ui.ZipkinUiConfiguration;

@Configuration
@Import({
ArmeriaAutoConfiguration.class,
ZipkinConfiguration.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -28,7 +27,7 @@
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.type.AnnotatedTypeMetadata;
import zipkin2.collector.CollectorMetrics;
import zipkin2.collector.CollectorSampler;
Expand All @@ -39,7 +38,11 @@
import zipkin2.storage.StorageComponent;

/** Base collector and storage configurations needed for higher-level integrations */
@Configuration
@Import({
ZipkinConfiguration.InMemoryConfiguration.class,
ZipkinConfiguration.ThrottledStorageComponentEnhancer.class,
ZipkinConfiguration.TracingStorageComponentEnhancer.class
})
public class ZipkinConfiguration {

@Bean CollectorSampler traceIdSampler(@Value("${zipkin.collector.sample-rate:1.0}") float rate) {
Expand All @@ -50,31 +53,26 @@ public class ZipkinConfiguration {
return new MicrometerCollectorMetrics(registry);
}

@Configuration
@EnableConfigurationProperties(ZipkinStorageThrottleProperties.class)
@ConditionalOnThrottledStorage
static class ThrottledStorageComponentEnhancer implements BeanPostProcessor, BeanFactoryAware {
@Autowired(required = false)
Tracing tracing;

/**
* Need this to resolve cyclic instantiation issue with spring. Mostly, this is for
* MeterRegistry as really bad things happen if you try to Autowire it (loss of JVM metrics) but
* also using it for properties just to make sure no cycles exist at all as a result of turning
* throttling on.
* Need this to resolve cyclic instantiation issue with spring when instantiating with metrics
* and tracing.
*
* <p>Ref: <a href="https://stackoverflow.com/a/19688634">Tracking down cause of Spring's "not
* eligible for auto-proxying"</a></p>
*/
private BeanFactory beanFactory;
BeanFactory beanFactory;

@Override public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof StorageComponent) {
ZipkinStorageThrottleProperties throttleProperties =
beanFactory.getBean(ZipkinStorageThrottleProperties.class);
return new ThrottledStorageComponent((StorageComponent) bean,
beanFactory.getBean(MeterRegistry.class),
tracing,
beanFactory.containsBean("tracing") ? beanFactory.getBean(Tracing.class) : null,
throttleProperties.getMinConcurrency(),
throttleProperties.getMaxConcurrency(),
throttleProperties.getMaxQueueSize());
Expand All @@ -87,33 +85,37 @@ static class ThrottledStorageComponentEnhancer implements BeanPostProcessor, Bea
}
}

@Configuration
@ConditionalOnSelfTracing
static class TracingStorageComponentEnhancer implements BeanPostProcessor {

@Autowired(required = false)
Tracing tracing;
static class TracingStorageComponentEnhancer implements BeanPostProcessor, BeanFactoryAware {
/**
* Need this to resolve cyclic instantiation issue with spring when instantiating with tracing.
*
* <p>Ref: <a href="https://stackoverflow.com/a/19688634">Tracking down cause of Spring's "not
* eligible for auto-proxying"</a></p>
*/
BeanFactory beanFactory;

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (tracing == null) return bean;
if (bean instanceof StorageComponent) {
@Override public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof StorageComponent && beanFactory.containsBean("tracing")) {
Tracing tracing = beanFactory.getBean(Tracing.class);
return new TracingStorageComponent(tracing, (StorageComponent) bean);
}
return bean;
}

@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}

/**
* This is a special-case configuration if there's no StorageComponent of any kind. In-Mem can
* supply both read apis, so we add two beans here.
*/
@Configuration
@Conditional(StorageTypeMemAbsentOrEmpty.class)
@ConditionalOnMissingBean(StorageComponent.class)
static class InMemoryConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import zipkin2.server.internal.health.ZipkinHealthController;
import zipkin2.server.internal.prometheus.ZipkinMetricsController;

@Configuration
@Configuration(proxyBeanMethods=false)
public class ZipkinHttpConfiguration {
public static final MediaType MEDIA_TYPE_ACTUATOR =
MediaType.parse("application/vnd.spring-boot.actuator.v2+json;charset=UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;
import zipkin2.collector.CollectorMetrics;
import zipkin2.collector.CollectorSampler;
import zipkin2.collector.activemq.ActiveMQCollector;
import zipkin2.storage.StorageComponent;

/** Auto-configuration for {@link ActiveMQCollector}. */
@Configuration
@ConditionalOnClass(ActiveMQCollector.class)
@EnableConfigurationProperties(ZipkinActiveMQCollectorProperties.class)
@Conditional(ZipkinActiveMQCollectorConfiguration.ActiveMQUrlSet.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zipkin2.Call;
import zipkin2.CheckResult;
import zipkin2.Span;
Expand All @@ -45,7 +44,6 @@
import zipkin2.server.internal.ConditionalOnSelfTracing;
import zipkin2.storage.StorageComponent;

@Configuration
@EnableConfigurationProperties(SelfTracingProperties.class)
@ConditionalOnSelfTracing
public class ZipkinSelfTracingConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
import brave.Tracing;
import brave.cassandra.driver.TracingSession;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import zipkin2.server.internal.ConditionalOnSelfTracing;
import zipkin2.storage.StorageComponent;
import zipkin2.storage.cassandra.v1.CassandraStorage;
Expand All @@ -35,11 +37,11 @@
* contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans
* are stored asynchronously.
*/
@Configuration
@ConditionalOnClass(CassandraStorage.class)
@EnableConfigurationProperties(ZipkinCassandraStorageProperties.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "cassandra")
@ConditionalOnMissingBean(StorageComponent.class)
@Import(ZipkinCassandraStorageConfiguration.TracingSessionFactoryEnhancer.class)
public class ZipkinCassandraStorageConfiguration {

@Bean SessionFactory sessionFactory() {
Expand All @@ -65,23 +67,31 @@ StorageComponent storage(
.sessionFactory(sessionFactory).build();
}

@Configuration
@ConditionalOnSelfTracing
static class TracingSessionFactoryEnhancer implements BeanPostProcessor {

@Autowired(required = false) Tracing tracing;
static class TracingSessionFactoryEnhancer implements BeanPostProcessor, BeanFactoryAware {
/**
* Need this to resolve cyclic instantiation issue with spring when instantiating with tracing.
*
* <p>Ref: <a href="https://stackoverflow.com/a/19688634">Tracking down cause of Spring's "not
* eligible for auto-proxying"</a></p>
*/
BeanFactory beanFactory;

@Override public Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean;
}

@Override public Object postProcessAfterInitialization(Object bean, String beanName) {
if (tracing == null) return bean;
if (bean instanceof SessionFactory) {
if (bean instanceof SessionFactory && beanFactory.containsBean("tracing")) {
SessionFactory delegate = (SessionFactory) bean;
Tracing tracing = beanFactory.getBean(Tracing.class);
return (SessionFactory) storage -> TracingSession.create(tracing, delegate.create(storage));
}
return bean;
}

@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
import brave.Tracing;
import brave.cassandra.driver.TracingSession;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import zipkin2.server.internal.ConditionalOnSelfTracing;
import zipkin2.storage.StorageComponent;
import zipkin2.storage.cassandra.CassandraStorage;
Expand All @@ -35,11 +37,11 @@
* contain a single span, which is TBinaryProtocol big-endian, then base64 encoded. Decoded spans
* are stored asynchronously.
*/
@Configuration
@ConditionalOnClass(CassandraStorage.class)
@EnableConfigurationProperties(ZipkinCassandra3StorageProperties.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "cassandra3")
@ConditionalOnMissingBean(StorageComponent.class)
@Import(ZipkinCassandra3StorageConfiguration.TracingSessionFactoryEnhancer.class)
// This component is named .*Cassandra3.* even though the package already says cassandra3 because
// Spring Boot configuration endpoints only printout the simple name of the class
public class ZipkinCassandra3StorageConfiguration {
Expand Down Expand Up @@ -67,23 +69,31 @@ StorageComponent storage(
.sessionFactory(sessionFactory).build();
}

@Configuration
@ConditionalOnSelfTracing
static class TracingSessionFactoryEnhancer implements BeanPostProcessor {

@Autowired(required = false) Tracing tracing;
static class TracingSessionFactoryEnhancer implements BeanPostProcessor, BeanFactoryAware {
/**
* Need this to resolve cyclic instantiation issue with spring when instantiating with tracing.
*
* <p>Ref: <a href="https://stackoverflow.com/a/19688634">Tracking down cause of Spring's "not
* eligible for auto-proxying"</a></p>
*/
BeanFactory beanFactory;

@Override public Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean;
}

@Override public Object postProcessAfterInitialization(Object bean, String beanName) {
if (tracing == null) return bean;
if (bean instanceof SessionFactory) {
if (bean instanceof SessionFactory && beanFactory.containsBean("tracing")) {
SessionFactory delegate = (SessionFactory) bean;
Tracing tracing = beanFactory.getBean(Tracing.class);
return (SessionFactory) storage -> TracingSession.create(tracing, delegate.create(storage));
}
return bean;
}

@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import static zipkin2.server.internal.elasticsearch.ZipkinElasticsearchStorageProperties.Ssl;

@Configuration
@Configuration(proxyBeanMethods=false)
@EnableConfigurationProperties(ZipkinElasticsearchStorageProperties.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "elasticsearch")
@ConditionalOnMissingBean(StorageComponent.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;
import zipkin2.collector.CollectorMetrics;
import zipkin2.collector.CollectorSampler;
Expand All @@ -30,7 +29,6 @@
* This collector consumes a topic, decodes spans from thrift messages and stores them subject to
* sampling policy.
*/
@Configuration
@ConditionalOnClass(KafkaCollector.class)
@Conditional(ZipkinKafkaCollectorConfiguration.KafkaBootstrapServersSet.class)
@EnableConfigurationProperties(ZipkinKafkaCollectorProperties.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import zipkin2.storage.StorageComponent;
import zipkin2.storage.mysql.v1.MySQLStorage;

@Configuration
@EnableConfigurationProperties(ZipkinMySQLStorageProperties.class)
@ConditionalOnClass(MySQLStorage.class)
@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "mysql")
Expand Down
Loading