diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxProperties.java index efd953395c..3a5735537a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,11 @@ public class SignalFxProperties extends StepRegistryProperties { */ private String source; + /** + * Type of histogram to publish. + */ + private HistogramType publishedHistogramType = HistogramType.DEFAULT; + @Override public Duration getStep() { return this.step; @@ -88,4 +93,31 @@ public class SignalFxProperties extends StepRegistryProperties { this.source = source; } + public HistogramType getPublishedHistogramType() { + return this.publishedHistogramType; + } + + public void setPublishedHistogramType(HistogramType publishedHistogramType) { + this.publishedHistogramType = publishedHistogramType; + } + + public enum HistogramType { + + /** + * Default, time-based histogram. + */ + DEFAULT, + + /** + * Cumulative histogram. + */ + CUMULATIVE, + + /** + * Delta histogram. + */ + DELTA; + + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapter.java index d5d16d32bf..754e3cb7c4 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx; import io.micrometer.signalfx.SignalFxConfig; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter; +import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType; /** * Adapter to convert {@link SignalFxProperties} to a {@link SignalFxConfig}. @@ -54,4 +55,22 @@ public class SignalFxPropertiesConfigAdapter extends StepRegistryPropertiesConfi return get(SignalFxProperties::getSource, SignalFxConfig.super::source); } + @Override + public boolean publishCumulativeHistogram() { + return get(this::isPublishCumulativeHistogram, SignalFxConfig.super::publishCumulativeHistogram); + } + + private boolean isPublishCumulativeHistogram(SignalFxProperties properties) { + return HistogramType.CUMULATIVE == properties.getPublishedHistogramType(); + } + + @Override + public boolean publishDeltaHistogram() { + return get(this::isPublishDeltaHistogram, SignalFxConfig.super::publishDeltaHistogram); + } + + private boolean isPublishDeltaHistogram(SignalFxProperties properties) { + return HistogramType.DELTA == properties.getPublishedHistogramType(); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java index a03af634c0..2dd2b882e8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; +import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType; import static org.assertj.core.api.Assertions.assertThat; @@ -62,4 +63,20 @@ class SignalFxPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5"); } + @Test + void whenPropertiesPublishHistogramTypeIsCumulativePublishCumulativeHistogramReturnsIt() { + SignalFxProperties properties = createProperties(); + properties.setPublishedHistogramType(HistogramType.CUMULATIVE); + assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue(); + assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isFalse(); + } + + @Test + void whenPropertiesPublishHistogramTypeIsDeltaPublishDeltaHistogramReturnsIt() { + SignalFxProperties properties = createProperties(); + properties.setPublishedHistogramType(HistogramType.DELTA); + assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isTrue(); + assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isFalse(); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesTests.java index 19ea7cdc9d..ff7b6bf380 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import io.micrometer.signalfx.SignalFxConfig; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesTests; +import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType; import static org.assertj.core.api.Assertions.assertThat; @@ -38,6 +39,11 @@ class SignalFxPropertiesTests extends StepRegistryPropertiesTests { // access token is mandatory assertThat(properties.getUri()).isEqualTo(config.uri()); // source has no static default value + // Not publishing cumulative or delta histograms implies that the default + // histogram type should be published. + assertThat(config.publishCumulativeHistogram()).isFalse(); + assertThat(config.publishDeltaHistogram()).isFalse(); + assertThat(properties.getPublishedHistogramType()).isEqualTo(HistogramType.DEFAULT); } }