From 5f08e04b67d7c05b5c92b50fdc2e6e3871dec530 Mon Sep 17 00:00:00 2001 From: akodali18 Date: Mon, 24 Aug 2020 20:44:53 -0700 Subject: [PATCH 1/4] Add build properties file in its own namespace to carry project version info. --- wavefront-spring-boot-bom/pom.xml | 9 +++++++++ .../spring/autoconfigure/WavefrontSleuthSpanHandler.java | 4 ++++ .../META-INF/wavefront-spring-boot/build.properties | 1 + 3 files changed, 14 insertions(+) create mode 100644 wavefront-spring-boot/src/main/resources/META-INF/wavefront-spring-boot/build.properties diff --git a/wavefront-spring-boot-bom/pom.xml b/wavefront-spring-boot-bom/pom.xml index 14a140e..4473d9e 100644 --- a/wavefront-spring-boot-bom/pom.xml +++ b/wavefront-spring-boot-bom/pom.xml @@ -47,6 +47,15 @@ + + + src/main/resources + + + src/main/resources/ + true + + org.codehaus.mojo diff --git a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java index 284e6a2..9607309 100644 --- a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java +++ b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java @@ -24,6 +24,7 @@ import com.wavefront.java_sdk.com.google.common.collect.Sets; import com.wavefront.sdk.common.NamedThreadFactory; import com.wavefront.sdk.common.Pair; +import com.wavefront.sdk.common.Utils; import com.wavefront.sdk.common.WavefrontSender; import com.wavefront.sdk.common.application.ApplicationTags; import com.wavefront.sdk.entities.tracing.SpanLog; @@ -74,6 +75,7 @@ final class WavefrontSleuthSpanHandler extends SpanHandler implements Runnable, private final static String DEFAULT_SOURCE = "wavefront-spring-boot"; private final static String WAVEFRONT_GENERATED_COMPONENT = "wavefront-generated"; + public static final String SDK_METRIC_PREFIX = "~sdk.java.wavefront_spring_boot_starter."; final LinkedBlockingQueue> spanBuffer; final WavefrontSender wavefrontSender; @@ -130,6 +132,8 @@ final class WavefrontSleuthSpanHandler extends SpanHandler implements Runnable, this.spanBuffer = new LinkedBlockingQueue<>(maxQueueSize); // init internal metrics + double sdkVersion = Utils.getSemVerGauge("wavefront-spring-boot"); + meterRegistry.gauge(SDK_METRIC_PREFIX + "version", sdkVersion); meterRegistry.gauge("reporter.queue.size", spanBuffer, sb -> (double) sb.size()); meterRegistry.gauge("reporter.queue.remaining_capacity", spanBuffer, sb -> (double) sb.remainingCapacity()); diff --git a/wavefront-spring-boot/src/main/resources/META-INF/wavefront-spring-boot/build.properties b/wavefront-spring-boot/src/main/resources/META-INF/wavefront-spring-boot/build.properties new file mode 100644 index 0000000..616e4be --- /dev/null +++ b/wavefront-spring-boot/src/main/resources/META-INF/wavefront-spring-boot/build.properties @@ -0,0 +1 @@ +project.version=${project.version} \ No newline at end of file From 84a2092cffd8abbb153e9053d358e9f8c4f08dc1 Mon Sep 17 00:00:00 2001 From: akodali18 Date: Wed, 7 Oct 2020 21:37:38 -0700 Subject: [PATCH 2/4] Fix review comments. Included specific resources to filter, move our version metric to be part of auto configuration. --- wavefront-spring-boot-bom/pom.xml | 5 ++- .../WavefrontMetricsConfiguration.java | 35 ++++++++++++++----- .../WavefrontSleuthSpanHandler.java | 3 -- .../WavefrontAutoConfigurationTests.java | 25 +++++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/wavefront-spring-boot-bom/pom.xml b/wavefront-spring-boot-bom/pom.xml index 4473d9e..384b919 100644 --- a/wavefront-spring-boot-bom/pom.xml +++ b/wavefront-spring-boot-bom/pom.xml @@ -52,8 +52,11 @@ src/main/resources - src/main/resources/ + src/main/resources true + + META-INF/wavefront-spring-boot/*.properties + diff --git a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java index bac9aa3..bd4d6f1 100644 --- a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java +++ b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java @@ -1,16 +1,11 @@ package com.wavefront.spring.autoconfigure; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - +import com.wavefront.internal.reporter.WavefrontInternalReporter; +import com.wavefront.internal_reporter_java.io.dropwizard.metrics5.MetricName; import com.wavefront.sdk.appagent.jvm.reporter.WavefrontJvmReporter; +import com.wavefront.sdk.common.Utils; import com.wavefront.sdk.common.WavefrontSender; import com.wavefront.sdk.common.application.ApplicationTags; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.wavefront.WavefrontConfig; -import io.micrometer.wavefront.WavefrontMeterRegistry; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; @@ -22,6 +17,17 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import io.micrometer.wavefront.WavefrontConfig; +import io.micrometer.wavefront.WavefrontMeterRegistry; + /** * Configuration for Wavefront metrics. * @@ -31,6 +37,7 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnBean(WavefrontSender.class) class WavefrontMetricsConfiguration { + public static final String SDK_INTERNAL_METRIC_PREFIX = "~sdk.java.wavefront_spring_boot_starter"; @Bean @ConditionalOnMissingBean @@ -43,6 +50,18 @@ WavefrontJvmReporter wavefrontJvmReporter(WavefrontSender wavefrontSender, Appli return reporter; } + @Bean + @ConditionalOnMissingBean + WavefrontInternalReporter wavefrontInternalReporter(WavefrontSender wavefrontSender, + WavefrontConfig wavefrontConfig) { + WavefrontInternalReporter reporter = new WavefrontInternalReporter.Builder(). + prefixedWith(SDK_INTERNAL_METRIC_PREFIX).withSource(wavefrontConfig.source()). + build(wavefrontSender); + Double sdkVersion = Utils.getSemVerGauge("wavefront-spring-boot"); + reporter.newGauge(new MetricName("version", Collections.EMPTY_MAP), () -> (() -> sdkVersion)); + reporter.start(1, TimeUnit.MINUTES); + return reporter; + } @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ WavefrontMeterRegistry.class, MeterRegistryCustomizer.class }) diff --git a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java index 9607309..e231759 100644 --- a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java +++ b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontSleuthSpanHandler.java @@ -75,7 +75,6 @@ final class WavefrontSleuthSpanHandler extends SpanHandler implements Runnable, private final static String DEFAULT_SOURCE = "wavefront-spring-boot"; private final static String WAVEFRONT_GENERATED_COMPONENT = "wavefront-generated"; - public static final String SDK_METRIC_PREFIX = "~sdk.java.wavefront_spring_boot_starter."; final LinkedBlockingQueue> spanBuffer; final WavefrontSender wavefrontSender; @@ -132,8 +131,6 @@ final class WavefrontSleuthSpanHandler extends SpanHandler implements Runnable, this.spanBuffer = new LinkedBlockingQueue<>(maxQueueSize); // init internal metrics - double sdkVersion = Utils.getSemVerGauge("wavefront-spring-boot"); - meterRegistry.gauge(SDK_METRIC_PREFIX + "version", sdkVersion); meterRegistry.gauge("reporter.queue.size", spanBuffer, sb -> (double) sb.size()); meterRegistry.gauge("reporter.queue.remaining_capacity", spanBuffer, sb -> (double) sb.remainingCapacity()); diff --git a/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java b/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java index fe1ec5a..a7482b0 100644 --- a/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java +++ b/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java @@ -7,6 +7,8 @@ import brave.Tracer; import brave.TracingCustomizer; import brave.handler.SpanHandler; + +import com.wavefront.internal.reporter.WavefrontInternalReporter; import com.wavefront.opentracing.WavefrontTracer; import com.wavefront.opentracing.reporting.Reporter; import com.wavefront.sdk.appagent.jvm.reporter.WavefrontJvmReporter; @@ -136,6 +138,29 @@ void applicationTagsAreNotExportedToNonWavefrontRegistry() { }); } + @Test + void internalReporterIsConfiguredWhenNoneExists() { + this.contextRunner + .with(wavefrontMetrics(() -> mock(WavefrontSender.class))) + .run((context) -> assertThat(context).hasSingleBean(WavefrontInternalReporter.class)); + } + + @Test + void internalReporterCanBeCustomized() { + WavefrontInternalReporter reporter = mock(WavefrontInternalReporter.class); + this.contextRunner + .with(wavefrontMetrics(() -> mock(WavefrontSender.class))) + .withBean(WavefrontInternalReporter.class, () -> reporter) + .run((context) -> assertThat(context).getBean(WavefrontInternalReporter.class).isEqualTo(reporter)); + } + + @Test + void internalReporterNotConfiguredWithoutWavefrontSender() { + this.contextRunner + .with(metrics()) + .run(context -> assertThat(context).doesNotHaveBean(WavefrontInternalReporter.class)); + } + @Test void jvmReporterIsConfiguredWhenNoneExists() { this.contextRunner From 81d37224718cded4ac6e0e0ee7e29b135b331c6c Mon Sep 17 00:00:00 2001 From: akodali18 Date: Sun, 11 Oct 2020 23:33:59 -0700 Subject: [PATCH 3/4] Add check to unit test to verify verion gauge is exported. --- wavefront-spring-boot-bom/pom.xml | 3 +++ .../WavefrontAutoConfigurationTests.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/wavefront-spring-boot-bom/pom.xml b/wavefront-spring-boot-bom/pom.xml index 384b919..c379f9f 100644 --- a/wavefront-spring-boot-bom/pom.xml +++ b/wavefront-spring-boot-bom/pom.xml @@ -50,6 +50,9 @@ src/main/resources + + META-INF/wavefront-spring-boot/*.properties + src/main/resources diff --git a/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java b/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java index a7482b0..609330f 100644 --- a/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java +++ b/wavefront-spring-boot/src/test/java/com/wavefront/spring/autoconfigure/WavefrontAutoConfigurationTests.java @@ -1,5 +1,7 @@ package com.wavefront.spring.autoconfigure; +import java.lang.reflect.Field; +import java.util.Collections; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; @@ -9,6 +11,8 @@ import brave.handler.SpanHandler; import com.wavefront.internal.reporter.WavefrontInternalReporter; +import com.wavefront.internal_reporter_java.io.dropwizard.metrics5.MetricName; +import com.wavefront.internal_reporter_java.io.dropwizard.metrics5.MetricRegistry; import com.wavefront.opentracing.WavefrontTracer; import com.wavefront.opentracing.reporting.Reporter; import com.wavefront.sdk.appagent.jvm.reporter.WavefrontJvmReporter; @@ -31,6 +35,7 @@ import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration; import org.springframework.test.util.ReflectionTestUtils; +import static com.wavefront.spring.autoconfigure.WavefrontMetricsConfiguration.SDK_INTERNAL_METRIC_PREFIX; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -142,7 +147,20 @@ void applicationTagsAreNotExportedToNonWavefrontRegistry() { void internalReporterIsConfiguredWhenNoneExists() { this.contextRunner .with(wavefrontMetrics(() -> mock(WavefrontSender.class))) - .run((context) -> assertThat(context).hasSingleBean(WavefrontInternalReporter.class)); + .run((context) -> { + assertThat(context).hasSingleBean(WavefrontInternalReporter.class); + MetricRegistry internalMetricRegistry = (MetricRegistry)extractMetricRegistry(context + .getBean(WavefrontInternalReporter.class)); + assertThat(internalMetricRegistry.getGauges().containsKey(new MetricName + (SDK_INTERNAL_METRIC_PREFIX + ".version", Collections.EMPTY_MAP))); + }); + } + + private Object extractMetricRegistry(WavefrontInternalReporter wavefrontInternalReporter) throws + NoSuchFieldException, IllegalAccessException { + Field field = wavefrontInternalReporter.getClass().getDeclaredField("internalRegistry"); + field.setAccessible(true); + return field.get(wavefrontInternalReporter); } @Test From cd3e588985b19c616532cdf232ea5610e8591f31 Mon Sep 17 00:00:00 2001 From: akodali18 Date: Sun, 11 Oct 2020 23:54:42 -0700 Subject: [PATCH 4/4] revert optimize import orders. --- .../WavefrontMetricsConfiguration.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java index bd4d6f1..386df99 100644 --- a/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java +++ b/wavefront-spring-boot/src/main/java/com/wavefront/spring/autoconfigure/WavefrontMetricsConfiguration.java @@ -1,11 +1,21 @@ package com.wavefront.spring.autoconfigure; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + import com.wavefront.internal.reporter.WavefrontInternalReporter; import com.wavefront.internal_reporter_java.io.dropwizard.metrics5.MetricName; import com.wavefront.sdk.appagent.jvm.reporter.WavefrontJvmReporter; import com.wavefront.sdk.common.Utils; import com.wavefront.sdk.common.WavefrontSender; import com.wavefront.sdk.common.application.ApplicationTags; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import io.micrometer.wavefront.WavefrontConfig; +import io.micrometer.wavefront.WavefrontMeterRegistry; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; @@ -17,17 +27,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.wavefront.WavefrontConfig; -import io.micrometer.wavefront.WavefrontMeterRegistry; - /** * Configuration for Wavefront metrics. *