Skip to content

Commit

Permalink
Makes brave-spring-beans Spring 2.5 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Dec 12, 2017
1 parent 92904ee commit 5c51589
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.Reporter;

import static javax.servlet.DispatcherType.REQUEST;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final class NoopSender extends Sender {
return encoding().listSizeInBytes(encodedSpans);
}

@Override public int messageSizeInBytes(int encodedSizeInBytes) {
return encoding().listSizeInBytes(encodedSizeInBytes);
}

@Override public Call<Void> sendSpans(List<byte[]> encodedSpans) {
messageEncoder.encode(encodedSpans);
return Call.create(null);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<!-- Note: 3.1.x requires Java 8; 3.0.20.Final is broken -->
<resteasy.version>3.1.4.Final</resteasy.version>
<zipkin.version>2.4.1</zipkin.version>
<zipkin-reporter2.version>2.1.4</zipkin-reporter2.version>
<zipkin-reporter2.version>2.2.0</zipkin-reporter2.version>
<zipkin-reporter.version>1.1.2</zipkin-reporter.version>
<finagle.version>6.45.0</finagle.version>
<log4j.version>2.8.2</log4j.version>
Expand Down
5 changes: 2 additions & 3 deletions spring-beans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ tracing with only XML

## Configuration
Bean Factories exist for the following types:
* AsyncReporterFactoryBean - for configuring how often spans are sent to Zipkin
* EndpointFactoryBean - for configuring the service name, IP etc representing this host
* TracingFactoryBean - wires most together, like reporter and log integration
* HttpTracingFactoryBean - for http tagging and sampling policy

Here are some example beans using the factories in this module:
```xml
<bean id="sender" class="zipkin.reporter2.okhttp3.OkHttpSender" factory-method="create">
<constructor-arg type="java.lang.String" value="http://localhost:9411/api/v2/spans"/>
<bean id="sender" class="zipkin2.reporter.beans.OkHttpSenderFactoryBean">
<property name="endpoint" value="http://localhost:9411/api/v2/spans"/>
</bean>

<bean id="tracing" class="brave.spring.beans.TracingFactoryBean">
Expand Down
12 changes: 6 additions & 6 deletions spring-beans/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-spring-beans</artifactId>
<version>${zipkin-reporter2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>test</scope>
<artifactId>spring-beans</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,75 +1,6 @@
package brave.spring.beans;

import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import zipkin2.codec.SpanBytesEncoder;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.ReporterMetrics;
import zipkin2.reporter.Sender;

/** Spring XML config does not support chained builders. This converts accordingly */
public class AsyncReporterFactoryBean extends AbstractFactoryBean<AsyncReporter> {
Sender sender;
SpanBytesEncoder encoder = SpanBytesEncoder.JSON_V1;
ReporterMetrics metrics;
Integer messageMaxBytes;
Integer messageTimeout;
Integer closeTimeout;
Integer queuedMaxSpans;
Integer queuedMaxBytes;

@Override public Class<? extends AsyncReporter> getObjectType() {
return AsyncReporter.class;
}

@Override protected AsyncReporter createInstance() throws Exception {
AsyncReporter.Builder builder = AsyncReporter.builder(sender);
if (metrics != null) builder.metrics(metrics);
if (messageMaxBytes != null) builder.messageMaxBytes(messageMaxBytes);
if (messageTimeout != null) builder.messageTimeout(messageTimeout, TimeUnit.MILLISECONDS);
if (closeTimeout != null) builder.closeTimeout(closeTimeout, TimeUnit.MILLISECONDS);
if (queuedMaxSpans != null) builder.queuedMaxSpans(queuedMaxSpans);
if (queuedMaxBytes != null) builder.queuedMaxBytes(queuedMaxBytes);
return builder.build(encoder);
}

@Override protected void destroyInstance(AsyncReporter instance) throws Exception {
instance.close();
}

@Override public boolean isSingleton() {
return true;
}

public void setSender(Sender sender) {
this.sender = sender;
}

public void setEncoder(SpanBytesEncoder encoder) {
this.encoder = encoder;
}

public void setMetrics(ReporterMetrics metrics) {
this.metrics = metrics;
}

public void setMessageMaxBytes(Integer messageMaxBytes) {
this.messageMaxBytes = messageMaxBytes;
}

public void setMessageTimeout(Integer messageTimeout) {
this.messageTimeout = messageTimeout;
}

public void setCloseTimeout(Integer closeTimeout) {
this.closeTimeout = closeTimeout;
}

public void setQueuedMaxSpans(Integer queuedMaxSpans) {
this.queuedMaxSpans = queuedMaxSpans;
}

public void setQueuedMaxBytes(Integer queuedMaxBytes) {
this.queuedMaxBytes = queuedMaxBytes;
}
/** @deprecated use {@link zipkin2.reporter.beans.AsyncReporterFactoryBean} */
@Deprecated
public class AsyncReporterFactoryBean extends zipkin2.reporter.beans.AsyncReporterFactoryBean {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import zipkin2.Endpoint;

/** Spring XML config does not support chained builders. This converts accordingly */
public class EndpointFactoryBean implements FactoryBean<Endpoint> {
public class EndpointFactoryBean implements FactoryBean {

String serviceName;
String ip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.beans.factory.FactoryBean;

/** Spring XML config does not support chained builders. This converts accordingly */
public class HttpTracingFactoryBean implements FactoryBean<HttpTracing> {
public class HttpTracingFactoryBean implements FactoryBean {

Tracing tracing;
HttpClientParser clientParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import zipkin2.reporter.Reporter;

/** Spring XML config does not support chained builders. This converts accordingly */
public class TracingFactoryBean extends AbstractFactoryBean<Tracing> {
public class TracingFactoryBean extends AbstractFactoryBean {

String localServiceName;
Endpoint localEndpoint;
Expand All @@ -37,8 +37,8 @@ public class TracingFactoryBean extends AbstractFactoryBean<Tracing> {
return builder.build();
}

@Override protected void destroyInstance(Tracing instance) throws Exception {
instance.close();
@Override protected void destroyInstance(Object instance) throws Exception {
((Tracing) instance).close();
}

@Override public Class<? extends Tracing> getObjectType() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public class EndpointFactoryBeanTest {
+ " <property name=\"serviceName\" value=\"brave-webmvc-example\"/>\n"
+ "</bean>"
);
context.refresh();

assertThat(context.getBean(Endpoint.class))
assertThat(context.getBean("localEndpoint", Endpoint.class))
.isEqualTo(Endpoint.newBuilder().serviceName("brave-webmvc-example").build());
}

Expand All @@ -34,9 +33,8 @@ public class EndpointFactoryBeanTest {
+ " <property name=\"ip\" value=\"1.2.3.4\"/>\n"
+ "</bean>"
);
context.refresh();

assertThat(context.getBean(Endpoint.class))
assertThat(context.getBean("localEndpoint", Endpoint.class))
.isEqualTo(Endpoint.newBuilder()
.serviceName("brave-webmvc-example")
.ip("1.2.3.4")
Expand All @@ -50,10 +48,9 @@ public class EndpointFactoryBeanTest {
+ " <property name=\"ip\" value=\"localhost\"/>\n"
+ "</bean>"
);
context.refresh();

try {
context.getBean(Endpoint.class);
context.getBean("localEndpoint", Endpoint.class);
failBecauseExceptionWasNotThrown(BeanCreationException.class);
} catch (BeanCreationException e) {
assertThat(e)
Expand All @@ -69,9 +66,8 @@ public class EndpointFactoryBeanTest {
+ " <property name=\"port\" value=\"8080\"/>\n"
+ "</bean>"
);
context.refresh();

assertThat(context.getBean(Endpoint.class))
assertThat(context.getBean("localEndpoint", Endpoint.class))
.isEqualTo(Endpoint.newBuilder()
.serviceName("brave-webmvc-example")
.ip("1.2.3.4")
Expand Down
Loading

0 comments on commit 5c51589

Please sign in to comment.