From a6c19dae071826e2e5bfee48d8bf4624337185c0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 21 Jul 2023 17:25:09 +0100 Subject: [PATCH] Add missing management.metrics.export.signalfx properties Closes gh-36497 --- .../export/signalfx/SignalFxProperties.java | 29 ++++++++++++++++++- .../SignalFxPropertiesConfigAdapter.java | 12 +++++++- .../SignalFxPropertiesConfigAdapterTests.java | 8 +++++ .../signalfx/SignalFxPropertiesTests.java | 7 ++++- 4 files changed, 53 insertions(+), 3 deletions(-) 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 d707331418..30c5a7803c 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-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. @@ -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,26 @@ 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; + + } + } 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 4cfc79971b..3632e42230 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-2020 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,13 @@ 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(); + } + } 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..c9b4183983 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,11 @@ class SignalFxPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5"); } + @Test + void whenPropertiesPublishHistogramTypeIsCumulativePublishCumulativeHistogramReturnsIt() { + SignalFxProperties properties = createProperties(); + properties.setPublishedHistogramType(HistogramType.CUMULATIVE); + assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue(); + } + } 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..73b61b34ce 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,10 @@ class SignalFxPropertiesTests extends StepRegistryPropertiesTests { // access token is mandatory assertThat(properties.getUri()).isEqualTo(config.uri()); // source has no static default value + // Not publishing cumulative histograms implies that the default histogram type + // should be published. + assertThat(config.publishCumulativeHistogram()).isFalse(); + assertThat(properties.getPublishedHistogramType()).isEqualTo(HistogramType.DEFAULT); } }