diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontProperties.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontProperties.java index fb2aa9533..ff206fcf0 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontProperties.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontProperties.java @@ -35,6 +35,11 @@ public class WavefrontProperties { */ private boolean enabled; + /** + * Span buffer maximum queue size. + */ + private int maxQueueSize = 50000; + /** * Tags that should be associated with RED metrics. If the span has any of the * specified tags, then those get reported to generated RED metrics. @@ -49,6 +54,14 @@ public class WavefrontProperties { this.redMetricsCustomTagKeys = redMetricsCustomTagKeys; } + public int getMaxQueueSize() { + return this.maxQueueSize; + } + + public void setMaxQueueSize(int maxQueueSize) { + this.maxQueueSize = maxQueueSize; + } + public boolean isEnabled() { return this.enabled; } diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthAutoConfiguration.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthAutoConfiguration.java index 160eba985..6a4436f3e 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthAutoConfiguration.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthAutoConfiguration.java @@ -52,24 +52,21 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(value = { "spring.sleuth.enabled", "spring.sleuth.wavefront.enabled" }, matchIfMissing = true) public class WavefrontSleuthAutoConfiguration { - static final String BEAN_NAME = "wavefrontTracingCustomizer"; - @Bean @ConditionalOnBean({ MeterRegistry.class, WavefrontConfig.class, WavefrontSender.class, ApplicationTags.class }) WavefrontSleuthSpanHandler wavefrontSleuthSpanHandler(MeterRegistry meterRegistry, WavefrontSender wavefrontSender, ApplicationTags applicationTags, WavefrontConfig wavefrontConfig, WavefrontProperties wavefrontProperties) { return new WavefrontSleuthSpanHandler( // https://github.com/wavefrontHQ/wavefront-opentracing-sdk-java/blob/f1f08d8daf7b692b9b61dcd5bc24ca6befa8e710/src/main/java/com/wavefront/opentracing/reporting/WavefrontSpanReporter.java#L54 - 50000, // TODO: maxQueueSize should be a property, ya? - wavefrontSender, meterRegistry, wavefrontConfig.source(), applicationTags, - wavefrontProperties.getRedMetricsCustomTagKeys()); + wavefrontProperties.getMaxQueueSize(), wavefrontSender, meterRegistry, wavefrontConfig.source(), + applicationTags, wavefrontProperties.getRedMetricsCustomTagKeys()); } @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ Tracer.class, TracingCustomizer.class, SpanHandler.class }) static class BraveCustomizerConfiguration { - @Bean(BEAN_NAME) + @Bean @ConditionalOnMissingBean(WavefrontTracingCustomizer.class) @ConditionalOnBean({ MeterRegistry.class, WavefrontConfig.class, WavefrontSender.class }) WavefrontTracingCustomizer wavefrontTracingCustomizer(WavefrontSleuthSpanHandler spanHandler) { diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthSpanHandler.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthSpanHandler.java index 33525b5d1..51b4bf072 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthSpanHandler.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontSleuthSpanHandler.java @@ -116,21 +116,21 @@ public final class WavefrontSleuthSpanHandler implements Runnable, Closeable { private static final byte[] DECODING = buildDecodingArray(); - final LinkedBlockingQueue> spanBuffer; + private final LinkedBlockingQueue> spanBuffer; - final WavefrontSender wavefrontSender; + private final WavefrontSender wavefrontSender; - final WavefrontInternalReporter wfInternalReporter; + private final WavefrontInternalReporter wfInternalReporter; - final Set traceDerivedCustomTagKeys; + private final Set traceDerivedCustomTagKeys; - final Counter spansDropped; + private final Counter spansDropped; - final Counter spansReceived; + private final Counter spansReceived; - final Counter reportErrors; + private final Counter reportErrors; - final Thread sendingThread; + private final Thread sendingThread; private volatile boolean stop = false; @@ -138,13 +138,13 @@ public final class WavefrontSleuthSpanHandler implements Runnable, Closeable { private final ScheduledExecutorService heartbeatMetricsScheduledExecutorService; - final String source; + private final String source; - final List> defaultTags; + private final List> defaultTags; - final Set defaultTagKeys; + private final Set defaultTagKeys; - final ApplicationTags applicationTags; + private final ApplicationTags applicationTags; WavefrontSleuthSpanHandler(int maxQueueSize, WavefrontSender wavefrontSender, MeterRegistry meterRegistry, String source, ApplicationTags applicationTags, Set redMetricsCustomTagKeys) { @@ -265,6 +265,7 @@ public final class WavefrontSleuthSpanHandler implements Runnable, Closeable { if (LOG.isDebugEnabled()) { LOG.debug("error sending span " + context, t); } + this.reportErrors.increment(); } // report stats irrespective of span sampling. @@ -281,6 +282,7 @@ public final class WavefrontSleuthSpanHandler implements Runnable, Closeable { if (LOG.isDebugEnabled()) { LOG.debug("error sending span RED metrics " + context, t); } + this.reportErrors.increment(); } } } diff --git a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontTracingIntegrationTests.java b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontTracingIntegrationTests.java index c505c8a4b..a3ae83c31 100644 --- a/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontTracingIntegrationTests.java +++ b/spring-cloud-sleuth-autoconfigure/src/test/java/org/springframework/cloud/sleuth/autoconfig/wavefront/WavefrontTracingIntegrationTests.java @@ -121,11 +121,10 @@ public class WavefrontTracingIntegrationTests { SpanRecord spanRecord = takeRecord(spanRecordQueue); // http - assertThat(spanRecord.tags).contains(Pair.of("http.status_code", "500"), Pair.of("error", "true") // retains + assertThat(spanRecord.tags).contains(Pair.of("http.status_code", "500"), Pair.of("error", "true")); // retains // the // boolean // true - ); } @Test @@ -134,11 +133,10 @@ public class WavefrontTracingIntegrationTests { SpanRecord spanRecord = takeRecord(spanRecordQueue); // http - assertThat(spanRecord.tags).contains(Pair.of("http.status_code", "500"), Pair.of("error", "true") // deletes + assertThat(spanRecord.tags).contains(Pair.of("http.status_code", "500"), Pair.of("error", "true")); // deletes // the // user // message - ); } @Test