From 7a05faf0798f55a2c0162c2e6e7d338144f04df0 Mon Sep 17 00:00:00 2001 From: Georg Pirklbauer Date: Thu, 7 Apr 2022 15:00:25 +0200 Subject: [PATCH] Allow disabling the Dynatrace instruments Since Micrometer version 1.9.0, the Dynatrace registry uses specialized instruments by default, which ensures data is exported in an optimal format. By using this new flag, users can switch back to the previous behavior, which uses the original instruments from Micrometer. See gh-30637 --- .../export/dynatrace/DynatraceProperties.java | 16 ++++++++++++++++ .../DynatracePropertiesConfigAdapter.java | 5 +++++ .../DynatracePropertiesConfigAdapterTests.java | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatraceProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatraceProperties.java index 4b70cc3a8c..ed931005a8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatraceProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatraceProperties.java @@ -168,6 +168,14 @@ public class DynatraceProperties extends StepRegistryProperties { */ private String metricKeyPrefix; + /** + * Since version 1.9.0 of Micrometer, the Dynatrace registry uses specialized + * instruments to make sure data is exported in an optimal format. This behavior + * is the new default. This toggle allows switching back to the original + * implementation. + */ + private boolean useDynatraceSummaryInstruments = true; + public Map getDefaultDimensions() { return this.defaultDimensions; } @@ -192,6 +200,14 @@ public class DynatraceProperties extends StepRegistryProperties { this.metricKeyPrefix = metricKeyPrefix; } + public boolean isUseDynatraceSummaryInstruments() { + return this.useDynatraceSummaryInstruments; + } + + public void setUseDynatraceSummaryInstruments(boolean useDynatraceSummaryInstruments) { + this.useDynatraceSummaryInstruments = useDynatraceSummaryInstruments; + } + } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapter.java index f073267516..3732aafc91 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapter.java @@ -90,6 +90,11 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt return get(v2(V2::isEnrichWithDynatraceMetadata), DynatraceConfig.super::enrichWithDynatraceMetadata); } + @Override + public boolean useDynatraceSummaryInstruments() { + return get(v2(V2::isUseDynatraceSummaryInstruments), DynatraceConfig.super::useDynatraceSummaryInstruments); + } + private Function v1(Function getter) { return (properties) -> getter.apply(properties.getV1()); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java index 0030283754..2062725b87 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java @@ -125,6 +125,13 @@ class DynatracePropertiesConfigAdapterTests { assertThat(new DynatracePropertiesConfigAdapter(properties).enrichWithDynatraceMetadata()).isTrue(); } + @Test + void whenPropertiesUseDynatraceInstrumentsIsSetAdapterUseDynatraceInstrumentsReturnsIt() { + DynatraceProperties properties = new DynatraceProperties(); + properties.getV2().setUseDynatraceSummaryInstruments(false); + assertThat(new DynatracePropertiesConfigAdapter(properties).useDynatraceSummaryInstruments()).isFalse(); + } + @Test void whenPropertiesDefaultDimensionsIsSetAdapterDefaultDimensionsReturnsIt() { DynatraceProperties properties = new DynatraceProperties(); @@ -148,6 +155,7 @@ class DynatracePropertiesConfigAdapterTests { assertThat(properties.getV2().getMetricKeyPrefix()).isNull(); assertThat(properties.getV2().isEnrichWithDynatraceMetadata()).isTrue(); assertThat(properties.getV2().getDefaultDimensions()).isNull(); + assertThat(properties.getV2().isUseDynatraceSummaryInstruments()).isTrue(); assertThat(properties.getDeviceId()).isNull(); assertThat(properties.getTechnologyType()).isEqualTo("java"); assertThat(properties.getGroup()).isNull();