Skip to content

Commit

Permalink
Remove support for LoadBalancerFeignClient (#324)
Browse files Browse the repository at this point in the history
LoadBalancerFeignClient was removed in spring-cloud-openfeign, so this code might raise errors when used with newer spring versions
  • Loading branch information
Stummi authored Oct 1, 2021
1 parent 76fc7de commit 8a865d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@
public class FeignContextBeanPostProcessor implements BeanPostProcessor {

private Tracer tracer;
private BeanFactory beanFactory;
private List<FeignSpanDecorator> spanDecorators;

FeignContextBeanPostProcessor(Tracer tracer, BeanFactory beanFactory,
List<FeignSpanDecorator> spanDecorators) {
FeignContextBeanPostProcessor(Tracer tracer, List<FeignSpanDecorator> spanDecorators) {
this.tracer = tracer;
this.beanFactory = beanFactory;
this.spanDecorators = spanDecorators;
}

@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof FeignContext && !(bean instanceof TraceFeignContext)) {
return new TraceFeignContext(tracer, (FeignContext) bean, beanFactory, spanDecorators);
return new TraceFeignContext(tracer, (FeignContext) bean, spanDecorators);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public class FeignTracingAutoConfiguration {

@Bean
@ConditionalOnClass(name = "org.springframework.cloud.openfeign.FeignContext")
FeignContextBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory) {
return new FeignContextBeanPostProcessor(tracer, beanFactory, spanDecorators);
FeignContextBeanPostProcessor feignContextBeanPostProcessor() {
return new FeignContextBeanPostProcessor(tracer, spanDecorators);
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.openfeign.FeignContext;

/**
Expand All @@ -30,10 +29,9 @@ class TraceFeignContext extends FeignContext {
private final FeignContext delegate;
private final TracedFeignBeanFactory tracedFeignBeanFactory;

TraceFeignContext(Tracer tracer, FeignContext delegate, BeanFactory beanFactory,
List<FeignSpanDecorator> spanDecorators) {
TraceFeignContext(Tracer tracer, FeignContext delegate, List<FeignSpanDecorator> spanDecorators) {
this.delegate = delegate;
this.tracedFeignBeanFactory = new TracedFeignBeanFactory(tracer, beanFactory, spanDecorators);
this.tracedFeignBeanFactory = new TracedFeignBeanFactory(tracer, spanDecorators);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,24 @@
import feign.opentracing.TracingClient;
import io.opentracing.Tracer;
import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Lazy;

class TracedFeignBeanFactory {

private final Tracer tracer;
private final BeanFactory beanFactory;
private final List<FeignSpanDecorator> spanDecorators;

public TracedFeignBeanFactory(Tracer tracer, BeanFactory beanFactory, @Lazy List<FeignSpanDecorator> spanDecorators) {
public TracedFeignBeanFactory(Tracer tracer, @Lazy List<FeignSpanDecorator> spanDecorators) {
this.tracer = tracer;
this.beanFactory = beanFactory;
this.spanDecorators = spanDecorators;
}

public Object from(Object bean) {
if (bean instanceof TracingClient || bean instanceof LoadBalancedTracedFeign) {
if (bean instanceof TracingClient) {
return bean;
}

if (bean instanceof Client) {
if (bean instanceof LoadBalancerFeignClient) {
return new LoadBalancedTracedFeign(
buildTracingClient(((LoadBalancerFeignClient) bean).getDelegate(), tracer),
beanFactory.getBean(CachingSpringLoadBalancerFactory.class),
beanFactory.getBean(SpringClientFactory.class));
}
return buildTracingClient((Client) bean, tracer);
}

Expand All @@ -60,17 +48,4 @@ private TracingClient buildTracingClient(Client delegate, Tracer tracer) {
.withFeignSpanDecorators(spanDecorators)
.build();
}

/**
* Needed for cast in {@link org.springframework.cloud.openfeign.FeignClientFactoryBean}
*/
static class LoadBalancedTracedFeign extends LoadBalancerFeignClient {

public LoadBalancedTracedFeign(Client delegate,
CachingSpringLoadBalancerFactory lbClientFactory,
SpringClientFactory clientFactory) {
super(delegate, lbClientFactory, clientFactory);
}
}

}

0 comments on commit 8a865d5

Please sign in to comment.